Questions tagged [keras]

Keras is a neural network library providing a high-level API in Python and R. Use this tag for questions relating to how to use this API. Please also include the tag for the language/backend ([python], [r], [tensorflow], [theano], [cntk]) that you are using. If you are using tensorflow's built-in keras, use the [tf.keras] tag.

Keras is a high-level deep learning API, written in , similar in spirit to and . It is developed with a focus on enabling fast experimentation and now solely uses as backend. Additionally, it also has a interface.

Having a simple API with less capabilities, Keras is often seen as a good place to start experimenting with deep learning. For beginners, the Sequential API is easy to learn. For intermediate users, the Functional API has more capabilities and flexibility, but it comes at the cost of simplicity. For expert users, the Subclassing API enable ultimate capabilities, that should only be used in experimental settings.

Starting from TensorFlow 1.8 versions, Keras is also integrated in the TensorFlow framework. The creator of Keras, Francois Chollet, recommends that Keras should to be used from inside TensorFlow, as of TensorFlow version 2.0, since the latter package is much better maintained and will be updated in the future/less prone to errors as compared to the plain Keras library.

References:

42247 questions
146
votes
8 answers

Loading a trained Keras model and continue training

I was wondering if it was possible to save a partly trained Keras model and continue the training after loading the model again. The reason for this is that I will have more training data in the future and I do not want to retrain the whole model…
145
votes
14 answers

Deep-Learning Nan loss reasons

Perhaps too general a question, but can anyone explain what would cause a Convolutional Neural Network to diverge? Specifics: I am using Tensorflow's iris_training model with some of my own data and keep getting ERROR:tensorflow:Model diverged with…
Free Url
  • 1,836
  • 2
  • 15
  • 28
129
votes
13 answers

Keras split train test set when using ImageDataGenerator

I have a single directory which contains sub-folders (according to labels) of images. I want to split this data into train and test set while using ImageDataGenerator in Keras. Although model.fit() in keras has argument validation_split for…
Nitin
  • 2,572
  • 5
  • 21
  • 28
128
votes
27 answers

NaN loss when training regression network

I have a data matrix in "one-hot encoding" (all ones and zeros) with 260,000 rows and 35 columns. I am using Keras to train a simple neural network to predict a continuous variable. The code to make the network is the following: model =…
The_Anomaly
  • 2,385
  • 3
  • 18
  • 22
122
votes
6 answers

How to load a model from an HDF5 file in Keras?

How to load a model from an HDF5 file in Keras? What I tried: model = Sequential() model.add(Dense(64, input_dim=14, init='uniform')) model.add(LeakyReLU(alpha=0.3)) model.add(BatchNormalization(epsilon=1e-06, mode=0, momentum=0.9,…
pr338
  • 8,730
  • 19
  • 52
  • 71
120
votes
8 answers

Can Keras with Tensorflow backend be forced to use CPU or GPU at will?

I have Keras installed with the Tensorflow backend and CUDA. I'd like to sometimes on demand force Keras to use CPU. Can this be done without say installing a separate CPU-only Tensorflow in a virtual environment? If so how? If the backend were…
mikal94305
  • 4,663
  • 8
  • 31
  • 40
119
votes
3 answers

How to concatenate two layers in keras?

I have an example of a neural network with two layers. The first layer takes two arguments and has one output. The second should take one argument as result of the first layer and one additional argument. It should looks like this: x1 x2 x3 \ / …
rdo
  • 3,872
  • 6
  • 34
  • 51
117
votes
4 answers

What does Keras Tokenizer method exactly do?

On occasion, circumstances require us to do the following: from keras.preprocessing.text import Tokenizer tokenizer = Tokenizer(num_words=my_max) Then, invariably, we chant this mantra: tokenizer.fit_on_texts(text) sequences =…
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
117
votes
2 answers

Which parameters should be used for early stopping?

I'm training a neural network for my project using Keras. Keras has provided a function for early stopping. May I know what parameters should be observed to avoid my neural network from overfitting by using early stopping?
AizuddinAzman
  • 1,307
  • 2
  • 9
  • 5
117
votes
10 answers

keras: how to save the training history attribute of the history object

In Keras, we can return the output of model.fit to a history as follows: history = model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=nb_epoch, validation_data=(X_test,…
jwm
  • 4,832
  • 10
  • 46
  • 78
117
votes
8 answers

How to apply gradient clipping in TensorFlow?

Considering the example code. I would like to know How to apply gradient clipping on this network on the RNN where there is a possibility of exploding gradients. tf.clip_by_value(t, clip_value_min, clip_value_max, name=None) This is an example that…
Arsenal Fanatic
  • 3,663
  • 6
  • 38
  • 53
116
votes
2 answers

What is the role of TimeDistributed layer in Keras?

I am trying to grasp what TimeDistributed wrapper does in Keras. I get that TimeDistributed "applies a layer to every temporal slice of an input." But I did some experiment and got the results that I cannot understand. In short, in connection to…
Buomsoo Kim
  • 1,283
  • 2
  • 9
  • 5
110
votes
11 answers

How to get reproducible results in keras

I get different results (test accuracy) every time I run the imdb_lstm.py example from Keras framework (https://github.com/fchollet/keras/blob/master/examples/imdb_lstm.py) The code contains np.random.seed(1337) in the top, before any keras imports.…
Pavel Surmenok
  • 4,584
  • 4
  • 30
  • 33
109
votes
3 answers

Why doesn't plt.imshow() display the image?

I have this code, copied from a tutorial: import numpy as np np.random.seed(123) from keras.models import Sequential from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Convolution2D, MaxPooling2D from keras.utils…
Yu Gu
  • 2,382
  • 5
  • 18
  • 33
108
votes
2 answers

Does model.compile() initialize all the weights and biases in Keras (tensorflow backend)?

When I start training a model, there is no model saved previously. I can use model.compile() safely. I have now saved the model in a h5 file for further training using checkpoint. Say, I want to train the model further. I am confused at this point:…
Preetom Saha Arko
  • 2,588
  • 4
  • 21
  • 37