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
66
votes
9 answers

Negative dimension size caused by subtracting 3 from 1 for 'Conv2D'

I'm using Keras with Tensorflow as backend , here is my code: import numpy as np np.random.seed(1373) import tensorflow as tf tf.python.control_flow_ops = tf import os from keras.datasets import mnist from keras.models import Sequential from…
ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
65
votes
4 answers

WARNING:tensorflow:sample_weight modes were coerced from ... to ['...']

Training an image classifier using .fit_generator() or .fit() and passing a dictionary to class_weight= as an argument. I never got errors in TF1.x but in 2.1 I get the following output when starting training: WARNING:tensorflow:sample_weight modes…
gosuto
  • 5,422
  • 6
  • 36
  • 57
65
votes
16 answers

"Could not interpret optimizer identifier" error in Keras

I got this error when I tried to modify the learning rate parameter of SGD optimizer in Keras. Did I miss something in my code or my Keras was not installed properly? Here is my code: from tensorflow.python.keras.models import Sequential from…
Nehemia
  • 651
  • 1
  • 5
  • 5
65
votes
3 answers

Saving best model in keras

I use the following code when training a model in keras from keras.callbacks import EarlyStopping model = Sequential() model.add(Dense(100, activation='relu', input_shape = input_shape)) model.add(Dense(1)) model_2.compile(optimizer='adam',…
dJOKER_dUMMY
  • 699
  • 2
  • 6
  • 5
65
votes
2 answers

How to check if keras tensorflow backend is GPU or CPU version?

I understand that when installing tensorflow, you either install the GPU or CPU version. How can I check which one is installed (I use linux). If the GPU version is installed, would it be automatically running on CPU if GPU is unavailable or would…
matchifang
  • 5,190
  • 12
  • 47
  • 76
65
votes
20 answers

TensorFlow: Blas GEMM launch failed

When I'm trying to use TensorFlow with Keras using the gpu, I'm getting this error message: C:\Users\nicol\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\__main__.py:2: UserWarning: Update your `fit_generator` call to the Keras 2 API:…
Nicolas
  • 699
  • 1
  • 7
  • 9
64
votes
7 answers

How to approach a number guessing game (with a twist) algorithm?

Update(July 2020): Question is 9 years old but still one that I'm deeply interested in. In the time since, machine learning(RNN's, CNN's, GANS,etc), new approaches and cheap GPU's have risen that enable new approaches. I thought it would be fun to…
Lostsoul
  • 25,013
  • 48
  • 144
  • 239
64
votes
2 answers

How to use return_sequences option and TimeDistributed layer in Keras?

I have a dialog corpus like below. And I want to implement a LSTM model which predicts a system action. The system action is described as a bit vector. And a user input is calculated as a word-embedding which is also a bit vector. t1: user: "Do you…
jef
  • 3,890
  • 10
  • 42
  • 76
64
votes
8 answers

How to compute Receiving Operating Characteristic (ROC) and AUC in keras?

I have a multi output(200) binary classification model which I wrote in keras. In this model I want to add additional metrics such as ROC and AUC but to my knowledge keras dosen't have in-built ROC and AUC metric functions. I tried to import ROC,…
Eka
  • 14,170
  • 38
  • 128
  • 212
64
votes
8 answers

How do I install Keras and Theano in Anaconda Python on Windows?

I am trying to work on neural networks in Python using the following Keras packages: from keras.utils import np_utils from keras.layers.core import Dense, Activation, Dropout from keras.models import Sequential from keras.layers.core import Dense,…
pavikirthi
  • 1,569
  • 3
  • 17
  • 26
63
votes
8 answers

ValueError: Shapes (None, 1) and (None, 2) are incompatible

I am training a facial expression (angry vs happy) model. Last dense output layer was previously 1 but when i predict an image it's output was always 1 with 64 % accuracy. So i changed it to 2 for 2 outputs. But now i am getting this error:: Epoch…
faiza rashid
  • 605
  • 1
  • 7
  • 13
63
votes
4 answers

What is the difference between Keras model.evaluate() and model.predict()?

I used Keras biomedical image segmentation to segment brain neurons. I used model.evaluate() it gave me Dice coefficient: 0.916. However, when I used model.predict(), then loop through the predicted images by calculating the Dice coefficient, the…
62
votes
7 answers

Tensorflow Data Adapter Error: ValueError: Failed to find data adapter that can handle input

While running a sentdex tutorial script of a cryptocurrency RNN, link here YouTube Tutorial: Cryptocurrency-predicting RNN Model, but have encountered an error when attempting to train the model. My tensorflow version is 2.0.0 and I'm running python…
Jonathan E
  • 631
  • 1
  • 5
  • 5
62
votes
2 answers

tf.data with multiple inputs / outputs in Keras

For the application, such as pair text similarity, the input data is similar to: pair_1, pair_2. In these problems, we usually have multiple input data. Previously, I implemented my models successfully: model.fit([pair_1, pair_2], labels,…
Amir
  • 16,067
  • 10
  • 80
  • 119
62
votes
6 answers

Keras ValueError: Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=5

I have checked all the solutions, but still, I am facing the same error. My training images shape is (26721, 32, 32, 1), which I believe it is 4 dimension, but I don't know why error shows it is 5 dimension. model = Sequential() …
Lucky
  • 875
  • 1
  • 9
  • 19