Questions tagged [keras]

Keras is a popular, open-source deep learning API for Python built on top of TensorFlow and is useful for fast implementation. Topics include efficient low-level tensor operations, computation of arbitrary gradients, scalable computations, export of graphs, etc.

What is Keras?

Keras is a popular, open-source deep learning API for Python built on top of TensorFlow and is useful for fast implementation. Topics include efficient low-level tensor operations, computation of arbitrary gradients, scalable computations, export of graphs, etc.


New to Keras?

There are various resources including books, tutorials/workshops, etc. for those looking to learn how to use Keras.

Introductions on the Keras website:

Introduction to Keras for Engineers

Introduction to Keras for Researchers

A popular introductory book is:

Deep Learning with Python, by François Chollet.


Tag usage

When posting questions about Keras, please take the following into consideration:

  • When tagging questions with the tag, users should make sure to post sufficient information regarding model construction (layers, input shape, activation functions, etc.) and include all other relevant tags that pertain to the specific topic at hand.

  • Explicit programming related questions are more suitable for Stack Overflow and should not be posted on Stack Exchange Data Science.

  • Questions should include sufficient details and clarity to be able to provide support for the problem at hand. This includes linking to underlying data used, providing code used for the model's construction, highlighting relevant outputs, etc.


External Resources

Keras: Documentation Page


Important Links

Issue Tracker: https://github.com/keras-team/keras/issues

2668 questions
267
votes
10 answers

How to set class weights for imbalanced classes in Keras?

I know that there is a possibility in Keras with the class_weights parameter dictionary at fitting, but I couldn't find any example. Would somebody so kind to provide one? By the way, in this case the appropriate praxis is simply to weight up the…
Hendrik
  • 8,767
  • 17
  • 43
  • 55
125
votes
2 answers

Training an RNN with examples of different lengths in Keras

I am trying to get started learning about RNNs and I'm using Keras. I understand the basic premise of vanilla RNN and LSTM layers, but I'm having trouble understanding a certain technical point for training. In the keras documentation, it says the…
Tac-Tics
  • 1,370
  • 2
  • 9
  • 6
70
votes
2 answers

Sparse_categorical_crossentropy vs categorical_crossentropy (keras, accuracy)

Which is better for accuracy or are they the same? Of course, if you use categorical_crossentropy you use one hot encoding, and if you use sparse_categorical_crossentropy you encode as normal integers. Additionally, when is one better than the…
Master M
  • 803
  • 1
  • 7
  • 5
66
votes
5 answers

How to get accuracy, F1, precision and recall, for a keras model?

I want to compute the precision, recall and F1-score for my binary KerasClassifier model, but don't find any solution. Here's my actual code: # Split dataset in train and test data X_train, X_test, Y_train, Y_test = train_test_split(normalized_X,…
ZelelB
  • 1,067
  • 2
  • 11
  • 15
66
votes
4 answers

Does batch_size in Keras have any effects in results' quality?

I am about to train a big LSTM network with 2-3 million articles and am struggling with Memory Errors (I use AWS EC2 g2x2large). I found out that one solution is to reduce the batch_size. However, I am not sure if this parameter is only related to…
hipoglucido
  • 1,200
  • 1
  • 10
  • 19
59
votes
3 answers

How to set batch_size, steps_per epoch, and validation steps?

I am starting to learn CNNs using Keras. I am using the theano backend. I don't understand how to set values to: batch_size steps_per_epoch validation_steps What should be the value set to batch_size, steps_per_epoch, and validation_steps, if I…
Ermene
  • 693
  • 1
  • 6
  • 6
48
votes
2 answers

How does the validation_split parameter of Keras' fit function work?

Validation-split in Keras Sequential model fit function is documented as following on https://keras.io/models/sequential/ : validation_split: Float between 0 and 1. Fraction of the training data to be used as validation data. The model will set…
rnso
  • 1,608
  • 3
  • 19
  • 35
46
votes
3 answers

What does from_logits=True do in SparseCategoricalcrossEntropy loss function?

In the documentation it has been mentioned that y_pred needs to be in the range of [-inf to inf] when from_logits=True. I truly didn't understand what this means, since the probabilities need to be in the range of 0 to 1! Can someone please explain…
46
votes
2 answers

Merging two different models in Keras

I am trying to merge two Keras models into a single model and I am unable to accomplish this. For example in the attached Figure, I would like to fetch the middle layer $A2$ of dimension 8, and use this as input to the layer $B1$ (of dimension 8…
Rkz
  • 1,033
  • 1
  • 10
  • 12
45
votes
7 answers

What is the relationship between the accuracy and the loss in deep learning?

I have created three different models using deep learning for multi-class classification and each model gave me a different accuracy and loss value. The results of the testing model as the following: First Model: Accuracy: 98.1% Loss: 0.1882 Second…
N.IT
  • 2,015
  • 4
  • 21
  • 36
44
votes
4 answers

Multi GPU in Keras

How we can program in the Keras library (or TensorFlow) to partition training on multiple GPUs? Let's say that you are in an Amazon ec2 instance that has 8 GPUs and you would like to use all of them to train faster, but your code is just for a…
Hector Blandin
  • 579
  • 1
  • 7
  • 11
41
votes
8 answers

Using TensorFlow with Intel GPU

Is there any way now to use TensorFlow with Intel GPUs? If yes, please point me in the right direction. If not, please let me know which framework, if any, (Keras, Theano, etc) can I use for my Intel Corporation Xeon E3-1200 v3/4th Gen Core…
James Bond
  • 1,265
  • 2
  • 12
  • 13
40
votes
2 answers

Keras difference beetween val_loss and loss during training

What is the difference between val_loss and loss during training in Keras? E.g. Epoch 1/20 1000/1000 [==============================] - 1s - loss: 0.1760, val_loss: 0.2032 On some sites I read that on validation, dropout was not working.
40
votes
1 answer

The difference between `Dense` and `TimeDistributedDense` of `Keras`

I am still confused about the difference between Dense and TimeDistributedDense of Keras even though there are already some similar questions asked here and here. People are discussing a lot but no common-agreed conclusions. And even though, here,…
fluency03
  • 503
  • 1
  • 5
  • 8
39
votes
1 answer

How does Keras calculate accuracy?

How does Keras calculate accuracy from the classwise probabilities? Say, for example we have 100 samples in the test set which can belong to one of two classes. We also have a list of the classwise probabilites. What threshold does Keras use to…
pseudomonas
  • 1,042
  • 3
  • 14
  • 32
1
2 3
99 100