Questions tagged [keras]

0

votes
0

answer
8

Views

keras incorrectly logs losses

I'm training WGAN with keras, critic model is compiled in the following way: self.critic_combined.compile(optimizer=k.optimizers.Adam(0.0001, beta_1=0.5, beta_2=0.9), loss=[self.wasserstein_loss, self.wasserstein_loss, self.gradient_penalty_loss], loss_weights=[1, 1, 10]) When i run it with train o...
mcstarioni
1

votes
0

answer
7

Views

How to multiply each 2D element of a tensor with dynamic dimension by a static 2D mask?

I have an input Tensor of size (?, 64, 64) and a static Tensor mask of size (64, 64). I want the output tensor of this model to be of shape (?, 64, 64) where the i_th element of the output is an element by element multiplication of the i_th element of the input and the mask. I've tried using the Mul...
polortiz4
9

votes
2

answer
162

Views

Training a tf.keras model with a basic low-level TensorFlow training loop doesn't work

Note: All code for a self-contained example to reproduce my problem can be found below. I have a tf.keras.models.Model instance and need to train it with a training loop written in the low-level TensorFlow API. The problem: Training the exact same tf.keras model once with a basic, standard low-level...
Alex
0

votes
1

answer
10

Views

TypeError: The added layer must be an instance of class Layer. Found: <keras.engine.input_layer.InputLayer object at 0x7fc6f1b92240>

I am trying to add vgg16 layers to Sequential model but getting the error mentioned in the Question Title from keras.applications.vgg16 import VGG16 from tensorflow.contrib.keras.api.keras.models import Sequential vgg_model = VGG16() model = Sequential() #print(model.summary()) for layer in vgg_mod...
AK_AI
0

votes
0

answer
2

Views

Using the output of an internal layer to fit Keras model?

I have a model M that have two inputs: x_train1, x_train2. After passing through heavy transformations these inputs are concatenated into one single array x1_x2. Later it is plugged into an autoencoder where output should be x1_x2. But when I try to fit the model I get the following error: ValueErro...
0

votes
0

answer
14

Views

How to stop Keras from ordering layer output?

I am trying to create a Conv2D layer in Keras (with tensorflow backend) and I've noticed that its output is ordeed in ascending manner. For example, consider a simple input such as this: _input = np.arange(2 * 2).reshape(2, 2) which results in: [[0 1] [2 3]] If we pass the _input variable to a convo...
ShellRox
1

votes
1

answer
1.3k

Views

ValueError: Unknown layer: CapsuleLayer

I have defined a custom layer named CapsuleLayer. The actual model has been defined in a separate class. I have loaded the weights into the actual model and have saved the model in an .h5 file. However when I try to load the model using load_model(filepath) I get the error ValueError: Unknown layer...
Sounak Ray
1

votes
3

answer
1.2k

Views

Cannot set attribute. Group with name “keras_version” exists

I have updated the example program in the keras cifar10_resnet to work on the cifar 100 instead of cifar 10 data set. I am able to run the code only for the first epoch. When i try to save the model the programs breaks with the below error - 'KeyError: 'Cannot set attribute. Group with name "ke...
Shetty
1

votes
2

answer
513

Views

How to convert keras(h5) file to a tflite file?

I got an keras(h5) file. I need to convert it to tflite?? I researched, First i need to go via h5 -> pb -> tflite (because h5 - tflite sometimes results in some issue)
Anthony
1

votes
0

answer
20

Views

How to predict using multiple saved model?

I am trying to predict the score values from downloaded saved model from this notebook https://www.kaggle.com/paoloripamonti/twitter-sentiment-analysis/ It contains 4 saved model namely : encoder.pkl model.h5 model.w2v tokenizer.pkl I am using model.h5 my code here is: from keras.models import load_...
Mansi Shukla
0

votes
0

answer
10

Views

How to feed multiple pandas columns into keras for learning?

Probably a super lame question, but I just can't wrap my head around this yet. I have some data that I built for keras model to learn on. At this point, it's basically a single pandas column for input and one column for output: X = names_frame_dupless["vectorized"].values X = np.array([np.array(l) f...
abolotnov
1

votes
0

answer
12

Views

Hierarchical LSTM in Keras

I want to predict the next element of a sequence using Lstm in Keras. I want to use hierarchical Lstm but not standard stacking. I want to implement two-layer lstm like below image (in the first layer there is time_step lstm unroll and in the second row only exist for example 3 lstm unroll) how can...
Arezoo Torkaman
0

votes
0

answer
7

Views

How to use Keras to create LSTM time series model with many input and many output

I have training data like this: train_x = np.random.randint(1, 20, (5, 4)) train_x array([[ 4, 19, 5, 4], [ 5, 2, 2, 8], [11, 9, 17, 16], [18, 18, 7, 10], [ 2, 1, 1, 4]]) train_y = np.random.randint(1, 10, (5, 2)) train_y array([[2, 7], [2, 9], [4, 5], [7, 8], [2, 8]]) And also validation...
wangmyde
0

votes
0

answer
12

Views

“Oserror cannot identify image file” can't load file from folder

I'm doing a project that trains a model that can classify plankton images. However, when I am doing my code and run it, it says that my image is in a folder that it cannot identify. First, I thought it have some with problem with the file name. I changed all jpg to png. But nothing changed. Every im...
Buche_De_Noel
-1

votes
0

answer
16

Views

Python and C# Interprocess

My project is using machine learning to classify an image. I'm sending a string (containing the path of the image) from C# to Python and I'm expecting the label of the image. I'm using the Anaconda 3 distribution, but the problem is that some modules are not found. The error is: "DLL load failed: T...
Dascalu Cosmin
0

votes
0

answer
6

Views

Can I save/load multiple keras neural network models into one .h5 file?

I trained 5 neural network models and want to share with my teammates. I don't want to save them one by one to 5 .h5 models. Is there any way that I can save them into one .h5 file? Here is how I save/load one model to one file. # save the entire model model.save('model.h5') # model is a trained...
Rocco
0

votes
0

answer
16

Views

Keras can't make predictions

We loaded the model we have trained. Then we tried to use predict_generator to make predictions of images. It ran over an hour for one image prediction but no output was generated (It didn't finish running until we interrupted it). Here is the code (similar to this post): enter code here test% predi...
Tao Huang
-2

votes
0

answer
12

Views

Keras: CNN + LSTM for video recognition

I am trying to implement the Model shown in the above picture that basically consists of time-distributed CNNs followed by a sequence of LSTMs using Keras with TF. I have divided two types of class, and extract 10 frames from each video captured. I have extracted 10 frames for each video and stored...
lai hang
0

votes
1

answer
22

Views

Train and validation score is high but very Poor Test Accuracy

I am working on multi-label image classification, i am using inception net as my base architecture. after the complete training i am getting, training accuracy > 90% and validation accuracy > 85% but i am getting 17% accuracy on test data. Model training --> model = Model(pre_trained_model.input, x)...
Savan Morya
-1

votes
0

answer
12

Views

How to train a Neural Network without instant label or cost on keras?

I want to train a Neural Network, however, neither my fitness/cost nor my "label" is well defined specially instantaneously. The application is to make the Neural Net play a game, thus, I want the NN to find its own way to beat the game, and the defeat is not instantaneous so that I can define the c...
Gustavo Exel
2

votes
0

answer
118

Views

How to extract forecasting errors from all training sets into a single data frame in R?

By forecasting errors, I mean the differences between predicted and actual values. I am doing a time series analysis using a deep learning model called the long-short term memory (LSTM) based on this great article. The author distributed the data set into 11 samples to train the model and then make...
T-T
1

votes
1

answer
499

Views

get intermediate output from Keras/Tensorflow during prediction

Let's say I load inception, and I need to extract the final descriptor just before classification. So given a simple code like this: cnn = InceptionV3(weights='imagenet', include_top='False', pooling='avg') cnn.predict(x, batch_size=32, verbose=0) How can I extract during prediction the last layer?
D.Giunchi
1

votes
2

answer
1.8k

Views

No result of tf.Print in keras's model.fit

I wrote that loss (for testing custom loss in keras): def loss(y_true, y_pred): loss = -tf.reduce_sum(y_true * tf.log(y_pred)) loss = tf.Print(loss, [loss], 'loss = ') return loss and then: model.compile(loss=loss, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy']) model.fit(x_train, y_tr...
1

votes
3

answer
1.1k

Views

'ImageDataGenerator' object has no attribute 'image_data_generator'

I tried transfer learning and then I got "no attribute 'image_data_generator'" error. What does this error mean? You can reproduce my error in the following way. *Steps to Reproduce $ cd /tmp $ git clone --branch no-attribute-error https://github.com/y-zono/btc-bch-ml.git $ cd btc-bch-ml $ docker bu...
zono
1

votes
2

answer
920

Views

How to normalize data when using Keras fit_generator

I have a very large data set and am using Keras' fit_generator to train a Keras model (tensorflow backend). My data needs to be normalized across the entire data set however when using fit_generator, I have access to relatively small batches of data and normalization of the data in this small batch...
Eric Broda
1

votes
2

answer
413

Views

What is the difference between Loss, accuracy, validation loss, Validation accuracy?

At the end of each epoch, I am getting for example the following output: Epoch 1/25 2018-08-06 14:54:12.555511: 2/2 [==============================] - 86s 43s/step - loss: 6.0767 - acc: 0.0469 - val_loss: 4.1037 - val_acc: 0.2000 Epoch 2/25 2/2 [==============================] - 26s 13s/step - loss...
Rochan
1

votes
1

answer
57

Views

LSTM autoencoder with Keras data shape issue

I am trying to make a model using Keras with LSTM autoencoder. Here what I have tried data = df.values timesteps = 10 dim = data.shape[1] samples = data.shape[0] data.shape = (int(samples/timesteps),timesteps,dim) and then model = Sequential() model.add(LSTM(50,input_shape=(timesteps,dim),return_se...
TheTechGuy
1

votes
2

answer
315

Views

Installed Keras with pip3, but getting the “No Module Named keras” error

I am Creating a leaf Identification Classifier using the CNN, the Keras and the Tensorflow backends on Windows. I have installed Anaconda, Tensorflow, numpy, scipy and keras. I installed keras using pip3: C:\> pip3 list | grep -i keras Keras 2.2.4 Keras-Applications 1.0.6 Keras-Prepro...
1

votes
2

answer
35

Views

Display extracted feature vector from trained layer of the model as an image

I am using Transfer learning for recognizing objects. I used trained VGG16 model as the base model and added my classifier on top of it using Keras. I then trained the model on my data, the model works well. I want to see the feature generated by the intermediate layers of the model for the given d...
Nhqazi
1

votes
1

answer
43

Views

The input layer disappears from the structure of a deep learning model

I used the following code to create a CNN model using VGG16 but after creating the model, the input layer of the model disappears from the structure (see the image). Why the input layer disappears from the structure? vgg16_model = keras.applications.vgg16.VGG16() model = Sequential([]) for layer in...
Noran
1

votes
1

answer
81

Views

Keras: how to get predicted labels for more than two classes

I implemented an image classifier in Keras, using the TensorFlow backend. With a dataset with two output classes, I checked the predicted labels as follows: if result[0][0] == 1: prediction ='adathodai' else: prediction ='thamarathtai' Full code link: here With three classes, I get [[0. 0. 1.]]...
1

votes
2

answer
34

Views

How to handles string data in ML classification

Hello I am a beginner in Machine Learning, I have previously worked with some binary ml tasks where the data was numerical. Now I am facing an issue where I have to find the probability of a particular combination. I can not disclose the dataset or the code at this point. My data is a dataframe of 1...
Tahjid Ashfaque
1

votes
2

answer
29

Views

Tensorflow Keras Input layer does not add _keras_shape

According to the keras documentation, Input adds the _keras_shape attribute to the input tensor. However, as shown below, this is not the case. import tensorflow as tf s = tf.keras.layers.Input(shape=[2], dtype=tf.float32, name='s') print(s._keras_shape) Traceback (most recent call last): File "", l...
reubenjohn
0

votes
0

answer
13

Views

Invalid dimension for image data in plt.imshow()

I am using mnist dataset for training a capsule network in keras background. After training, I want to display an image from mnist dataset. For loading images, mnist.load_data() is used. The data is stored as (x_train, y_train),(x_test, y_test). Now, for visualizing image, my code is as follows: img...
Anusha Mehta
0

votes
0

answer
10

Views

Vectorizing the labels for Multi-layer perceptron

I am trying to build a MLP model to solve .csv data which has 9 classes and some textual data. These are labels and their counts: 7:953, 4:686, 1:568, 2:452, 6:275, 5:242, 3:89, 9:37, 8:19. For MLP, I got to know that we need to vectorize class labels. Is it so ?? And when I run following code to do...
Yashu Vihari
0

votes
0

answer
5

Views

keras - loss: nan and accuracy is 0.000

dataset = data.values dataset[:, [0,2,3,4,5,6,7,8,9]] Y = dataset[:, 1] X_train, X_test, y_train, y_test = train_test_split(X, Y, stratify=Y, random_state=0) from sklearn.preprocessing import StandardScaler scaler = StandardScaler() X_train_scaled = scaler.fit(X_train).transform(X_train) X_test_scal...
ean
0

votes
0

answer
6

Views

How can I use ImageDataGenerator class to generate either train and label as image for a keras model?

I want to train a model to generate new images using Keras and I would use the ImageDataGenerator class to generate batches of images. The problem is that I can't find a way to use this class to generate train and label batches as image. I want to pass to the model as training some images and as lab...
Syrius Deffey
1

votes
2

answer
95

Views

TensorFlow Graph to Keras Model?

Is it possible to define a graph in native TensorFlow and then convert this graph to a Keras model? My intention is simply combining (for me) the best of the two worlds. I really like the Keras model API for prototyping and new experiments, i.e. using the awesome multi_gpu_model(model, gpus=4) for t...
daniel451
0

votes
0

answer
5

Views

Multiprocessing to build a single minibatch (Keras - TF backend)

In Keras API, there is the option to use Sequence to generate mini-batches in multi-process mode. However, the generation of a single minibatch remains a single process: i.e one needs to loop through a fixed set of examples (of size BATCH_SIZE) one at a time, perform data augmentation if needed, and...
JMarc

View additional questions