keras

ValueError: A merge layer should be called on a list of inputs. Add()

给你一囗甜甜゛ 提交于 2021-02-05 12:13:29
问题 # import the necessary packages import keras from keras.initializers import glorot_uniform from keras.layers import AveragePooling2D, Input, Add from keras.models import Model from keras.layers.normalization import BatchNormalization from keras.layers.convolutional import Conv2D from keras.layers.convolutional import MaxPooling2D from keras.layers.core import Activation from keras.layers.core import Flatten from keras.layers.core import Dropout from keras.layers.core import Dense class

Keras input shape throws value error expected 4d but got an array with shape (60000, 28,28)

孤者浪人 提交于 2021-02-05 11:37:19
问题 (x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data() x_train = x_train.astype('float32') / 255 x_test = x_test.astype('float32') / 255 x_train.shape #Shape is (60000, 28, 28) Then the model made sure input shape is 28,28,1 since 60k is the sample. model2 = tf.keras.Sequential() # Must define the input shape in the first layer of the neural network model2.add(tf.keras.layers.Conv2D(filters=64, kernel_size=2, padding='same', activation='relu', input_shape=(28,28,1)

Numpy load with `allow_pickle=true` old `keras` in `tensorflow.keras`

落爺英雄遲暮 提交于 2021-02-05 10:47:41
问题 Numpy load with allow_pickle=true old keras in tensorflow.keras Situation I have taken a course, where a Jupyter-notebook with a few example use-cases was provided. In order to save time and to have a clean working-environment, I've decided to use the Docker-image: jupyter/tensorflow-notebook:latest (see here). These are the pip list results for the relevant modules: [...] Keras-Applications 1.0.8 Keras-Preprocessing 1.1.0 [...] numpy 1.17.5 [...] tensorflow 2.1.0 [...] (a) The following

Loading images in Keras for CNN from directory but label in CSV file

孤街浪徒 提交于 2021-02-05 09:34:27
问题 I have a set of image files in a directory train_images = './data/images' and train_labels = './data/labels.csv' For example - There are 1000 images in train_images as 377.jpg,17814.jpg .... and so on. And the class they correspond to are saved in a different CSV file. EDIT - Here are a few rows from the CSV file - >> ID Class 0 377.jpg MIDDLE 1 17814.jpg YOUNG 2 21283.jpg MIDDLE 3 16496.jpg YOUNG 4 4487.jpg MIDDLE Here I.D is the image file name and the class is the class it is associated to

Keras isn't using Theano

霸气de小男生 提交于 2021-02-05 09:32:30
问题 1- I create a virtual env: mkvirtualenv kerasTH 2- I install keras using pip install keras 3- That's the output for pip list Package Version ------------- ------- h5py 2.10.0 joblib 0.16.0 Keras 2.4.3 numpy 1.19.1 Pillow 7.2.0 pip 20.2.2 PyYAML 5.3.1 scikit-learn 0.23.2 scipy 1.5.2 setuptools 49.6.0 six 1.15.0 Theano 1.0.5 threadpoolctl 2.1.0 wheel 0.35.1 When I run python and then import keras I get this error ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip

TensorFlow 2.x: Cannot save trained model in h5 format (OSError: Unable to create link (name already exists))

◇◆丶佛笑我妖孽 提交于 2021-02-05 09:13:24
问题 My model uses pre-processed data to predict if a customer is a private or non-private customer. The pre-processing-step is using steps like feature_column.bucketized_column(…), feature_column.embedding_column(…) and so on. After the training, I am trying to save the model but I get the following error: File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py\h5o.pyx", line 202, in h5py.h5o.link OSError

TensorFlow 2.x: Cannot save trained model in h5 format (OSError: Unable to create link (name already exists))

霸气de小男生 提交于 2021-02-05 09:12:07
问题 My model uses pre-processed data to predict if a customer is a private or non-private customer. The pre-processing-step is using steps like feature_column.bucketized_column(…), feature_column.embedding_column(…) and so on. After the training, I am trying to save the model but I get the following error: File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py\h5o.pyx", line 202, in h5py.h5o.link OSError

How can I explore and modify the created dataset from tf.keras.preprocessing.image_dataset_from_directory()?

穿精又带淫゛_ 提交于 2021-02-05 08:51:43
问题 Here's how I used the function: dataset = tf.keras.preprocessing.image_dataset_from_directory( main_directory, labels='inferred', image_size=(299, 299), validation_split=0.1, subset='training', seed=123 ) I'd like to explore the created dataset much like in this example, particularly the part where it was converted to a pandas dataframe. But my minimum goal is to check the labels and the number of files attached to it, just to check if, indeed, it created the dataset as expected (sub

Keras multiclass classification probabilities do not sum up to 1

回眸只為那壹抹淺笑 提交于 2021-02-05 07:59:26
问题 When using the following Keras network to train and classify 9 classes: from keras.models import Model from keras.layers import Convolution1D, Input, Dropout, GlobalMaxPooling1D, Dense, merge input_window3 = Input(shape=(MEANLEN, W2VLEN)) input_window4 = Input(shape=(MEANLEN, W2VLEN)) conv_w3 = Convolution1D(MEANLEN*2, 3, activation='tanh', border_mode='valid')(input_window3) drop_w3 = Dropout(0.7)(conv_w3), pool_w3 = GlobalMaxPooling1D(name='pool_w3')(drop_w3[0]) conv_w4 = Convolution1D

Keras: Predict model within custom loss function

谁说胖子不能爱 提交于 2021-02-05 05:57:26
问题 I am trying to use some_model.predict(x) within a custom loss function. I found this custom loss function: _EPSILON = K.epsilon() def _loss_tensor(y_true, y_pred): y_pred = K.clip(y_pred, _EPSILON, 1.0-_EPSILON) out = -(y_true * K.log(y_pred) + (1.0 - y_true) * K.log(1.0 - y_pred)) return K.mean(out, axis=-1) But the problem is that model.predict() is expecting a numpy array. So I looked for how to convert a tensor ( y_pred ) to a numpy array. I found tmp = K.tf.round(y_true) but this returns