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
254 votes
10 answers
404k 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,297
30 votes
2 answers
25k 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,260
16 votes
1 answer
20k views

Multi-dimentional and multivariate Time-Series forecast (RNN/LSTM) Keras

I have been trying to understand how to represent and shape data to make a multidimentional and multivariate time series forecast using Keras (or TensorFlow) but I am still very unclear after reading ...
Bastien's user avatar
  • 263
120 votes
2 answers
110k 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,320
13 votes
1 answer
15k views

How to Predict the future values of time horizon with Keras?

I just built this LSTM neural network with Keras ...
Nbenz's user avatar
  • 273
38 votes
4 answers
49k 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,935
59 votes
3 answers
112k 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
17 votes
7 answers
14k 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,411
14 votes
3 answers
55k views

Keras Sequential model returns loss 'nan'

I'm implementing a neural network with Keras, but the Sequential model returns nan as loss value. I have sigmoid activation ...
pairon's user avatar
  • 395
10 votes
3 answers
5k views

How to use a dataset with only one category of data

I am performing a classification task, to try to detect an object. A picture of the environment is taken, candidates are generated of this possible object using vision algorithms, and once isolated, ...
Finn Williams's user avatar
63 votes
4 answers
77k 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,160
45 votes
2 answers
73k 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,013
39 votes
1 answer
56k 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,032
37 votes
1 answer
36k 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,205
27 votes
2 answers
17k 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
  • 383
16 votes
3 answers
34k 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
  • 418
15 votes
2 answers
12k views

Can overfitting occur even with validation loss still dropping?

I have a convolutional + LSTM model in Keras, similar to this (ref 1), that I am using for a Kaggle contest. Architecture is shown below. I have trained it on my labeled set of 11000 samples (two ...
DeusXMachina's user avatar
15 votes
5 answers
7k 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,295
14 votes
2 answers
14k views

How to implement "one-to-many" and "many-to-many" sequence prediction in Keras?

I struggle to interpret the Keras coding difference for one-to-many (e. g. classification of single images) and many-to-many (e. g. classification of image sequences) sequence labeling. I frequently ...
Hendrik's user avatar
  • 8,297
13 votes
2 answers
24k views

Activation function between LSTM layers

I'm aware the LSTM cell uses both sigmoid and tanh activation functions internally, however when creating a stacked LSTM architecture does it make sense to pass their outputs through an activation ...
lsfischer's user avatar
  • 242
12 votes
3 answers
17k views

What are the consequences of not freezing layers in transfer learning?

I am trying to fine tune some code from a Kaggle kernel. The model uses pretrained VGG16 weights (via 'imagenet') for transfer learning. However, I notice there is no layer freezing of layers as is ...
Borealis's user avatar
  • 337
12 votes
4 answers
10k views

Neural networks - Find most similar images

I am working with Python, scikit-learn and keras. I have 3000 thousands images of front-faced watches like the following ones: Watch_1, Watch_2, Watch_3. I want to write a program which receives as ...
Outcast's user avatar
  • 1,027
9 votes
1 answer
2k views

Binary classification of every time series step based on past and future values

I'm currently facing a Machine Learning problem and I've reached a point where I need some help to proceed. I have various time series of positional (x, ...
Chryb's user avatar
  • 245
9 votes
2 answers
14k views

What does an Input layer of shape=(None,) or (None,12) actually mean?

Is this telling the model that there are two dimensions (i.e. it’s a matrix) but we don’t yet know the size of that particular dimension? If so, how can the model be compiled? Doesn’t the size of each ...
Nic Cottrell's user avatar
8 votes
1 answer
4k views

Is time series multi-step ahead forecasting a sequence to sequence problem?

I'm using the keras package in order to train an LSTM for a univariate time series of type numeric (float). Performing a 1-step ahead forecast is trivial, but I'm not sure how to perform a, let's say, ...
sevelf's user avatar
  • 81
7 votes
1 answer
29k views

Validation loss increases and validation accuracy decreases

I have an issue with my model. I'm trying to use the most basic Conv1D model to analyze review data and output a rating of 1-5 class, therefore the loss is categorical_crossentropy. Model structure is ...
stranger's user avatar
6 votes
1 answer
6k views

Keras: How to normalize dataframe with continuous and categorical data?

I have a dataframe with about 50 columns. The columns are either categorical or continuous data. The continuous data can be between 0.000001-1.00000 or they can be between 500,000-5,000,000. The ...
user1367204's user avatar
6 votes
2 answers
12k views

Keras custom loss function as True Negatives by (True Negatives plus False Positives)

I have some model for which I can construct the confusion matrix, although I need a custom loss function which will be as: true negatives (TN): We predicted no, and it is no. false positives (FP): ...
Nikhil Verma's user avatar
6 votes
2 answers
15k views

Loss being outputed as nan in keras RNN

Since the first Epoch of the RNN, the loss value is being outputted as nan. Epoch 1/100 9787/9787 [==============================] - 22s 2ms/step - loss: nan I have normalized the data. ...
Erik Dz's user avatar
  • 73
6 votes
4 answers
766 views

What are the possible ways to detect skin while classifying diseases?

I am working on a skin disease classification problem where I have successfully created a classifier ( TensorFlow + Keras ) which can classify images of two skin diseases. The sample image needs to ...
Shubham Panchal's user avatar
6 votes
1 answer
4k views

Keras CNN with low/constant accuracies

I am dealing with the Street View House Number recognition problem. I am trying to train a CNN with Keras. Here is how I prepared the input: ...
Andrea Sindico's user avatar
6 votes
2 answers
27k views

Keras - no prediction probability for multiple output models?

I have built the following model: ...
Hendrik's user avatar
  • 8,297
5 votes
2 answers
20k views

Get multiple output from Keras

I have a regression problem which I have to predict 3 numerical values from a provided data. For example let's say I have a data set containing ...
Sathindu's user avatar
  • 161
4 votes
5 answers
6k views

Applying a keras model working with greyscale images to RGB images

I followed this basic classification TensorFlow tutorial using the Fashion MNIST dataset. The training set contains 60,000 28x28 pixels greyscale images, split into 10 classes (trouser, pullover, shoe,...
Sheldon's user avatar
  • 195
3 votes
1 answer
364 views

ANN on Pattern Recognition

I have been trying to apply a simple neural network using keras to predict a sequence of numbers and the rule is if the input integer is odd it should be 4 and if its even it should be 2. Yet the ...
Sam Thomas's user avatar
2 votes
2 answers
5k views

loss/val_loss are decreasing but accuracies are the same in LSTM!

I am trying to train a LSTM model, but the problem is that the loss and val_loss are decreasing from 12 and 5 to less than 0.01, but the training set ...
user3486308's user avatar
  • 1,260
2 votes
2 answers
27k views

Error: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=2

I am getting the error: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=2 Using the model: ...
Midnight's user avatar
  • 129
2 votes
1 answer
4k views

What if My Word is not in Bert model vocabulary?

I am doing NER using Bert Model. I have encountered some words in my datasets which is not a part of bert vocabulary and i am getting the same error while converting words to ids. Can someone help me ...
AMIT KUMAR's user avatar
45 votes
2 answers
116k 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,536
43 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
39 votes
7 answers
68k 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,145
35 votes
5 answers
61k 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
31 votes
3 answers
50k 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
25 votes
4 answers
91k 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
6 answers
28k 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
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?
21 votes
4 answers
21k 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,330
20 votes
2 answers
23k 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,260
17 votes
2 answers
38k 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
  • 651
16 votes
1 answer
35k views

How to define a custom performance metric in Keras?

I tried to define a custom metric fuction (F1-Score) in Keras (Tensorflow backend) according to the following: ...
Hendrik's user avatar
  • 8,297