Questions tagged [keras-layer]
1512 questions
7
votes
4 answers
Keras reset layer numbers
Keras assigns incrementing ID numbers to layers of the same type, e.g. max_pooling1d_7, max_pooling1d_8, max_pooling1d_9,etc. Each iteration of my code constructs a new model, starting with model = Sequential() and then adding layers via…

Ron Cohen
- 2,815
- 5
- 30
- 45
7
votes
2 answers
Keras : Why does Sequential and Model give different outputs?
I am using Keras for computing a simple sequence classification neural network. I played with the different module and I found that there are two way to create Sequential neural network.
The first way is to use Sequential API. This is the most…

Clement Viricel
- 256
- 3
- 7
7
votes
1 answer
Keras initializers outside Keras
I want to initialize a 4*11 matrix using glorot uniform in Keras, using following code:
import keras
keras.initializers.glorot_uniform((4,11))
I get this output :
How can I visualize the…

Hitesh
- 1,285
- 6
- 20
- 36
7
votes
1 answer
Why does the call method gets called at build time in Keras layers
So I'm trying to implement my own layer in Keras, using the provided example:
class MyLayer(Layer):
def __init__(self, output_dim, **kwargs):
self.output_dim = output_dim
super(MyLayer, self).__init__(**kwargs)
def…

gotch4
- 13,093
- 29
- 107
- 170
7
votes
1 answer
Keras dot product layer by last axis
I have Siamese network that produce feature maps for images, how do I get dot product of those feature maps with Keras?
input_a = Input(input_size)
input_b = Input(input_size)
fe_net_a = model(input_a)
fe_net_b = model(input_b)
E.g. if output…

DikobrAz
- 3,557
- 4
- 35
- 53
7
votes
0 answers
how do I copy layers in keras to create a similar but not identical model
How do I take an existing model and create a new one that has batchnormalisation after each dropout layer?
I have tried this:
bn = []
for layer in model.layers:
bn.append(layer)
if type(layer) is Dropout:
…

simon
- 2,561
- 16
- 26
7
votes
2 answers
Add dense layer before LSTM layer in keras or Tensorflow?
I am trying to implement a denoising autoencoder with an LSTM layer in between. The architecture goes following.
FC layer -> FC layer -> LSTM cell -> FC layer -> FC layer.
I am unable to understand how my input dimension should be to implement…

Nilay Thakor
- 375
- 1
- 3
- 13
7
votes
1 answer
Multi-Output Multi-Class Keras Model
For each input I have, I have a 49x2 matrix associated. Here's what 1 input-output couple looks like
input :
[Car1, Car2, Car3 ..., Car118]
output :
[[Label1 Label2]
[Label1 Label2]
...
[Label1 Label2]]
Where both Label1 and Label2 are…

Julien Bélanger
- 73
- 1
- 4
7
votes
1 answer
How to merge two LSTM layers in Keras
I’m working with Keras on a sentence similarity task (using the STS dataset) and am having problems merging the layers. The data consists of 1184 sentence pairs each scored between 0 and 5. Below are the shapes of my numpy arrays. I’ve padded each…

pchowdhry
- 303
- 5
- 12
7
votes
2 answers
How to perform deconvolution in Keras/ Theano?
I am trying to implement deconvolution in Keras. My model definition is as follows:
model=Sequential()
model.add(Convolution2D(32, 3, 3, border_mode='same',
…

Avijit Dasgupta
- 2,055
- 3
- 22
- 36
6
votes
1 answer
Unexpected results with CuDNNLSTM (instead of LSTM) layer
I have posted this question as an issue in Keras' Github but figured it might reach a broader audience here.
System information
Have I written custom code (as opposed to using example directory): Minimal change to official Keras tutorial
OS…

Orest Xherija
- 434
- 4
- 18
6
votes
1 answer
trainable_variables attribute of the custom layer in Keras returns empty list
I tried to build my own custom layer in tensorflow/keras that enforces the layer to be symmetric and what I ended up with is the following:
import tensorflow as tf
from tensorflow.python.framework.ops import…

xabdax
- 165
- 1
- 4
6
votes
1 answer
How to feed Bert embeddings to LSTM
I am working on a Bert + MLP model for text classification problem. Essentially, I am trying to replace the MLP model with a basic LSTM model.
Is it possible to create a LSTM with embedding? Or, is best to create a LSTM with embedded layer?
More…

Green
- 695
- 2
- 9
- 21
6
votes
1 answer
What is the difference between dropout layer and dropout parameter in any keras layer
What is the difference between the Dropout layer and the dropout and recurrent_droput parameters in keras? Do they all serve the same purpose?
Example:
model.add(Dropout(0.2)) # layer
model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2)) #…

Nandini Matam
- 119
- 1
- 10
6
votes
1 answer
Modify ResNet50 output layer for regression
I am trying to create a ResNet50 model for a regression problem, with an output value ranging from -1 to 1.
I omitted the classes argument, and in my preprocessing step I resize my images to 224,224,3.
I try to create the model with
def…

DaveS
- 105
- 1
- 1
- 8