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
76
votes
2 answers

Tensorflow: None of the MLIR optimization passes are enabled (registered 1)

I am using a very small model for testing purposes using tensorflow 2.3 and keras. Looking at my terminal, I get the following warning: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:118] None of the MLIR optimization passes are enabled…
MichaelJanz
  • 1,775
  • 2
  • 8
  • 23
75
votes
12 answers

How to return history of validation loss in Keras

Using Anaconda Python 2.7 Windows 10. I am training a language model using the Keras exmaple: print('Build model...') model = Sequential() model.add(GRU(512, return_sequences=True, input_shape=(maxlen,…
ishido
  • 4,065
  • 9
  • 32
  • 42
74
votes
14 answers

How to export Keras .h5 to tensorflow .pb?

I have fine-tuned inception model with a new dataset and saved it as ".h5" model in Keras. now my goal is to run my model on android Tensorflow which accepts ".pb" extension only. question is that is there any library in Keras or tensorflow to do…
Solix
  • 1,076
  • 2
  • 9
  • 13
73
votes
9 answers

Keras model.summary() object to string

I want to write a *.txt file with the neural network hyperparameters and the model architecture. Is it possible to write the object model.summary() to my output file? (...) summary = str(model.summary()) (...) out = open(filename +…
lmpeixoto
  • 853
  • 1
  • 6
  • 7
73
votes
9 answers

Error when checking model input: expected convolution2d_input_1 to have 4 dimensions, but got array with shape (32, 32, 3)

I want to train a deep network starting with the following layer: model = Sequential() model.add(Conv2D(32, 3, 3, input_shape=(32, 32, 3))) using history = model.fit_generator(get_training_data(), samples_per_epoch=1,…
Oblomov
  • 8,953
  • 22
  • 60
  • 106
71
votes
11 answers

ImportError: cannot import name 'adam' from 'keras.optimizers'

I am trying to import Keras but I get the following error: ImportError: cannot import name 'adam' from 'keras.optimizers' (/usr/local/lib/python3.8/dist-packages/keras/optimizers/__init__.py) The import is invoked here: from tensorflow import…
dclipca
  • 1,739
  • 1
  • 16
  • 51
71
votes
4 answers

Keras - Difference between categorical_accuracy and sparse_categorical_accuracy

What is the difference between categorical_accuracy and sparse_categorical_accuracy in Keras? There is no hint in the documentation for these metrics, and by asking Dr. Google, I did not find answers for that either. The source code can be found…
jcklie
  • 4,054
  • 3
  • 24
  • 42
71
votes
4 answers

How to find Number of parameters of a keras model?

For a Feedforward Network (FFN), it is easy to compute the number of parameters. Given a CNN, LSTM etc is there a quick way to find the number of parameters in a keras model?
Anuj Gupta
  • 6,328
  • 7
  • 36
  • 55
68
votes
1 answer

How to define max_queue_size, workers and use_multiprocessing in keras fit_generator()?

I am applying transfer-learning on a pre-trained network using the GPU version of keras. I don't understand how to define the parameters max_queue_size, workers, and use_multiprocessing. If I change these parameters (primarily to speed-up learning),…
Sophie Crommelinck
  • 1,053
  • 1
  • 9
  • 13
68
votes
5 answers

Dimension of shape in conv1D

I have tried to build a CNN with one layer, but I have some problem with it. Indeed, the compilator says me that ValueError: Error when checking model input: expected conv1d_1_input to have 3 dimensions, but got array with shape (569, 30) This is…
protti
  • 871
  • 1
  • 9
  • 12
68
votes
7 answers

Convert Keras model to C++

I am using Keras (with Theano) to train my CNN model. Does anyone has idea how can I use it in my C++ application? Does anyone tried something similar? I have idea to write some python code that will generate a c++ code with network functions - any…
pplonski
  • 5,023
  • 1
  • 30
  • 34
67
votes
10 answers

Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'

Im attempting to find model performance metrics (F1 score, accuracy, recall) following this guide https://machinelearningmastery.com/how-to-calculate-precision-recall-f1-and-more-for-deep-learning-models/ This exact code was working a few months ago…
Greig Fotheringham
  • 683
  • 1
  • 5
  • 5
67
votes
3 answers

How do I check if keras is using gpu version of tensorflow?

When I run a keras script, I get the following output: Using TensorFlow backend. 2017-06-14 17:40:44.621761: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are…
humble
  • 2,016
  • 4
  • 27
  • 36
66
votes
2 answers

what is the default kernel_initializer in keras

In the user manual, it shows the different kernel_initializer below https://keras.io/initializers/ the main purpose is to initialize the weight matrix in the neural network. Anyone knows what the default initializer is? the document didn't show the…
Chris Chou
  • 832
  • 1
  • 6
  • 9
66
votes
6 answers

Keras Text Preprocessing - Saving Tokenizer object to file for scoring

I've trained a sentiment classifier model using Keras library by following the below steps(broadly). Convert Text corpus into sequences using Tokenizer object/class Build a model using the model.fit() method Evaluate this model Now for scoring…