# Questions tagged [keras]

Keras is a minimalist, highly modular neural network library providing a high-level API in Python as well as an R interface that allows for rapid prototyping and the use of one of several computational back-ends.

17,126 questions

**0**

votes

**0**answers

4 views

### how to calculate differential entropy over a tensor in python keras

I have been struggling on this and could not get it to work. hope someone can help me with this.
I want to calculate the differential entropy on each row of the tensor.
Just for information My model ...

**0**

votes

**0**answers

4 views

### Python ValueError:bad marshal data?

I'm trying to load a keras model , I get this error
I am using this packages:
Keras: 2.2.4 Tensorflow: 1.13.x Python 2.7.13 Raspbian GNU/Linux 9.8
Using TensorFlow backend.
Now loading Model...
...

**0**

votes

**2**answers

10 views

### How to create my own dataset for keras model.fit() using Tensorflow(python)?

I want to train a simple classification neural network which can classify the data into 2 types, i.e. true or false.
I have 29 data along with respective labels available with me. I want to parse ...

**0**

votes

**0**answers

15 views

### TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tensor use tf.map_fn

So I run into this error, I am trying to have a custom layer in seq2seq model.
the main function that runs into error is rev_entropy and in the first for loop when it wants to iterate over the tensor.
...

**0**

votes

**1**answer

20 views

### Keras - How should I specify the input_shape of my training data? (The data are gray-scale images)

I'm using Conv2d in Keras to do some classification for gray-scale images. Each image is stored as a 240*300 matrix, (namely a list [ A_1, A_2,..., A_240 ] and each A_k is a list of length 300
How ...

**0**

votes

**1**answer

15 views

### Not able to convert keras model to tfjs layers using tensorflowjs_converter

I am trying to use tensorflowjs for the first time alongside react to build a web application, I have trained my model using keras and have saved my weights into a hdf5 file format and am referring to ...

**1**

vote

**0**answers

14 views

### Decimal to binary tensor conversion

I'm trying to convert a one-hot tensor to a 8-binary tensor array. I'm using tf.keras.backend.argmax to find the decimal index which I'd like to convert to a binary representation.
When using tf....

**0**

votes

**1**answer

16 views

### How can I improve my dataset , layers and hyperparameters to achieve my goal?

Hi to all the community,
I'm currently working on a Neural Network to provide some simulation about the topic I'm developing for my graduation thesis in biomedical engineering and I'm currently facing ...

**0**

votes

**0**answers

17 views

### Keras acc and val_acc is high during training but prediction is really bad

I'm trying to create a CNN which classifies images into 3 classes.
- I'm using the following versions:
+ Keras 2.2.4
+ Python 3.6.8
+ tensorflow 1.13.1
While training my val_acc is above 90%. But ...

**0**

votes

**0**answers

11 views

### Reticulate installation failure

I'm trying to install the reticulate package for the use of keras. It terminates with an Error.
I tried to install reticulate manual using github and over CRAN. Both are terminating with the same ...

**0**

votes

**1**answer

22 views

### Keras ValueError: Dimensions must be equal issue

My model's layers look like
Layer (type) Output Shape Param #
=================================================================
input_18 (InputLayer) (None, 64, ...

**0**

votes

**0**answers

16 views

### How to solve Problem with dimension in Keras and estimator

I'm trying to convert this code using estimator, because I want to learn how to distribute the training, and I understand is using estimator with train_and_evaluate in Tensorflow 1.13
import ...

**1**

vote

**1**answer

14 views

### Tensorflow/keras: “logits and labels must have the same first dimension” How to squeeze logits or expand labels?

I'm trying to make a simple CNN classifier model. For my training images (BATCH_SIZEx227x227x1) and labels (BATCH_SIZEx7) datasets, I'm using numpy ndarrays that are fed to the model in batches via ...

**0**

votes

**0**answers

21 views

### how can I calculate entropy on array with shape (?,20) along rows

So I need to calculate entropy function on each row of my array with shape(?,20).
Also, this calculation is going to be on one layer of Seq2Seq model.
when I pass the array to this function, the ...

**0**

votes

**1**answer

21 views

### How to split model between 2 GPUs with keras in Tensorflow?

Essentially, I am looking for something like with tf.device('/device:GPU:0' for keras. I want to put my operations on different GPUs. I am using a Sequential model following lines of
...
model....

**0**

votes

**0**answers

20 views

### torch detect GPU but TF can't find it

I have followed all instruction and now, torch runs on GPU but TF can't detects GPU.
I have tried a lot of StackOverflow topics but after all, I couldn't!
the result of this:
torch.cuda....

**1**

vote

**1**answer

19 views

### Units in Dense layer in Keras

I am trying to understand a concept of ANN architecture in Keras. Number of input neurons in any NN should be equal to the number of features/attributes/columns. So, in the case of having matrix of (...

**0**

votes

**0**answers

17 views

### Extract feature labels and X_test labels are equal?

I trained a keras model for image classification i want to know that when i extract the model layer feature i got the predict feature labels are these labels equal to the test labels

**0**

votes

**0**answers

12 views

### Distributed training on CPU's multiple cores in Keras

According to what I read in different posts and blogs and my limited trials, it looks like both Tensorflow and Keras use as many CPU cores available on an individual machine. That makes sense (and is ...

**0**

votes

**0**answers

18 views

### How to divide label data into time series in Keras?

I'm trying to build a simple lstm model with timesteps and using a small dataset which contains 36 rows and a total of 3 features - year, month, price.
I used pandas and numpy to reshape year and ...

**0**

votes

**0**answers

11 views

### Autofilter for Time Series in Python/Keras using Conv1d

It may looks like a lot of code, but most of the code is comments or formatting to make it more readable.
Given:
If I define my variable of interest, "sequence", as follows:
# define input sequence
...

**0**

votes

**0**answers

13 views

### how can I fine-tune with new dataset a fine-tuned network with Keras? Input 0 is incompatible with layer flatten: expected min_ndim=3, found ndim=2

I struggle with fine-tune a network that I have trained on a imagnet pretrained network with keras.
Firstly, I fine-tuned a network of 10 classes on pretrained imagenet.
Then I want to train 3 ...

**1**

vote

**1**answer

15 views

### How to reset Keras data generator in R?

When we are dealing with data generator ( for training or testing purposes) in Keras, there are cases when we want to reset the generator.
The following code is an example of test_generator in R ...

**1**

vote

**1**answer

11 views

### How to save input memory for keras layers?

Specifically, can I save the memory of input by "reusing" them especially in prediction procedure?
Considering the following scenarios:
case 1:
... # net = previous_layer
net = Conv2D(64, 3)(net)
...

**0**

votes

**0**answers

11 views

### How to understand rescale to 1/255 twice on Keras for better result

here are my two training setting for Mnist with ResNet34 on Keras
The only differences between two networks are about "rescale"
So here are my two questions:
why the first network has better ...

**0**

votes

**0**answers

11 views

### implement keras ConvLSTM2D with seq frames to forcast one single value

I try to implement an ConvLSTM2D to use a sequence of low resolution video frames to make a prediction of what will append after. The prediction is not a Frame or a video it is a single values (kind ...

**0**

votes

**0**answers

15 views

### How exactly the keras layer works?

I try to create a sentiment analysis that have 7 classification.
Let's say, I have 100.000 unique word (already converted into 100.000 integer) which have the longest input is 41.
I created 3 layer ...

**1**

vote

**0**answers

25 views

### Using a Pre-trained Keras model in a Tensorflow graph

I have a pre-trained Keras model that takes inputs of an arbitrary dimension and outputs a single classification result. I do not need to train the model any further so I would be happy to convert all ...

**0**

votes

**0**answers

20 views

### Tensorflow 2.0 custom layer that accepts more than 1 input tensor

I'm working on the TensorFlow 2.0 alpha0 and I tried to follow Custom layers in order to implement my own custom layer that accepts two input tensors. This is what I have
import tensorflow as tf
from ...

**0**

votes

**1**answer

17 views

### Categorical focal loss on keras

I would like to use categorical focal loss in tf/keras. Binary Focal loss works for me but not the code I found for categorical f.l. Does someone have this ?

**0**

votes

**1**answer

25 views

### How to add Conv2D layers with LSTM in Keras?

I'm trying to identify the sequence of images. I've 2 images and I need to identify the 3rd one. All are color images.
I'm getting below error:
ValueError: Error when checking input: expected
...

**0**

votes

**0**answers

9 views

### How can i create GUI to use keras model with Tkinter with an array input?

I tried below code, but it didn't work, I have a GUI with form for entering input, and now i want to use this input to predict, i have already train and save my keras model into .h5 file! any help ...

**-1**

votes

**0**answers

26 views

### How to use Keras model to forecast the future value?

My model:
model = Sequential()
model.add(LSTM(512, input_shape=(None, 1), return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(512, input_shape=(None, 1)))
model.add(Dropout(0.3))
model....

**-1**

votes

**0**answers

19 views

### How to use the output of a lstm model as input of another model

I have two models, one is a keras LSTM model and the other one is a scikit-learn gradient boosting classifier. And I want to use the output of the LSTM model as one of the input variables for the ...

**0**

votes

**1**answer

27 views

### How to train deep learning model, if one class has large data compared to other classes

I am using keras for a text to speech project , and for this project I have almost 1000 labeled data.
since the sounds length in dataset are different , I resized all of them to the maximum length.
so ...

**0**

votes

**0**answers

22 views

### model gets correct input dimensions, but throws dimension error

Edit: Solved. Spelling mistake, see first comment
I use a MobileNetV2 pretrained model in Keras2/TF2
My images are scaled to 224x224
I set the model input shape: input_shape=(224,224,3)
Later I ...

**0**

votes

**1**answer

27 views

### Is it possible to use Keras to optimize the coefficients of a mathematical function?

I'm very new to Keras a neural network in general. and I was wondering if I had a list of points (x,y) that came from a quadratic function that looks like this (ax^2+bx+c) is it possible
to feed the ...

**0**

votes

**0**answers

21 views

### InvalidArgumentError: Input to reshape is a tensor with 50 values, but the requested shape has 1

I'm using Keras functional API for CNN, the model is like this: The input is an image of size 50x50x1, and there are 2 output layers, one with 3 labels and the second with 7 labels, hidden layers ...

**1**

vote

**0**answers

13 views

### Value error while predicting result using Convlstm2d with attention layer?

I am integrating Attention mechanism with convlstm2d. I can build and fit the model but getting value error while predicting the result.
I am using attention layer implementation of from:
https://www....

**0**

votes

**0**answers

20 views

### Issue with policy gradient code for pong-v0 in Keras

I am new with machine learning and trying one code I wrote on pong-v0. I am using policy gradient method and calculating advantage function by subtracting value estimator(baseline) with discounted ...

**0**

votes

**0**answers

17 views

### How can I fix the 'instance of class Layer' error by creating LSTM with multiple inputs?

I'm creating a LSTM model with multiple categorical inputs. I've 169.856 samples, max 105 timesteps per sample (so I used paddings), and 2 categorical features. I've one label per sequence. Because ...

**0**

votes

**0**answers

16 views

### Mask-RCNN with Keras : Tried to convert 'shape' to a tensor and failed. Error: None values not supported

I am trying to run the Keras implemention of Mask_RCNN in inference mode. It is basically running this code demo.ipynb
But when I run it, I get the following error on model creation :
ValueError: ...

**-1**

votes

**0**answers

19 views

### UnboundLocalError: local variable 'zipped' referenced before assignment: Generator Error

I'm trying to build semantic segmentation model in keras. Since I use a custom data, I decided to write a custom generator to feed it to the keras function _.fit_generator and I have reached a dead-...

**1**

vote

**0**answers

23 views

### when extract keras model feature does not get the all feature labels

inputs =[input_1,input_3]
outputs =[output_1,output_3]
combine = concatenate(outputs)
output = Dense(400,activation='sigmoid',name ='dense_1')(combine)
output = Dense(num_classes,activation='softmax')...

**1**

vote

**0**answers

13 views

### Replacing multiplication operator in existing keras (tensorflow) model

I am currently using an existing Keras implementation of a certain model and I would like to study the effects of different multiplication implementations on its computational speed and accuracy.
Is ...

**0**

votes

**3**answers

39 views

### How can we train a deep learning model for input of any length?

I have created a deep learning model, using keras. I am training the model on comments of different lengths. I pre-processed the input data, and padded it to equal length. While predicting, if I give ...

**1**

vote

**0**answers

27 views

### Custom Keras Loss always returns 0

The custom Keras loss function I wrote always returns 0 as loss when evaluated. All points in my deep learning problem seem to collapse after training of one batch.
The loss I'm trying to implement ...

**2**

votes

**0**answers

14 views

### tf.keras.metrics.SpecificityAtSensitivity num_thresholds interpretation

I'm trying to get my head around tf.keras.metrics.SensitivityAtSpecificity. I'm fine with the concept of sensity and specificity in isolation, but I'm unsure how the two are related in this single ...

**1**

vote

**1**answer

28 views

### How to combine 2 vectors using element-wise multiplication training in Keras functional API?

I’m a beginner in Keras. I meet a simple problem, but I have searched for a long time and cannot find how to deal with it.
In briefly, I have 2 vectors: [a1, a2, a3] & [b1, b2, b3], and I want to ...

**1**

vote

**0**answers

12 views

### Tensorboad activation values histogram not showing up with Keras Callback

I can't see the histograms of activation values using Tensorboard on Keras.
I am currently using tensorflow 2.0 and I've followed the instructions of the Keras documentation on Callbacks. My callback ...