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
108
votes
6 answers

Keras, how do I predict after I trained a model?

I'm playing with the reuters-example dataset and it runs fine (my model is trained). I read about how to save a model, so I could load it later to use again. But how do I use this saved model to predict a new text? Do I use models.predict()? Do I…
bky
  • 1,314
  • 3
  • 11
  • 14
105
votes
4 answers

What is an Embedding in Keras?

Keras documentation isn't clear what this actually is. I understand we can use this to compress the input feature space into a smaller one. But how is this done from a neural design perspective? Is it an autoenocder, RBM?
user1008537
101
votes
3 answers

What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?

What is the difference between sparse_categorical_crossentropy and categorical_crossentropy? When should one loss be used as opposed to the other? For example, are these losses suitable for linear regression?
xpertdev
  • 1,293
  • 2
  • 6
  • 12
101
votes
3 answers

Keras: Difference between Kernel and Activity regularizers

I have noticed that weight_regularizer is no more available in Keras and that, in its place, there are activity and kernel regularizer. I would like to know: What are the main differences between kernel and activity regularizers? Could I use…
Simone
  • 4,800
  • 12
  • 30
  • 46
100
votes
1 answer

What is the meaning of axis=-1 in keras.argmax?

I am a beginner in Keras and need help to understand keras.argmax(a, axis=-1) and keras.max(a, axis=-1). What is the meaning of axis=-1 when a.shape = (19, 19, 5, 80)? And also what will be the output of keras.argmax(a, axis=-1) and keras.max(a,…
youngtackpark
  • 1,475
  • 3
  • 12
  • 14
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
99
votes
10 answers

Does Any one got "AttributeError: 'str' object has no attribute 'decode' " , while Loading a Keras Saved Model

After Training, I saved Both Keras whole Model and Only Weights using model.save_weights(MODEL_WEIGHTS) and model.save(MODEL_NAME) Models and Weights were saved successfully and there was no error. I can successfully load the weights simply using…
Rizwan
  • 1,210
  • 2
  • 9
  • 21
99
votes
2 answers

Keras: the difference between LSTM dropout and LSTM recurrent dropout

From the Keras documentation: dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs. recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the…
Alonzorz
  • 2,113
  • 4
  • 18
  • 21
98
votes
5 answers

What's the difference between a bidirectional LSTM and an LSTM?

Can someone please explain this? I know bidirectional LSTMs have a forward and backward pass but what is the advantage of this over a unidirectional LSTM? What is each of them better suited for?
97
votes
4 answers

How to stack multiple lstm in keras?

I am using deep learning library keras and trying to stack multiple LSTM with no luck. Below is my code model = Sequential() model.add(LSTM(100,input_shape =(time_steps,vector_size))) model.add(LSTM(100)) The above code returns error in the third…
Tamim Addari
  • 7,591
  • 9
  • 40
  • 59
96
votes
6 answers

How to check which version of Keras is installed?

Question is the same as the title says. I prefer not to open Python and I use either MacOS or Ubuntu.
aerin
  • 20,607
  • 28
  • 102
  • 140
93
votes
8 answers

Using Keras & Tensorflow with AMD GPU

I'm starting to learn Keras, which I believe is a layer on top of Tensorflow and Theano. However, I only have access to AMD GPUs such as the AMD R9 280X. How can I setup my Python environment such that I can make use of my AMD GPUs through…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
91
votes
10 answers

Higher validation accuracy, than training accurracy using Tensorflow and Keras

I'm trying to use deep learning to predict income from 15 self reported attributes from a dating site. We're getting rather odd results, where our validation data is getting better accuracy and lower loss, than our training data. And this is…
Jasper
  • 1,018
  • 1
  • 10
  • 14
91
votes
7 answers

How to tell Keras stop training based on loss value?

Currently I use the following code: callbacks = [ EarlyStopping(monitor='val_loss', patience=2, verbose=0), ModelCheckpoint(kfold_weights_path, monitor='val_loss', save_best_only=True, verbose=0), ] model.fit(X_train.astype('float32'),…
ZFTurbo
  • 3,652
  • 3
  • 22
  • 27
88
votes
3 answers

What is the difference between loss function and metric in Keras?

It is not clear for me the difference between loss function and metrics in Keras. The documentation was not helpful for me.
Zaratruta
  • 2,097
  • 2
  • 20
  • 26