Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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.

Filter by
Sorted by
Tagged with
265 votes
10 answers
432k views

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 ...
Hendrik's user avatar
  • 8,637
125 votes
2 answers
115k views

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 ...
Tac-Tics's user avatar
  • 1,370
68 votes
2 answers
65k views

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 ...
Master M's user avatar
  • 783
65 votes
5 answers
200k views

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: ...
ZelelB's user avatar
  • 1,057
64 votes
4 answers
78k views

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 ...
hipoglucido's user avatar
  • 1,170
59 votes
3 answers
115k views

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 ...
Ermene's user avatar
  • 693
47 votes
2 answers
128k views

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 ...
rnso's user avatar
  • 1,578
46 votes
3 answers
52k views

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 ...
Nagendra Prasad's user avatar
46 votes
2 answers
75k views

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 ...
Rkz's user avatar
  • 1,033
44 votes
6 answers
62k views

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: ...
N.IT's user avatar
  • 1,995
44 votes
4 answers
57k views

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 ...
Hector Blandin's user avatar
40 votes
8 answers
76k views

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 ...
James Bond's user avatar
  • 1,195
40 votes
1 answer
21k views

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

I am still confused about the difference between Dense and TimeDistributedDense of Keras ...
fluency03's user avatar
  • 503
39 votes
1 answer
57k views

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 ...
pseudomonas's user avatar
  • 1,042
39 votes
2 answers
106k views

Keras difference beetween val_loss and loss during training

What is the difference between val_loss and loss during training in Keras? E.g. ...
Vladimir Shebuniayeu's user avatar
37 votes
5 answers
66k views

What to set in steps_per_epoch in Keras' fit_generator?

I am replicating, in Keras, the work of a paper where I know the values of epoch and batch_size. Since the dataset is quite ...
yamini goel's user avatar
37 votes
1 answer
37k views

RNN's with multiple features

I have a bit of self taught knowledge working with Machine Learning algorithms (the basic Random Forest and Linear Regression type stuff). I decided to branch out and begin learning RNN's with Keras. ...
Rjay155's user avatar
  • 1,215
35 votes
1 answer
71k views

What is the best Keras model for multi-class classification?

I am working on research, where need to classify one of three event WINNER=(win, draw, lose) ...
SpanishBoy's user avatar
35 votes
2 answers
22k views

What is/are the default filters used by Keras Convolution2d()?

I am pretty new to neural networks, but I understand linear algebra and the mathematics of convolution pretty decently. I am trying to understand the example code I find in various places on the net ...
ChrisFal's user avatar
  • 453
35 votes
4 answers
80k views

How to use LeakyRelu as activation function in sequence DNN in keras?When it perfoms better than Relu?

How do you use LeakyRelu as an activation function in sequence DNN in keras? If I want to write something similar to: ...
user10296606's user avatar
  • 1,844
32 votes
2 answers
25k views

When should one use L1, L2 regularization instead of dropout layer, given that both serve same purpose of reducing overfitting?

In Keras, there are 2 methods to reduce over-fitting. L1,L2 regularization or dropout layer. What are some situations to use L1,L2 regularization instead of dropout layer? What are some situations ...
user781486's user avatar
  • 1,415
31 votes
2 answers
29k views

How to feed LSTM with different input array sizes?

If I like to write a LSTM network and feed it by different input array sizes, how is it possible? For example I want to get voice messages or text messages in a ...
user3486308's user avatar
  • 1,280
31 votes
3 answers
53k views

Keras Callback example for saving a model after every epoch?

Can someone please post a straightforward example of Keras using a callback to save a model after every epoch? I can find examples of saving weights, but I want to be able to save a completely ...
I_Play_With_Data's user avatar
29 votes
2 answers
30k views

What is the difference between fit() and fit_generator() in Keras?

What is the difference between fit() and fit_generator() in Keras? When should I use fit() ...
N.IT's user avatar
  • 1,995
28 votes
2 answers
18k views

Is there away to change the metric used by the Early Stopping callback in Keras?

When using the early stopping callback in Keras, training stops when some metric (usually validation loss) is not increasing. Is there a way to use another metric (like precision, recall, or f-measure)...
P.Joseph's user avatar
  • 393
28 votes
2 answers
12k views

Keras vs. tf.keras

I'm a bit confused in choosing between Keras (keras-team/keras) and tf.keras (tensorflow/tensorflow/python/keras/) for my new research project. There is a debate that Keras isn't owned by anyone, so ...
Mo-'s user avatar
  • 1,255
27 votes
3 answers
39k views

How to deal with string labels in multi-class classification with keras?

I am newbie on machine learning and keras and now working a multi-class image classification problem using keras. The input is tagged image. After some pre-processing, the training data is represented ...
Dracarys's user avatar
  • 393
25 votes
9 answers
66k views

How can I get prediction for only one instance in Keras?

When I request Keras to apply prediction with a fitted model to a new dataset without label like this: model1.predict_classes(X_test) it works fine. But when I ...
Hendrik's user avatar
  • 8,637
25 votes
4 answers
97k views

What does the output of model.predict function from Keras mean?

I have built a LSTM model to predict duplicate questions on the Quora official dataset. The test labels are 0 or 1. 1 indicates the question pair is duplicate. After building the model using ...
Dookoto_Sea's user avatar
24 votes
1 answer
19k views

What is Monte Carlo dropout?

I understand how to use MC dropout from this answer, but I don't understand how MC dropout works, what its purpose is, and how it differs from normal dropout.
Arka Mallick's user avatar
24 votes
2 answers
55k views

What are kernel initializers and what is their significance?

I was looking at code and found this: model.add(Dense(13, input_dim=13, kernel_initializer='normal', activation='relu')) I was keen to know about ...
thanatoz's user avatar
  • 2,425
24 votes
6 answers
29k views

Keras -- Transfer learning -- changing Input tensor shape

This post seems to indicate that what I want to accomplish is not possible. However, I'm not convinced of this -- given what I've already done, I don't see why what I want to do can not be achieved... ...
aweeeezy's user avatar
  • 501
24 votes
2 answers
10k views

Choosing between TensorFlow or Theano as backend for Keras

Keras supports both TensorFlow and Theano as backend: what are the pros/cons of choosing one versus the other, besides the fact that currently not all operations are implemented with the TensorFlow ...
Franck Dernoncourt's user avatar
22 votes
1 answer
10k views

What are the pros and cons of Keras and TFLearn?

What are the pros and cons of Keras and TFlearn? When is one library preferred over the other?
22 votes
1 answer
3k views

Understanding Timestamps and Batchsize of Keras LSTM considering Hiddenstates and TBPTT

What I'm trying to do What I am trying to do is predicting the next data-point $x_t$ for each point in the timeseries $[x_0, x_1, x_2,...,x_T]$ in the context of a date-stream in real-time, in theory ...
user avatar
21 votes
2 answers
36k views

In CNN, why do we increase the number of filters in deeper Convolution layers for complex images?

I have been doing this online course Introduction to TensorFlow for AI, ML and DL. Here in one part, they were showing a CNN model for classifying human and horses. In this model, the first ...
Sanjay's user avatar
  • 333
21 votes
1 answer
25k views

What do "compile", "fit", and "predict" do in Keras sequential models?

I am a little confused between these two parts of Keras sequential models functions. May someone explains what is exactly the job of each one? I mean ...
user3486308's user avatar
  • 1,280
21 votes
4 answers
34k views

How to maximize recall?

I'm a little bit new to machine learning. I am using a neural network to classify images. There are two possible classes. I am using a Sigmoid activation at the ...
Louis's user avatar
  • 404
21 votes
2 answers
25k views

What is the job of "RepeatVector" and "TimeDistributed"?

I read about them in Keras documentation and other websites, but I couldn't exactly understand what exactly they do and how should we use them in designing ...
user3486308's user avatar
  • 1,280
21 votes
3 answers
78k views

How to get predictions with predict_generator on streaming test data in Keras?

In the Keras blog on training convnets from scratch, the code shows only the network running on training and validation data. What about test data? Is the validation data the same as test data (I ...
pseudomonas's user avatar
  • 1,042
21 votes
4 answers
22k views

Hyperparameter search for LSTM-RNN using Keras (Python)

From Keras RNN Tutorial: "RNNs are tricky. Choice of batch size is important, choice of loss and optimizer is critical, etc. Some configurations won't converge." So this is more a general question ...
wacax's user avatar
  • 3,400
20 votes
2 answers
14k views

What are the differences between Convolutional1D, Convolutional2D, and Convolutional3D?

I've been learning about Convolutional Neural Networks. When looking at Keras examples, I came across three different convolution methods. Namely, 1D, 2D & 3D. ...
Saurabh's user avatar
  • 347
20 votes
3 answers
22k views

How to create custom Activation functions in Keras / TensorFlow?

I'm using keras and I wanted to add my own activation function myf to tensorflow backend. how to define the new function and make it operational. so instead of the line of code: ...
Basta's user avatar
  • 201
19 votes
2 answers
32k views

Sample Importance (Training Weights) in Keras

How do you add more importance to some samples than others (sample weights) in Keras? I'm not looking for class_weightwhich is a fix for unbalanced datasets. ...
wacax's user avatar
  • 3,400
18 votes
7 answers
15k views

Why does Keras need TensorFlow as backend?

Why does Keras need the TensorFlow engine? I am not getting correct directions on why we need Keras. We can use TensorFlow to build a neural network model, but why do most people use Keras with ...
star's user avatar
  • 1,481
18 votes
3 answers
44k views

How to determine feature importance in a neural network?

I have a neural network to solve a time series forecasting problem. It is a sequence-to-sequence neural network and currently it is trained on samples each with ten features. The performance of the ...
Aesir's user avatar
  • 458
17 votes
5 answers
70k views

High model accuracy vs very low validation accuarcy

I'm building a sentiment analysis program in python using Keras Sequential model for deep learning my data is 20,000 tweets: positive tweets: 9152 tweets negative tweets: 10849 tweets I wrote a ...
Amy.Dj's user avatar
  • 173
17 votes
2 answers
39k views

Custom loss function with additional parameter in Keras

I'm looking for a way to create a loss function that looks like this: The function should then maximize for the reward. Is this possible to achieve in Keras? Any suggestions how this can be achieved ...
Nickpick's user avatar
  • 661
16 votes
5 answers
8k views

Why does adding a dropout layer improve deep/machine learning performance, given that dropout suppresses some neurons from the model?

If removing some neurons results in a better performing model, why not use a simpler neural network with fewer layers and fewer neurons in the first place? Why build a bigger, more complicated model ...
user781486's user avatar
  • 1,415
16 votes
5 answers
678 views

What more does TensorFlow offer to keras?

I'm aware that keras serves as a high-level interface to TensorFlow. But it seems to me that keras can do many functionalities on its own (data input, model creation, training, evaluation). ...
Javier's user avatar
  • 362

1
2 3 4 5
55