Questions tagged [keras-2]

with a new API.

Keras API will now become available directly as part of

264 questions
100
votes
4 answers

What is validation data used for in a Keras Sequential model?

My question is simple, what is the validation data passed to model.fit in a Sequential model used for? And, does it affect how the model is trained (normally a validation set is used, for example, to choose hyper-parameters in a model, but I think…
danidc
  • 1,309
  • 3
  • 11
  • 11
39
votes
7 answers

Keras: weighted binary crossentropy

I tried to implement a weighted binary crossentropy with Keras, but I am not sure if the code is correct. The training output seems to be a bit confusing. After a few epochs I just get an accuracy of ~0.15. I think thats much too less (even for a…
Kevin Meier
  • 2,339
  • 3
  • 25
  • 52
32
votes
7 answers

ImportError: cannot import name '_obtain_input_shape' from keras

In Keras, I'm trying to import _obtain_input_shape as follows: from keras.applications.imagenet_utils import _obtain_input_shape However, I get the following error: ImportError: cannot import name '_obtain_input_shape' The reason I'm trying to…
Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
30
votes
4 answers

Is there any way to get variable importance with Keras?

I am looking for a proper or best way to get variable importance in a Neural Network created with Keras. The way I currently do it is I just take the weights (not the biases) of the variables in the first layer with the assumption that more…
user1367204
  • 4,549
  • 10
  • 49
  • 78
18
votes
3 answers

How to use keras ReduceLROnPlateau

I am training a keras sequential model. I want the learning rate to be reduced when training is not progressing. I use ReduceLROnPlateau callback. After first 2 epoch with out progress, the learning rate is reduced as expected. But then its reduced…
Naomi Fridman
  • 2,095
  • 2
  • 25
  • 36
18
votes
2 answers

Validation accuracy is always greater than training accuracy in Keras

I am trying to train a simple neural network with the mnist dataset. For some reason, when I get the history (the parameter returned from model.fit), the validation accuracy is higher than the training accuracy, which is really odd, but if I check…
danidc
  • 1,309
  • 3
  • 11
  • 11
16
votes
3 answers

How to add variables to progress bar in Keras?

I'd like to monitor eg. the learning rate during training in Keras both in the progress bar and in Tensorboard. I figure there must be a way to specify which variables are logged, but there's no immediate clarification on this issue on the Keras…
Neergaard
  • 454
  • 4
  • 16
16
votes
1 answer

keras: Use one model output as another model input

I am adding a dense layer before InceptionResNetV2 model(pre-trained) This is InceptionResNetV2 output model_base = InceptionResNetV2(include_top=True, weights='imagenet') x = model_base.get_layer('avg_pool').output x = Dense(3,…
cwzat cwzat
  • 193
  • 1
  • 1
  • 6
14
votes
3 answers

How do I load a keras saved model with custom Optimizer

I have compiled and trained a keras model with a custom optimizer. I saved the model but when I try to load the model, it throws an error stating ValueError: Unknown optimizer: MyOptimizer. I tried to pass MyOptimizer as a custom object something…
Delta
  • 161
  • 1
  • 8
14
votes
2 answers

Removing layers from a pretrained keras model gives the same output as original model

During some feature extraction experiments, I noticed that the 'model.pop()' functionality is not working as expected. For a pretrained model like vgg16, after using 'model.pop()' , model.summary() shows that the layer has been removed (expected…
Koul
  • 180
  • 1
  • 1
  • 8
13
votes
3 answers

Python Keras: An layer output exactly the same thing as input

I am using Keras to build a Network. During the process, I need a layer, which takes an LSTM input, doing nothing, just output exactly the same as input. i.e. if each input record of LSTM is like [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]], I am looking…
Edamame
  • 23,718
  • 73
  • 186
  • 320
12
votes
1 answer

restore_best_weights issue keras early stopping

I am using EarlyStopping from Keras for my deep learning project. The documentations here mentions a very useful idea of restoring best weights. But somehow I am not able to use it yet. I am using Keras 2.2.2/TF 1.10, installed using Anaconda. Call…
Arka Mallick
  • 1,206
  • 3
  • 15
  • 28
12
votes
6 answers

how to save resized images using ImageDataGenerator and flow_from_directory in keras

I am resizing my RGB images stored in a folder(two classes) using following code: from keras.preprocessing.image import…
Hitesh
  • 1,285
  • 6
  • 20
  • 36
12
votes
1 answer

Preprocessing function of inception v3 in Keras

This is preprocessing function of inception v3 in Keras. It is totally different from other models preprocessing. def preprocess_input(x): x /= 255. x -= 0.5 x *= 2. return x 1. Why there is no mean subtraction? 2. Why there is no…
Iman
  • 424
  • 5
  • 18
11
votes
4 answers

Keras2 ImageDataGenerator or TensorFlow tf.data?

With Keras2 being implemented into TensorFlow and TensorFlow 2.0 on the horizon, should you use Keras ImageDataGenerator with e.g, flow_from_directory or tf.data from TensorFlow which also can be used with fit_genearator of Keras now? Will both…
Florida Man
  • 2,021
  • 3
  • 25
  • 43
1
2 3
17 18