Questions tagged [keras-layer]
1512 questions
14
votes
2 answers
Average weights in keras models
How to average weights in Keras models, when I train few models with the same architecture with different initialisations?
Now my code looks something like this?
datagen = ImageDataGenerator(rotation_range=15,
…

Miłosz Bednarzak
- 165
- 2
- 9
14
votes
2 answers
Removing layers from a pretrained keras model gives the same output as original model
During some feature extraction experiments, I noticed that the 'model.pop()' functionality is not working as expected. For a pretrained model like vgg16, after using 'model.pop()' , model.summary() shows that the layer has been removed (expected…

Koul
- 180
- 1
- 1
- 8
14
votes
2 answers
Cannot add layers to saved Keras Model. 'Model' object has no attribute 'add'
I have a saved a model using model.save(). I'm trying to reload the model and add a few layers and tune some hyper-parameters, however, it throws the AttributeError.
Model is loaded using load_model().
I guess I'm missing understanding how to add…

Abhijit Nathwani
- 398
- 1
- 5
- 17
14
votes
2 answers
TimeDistributed vs. TimeDistributedDense Keras
I have gone through the official documentation but still can't understand what actually TimeDistributed does as a layer in Keras model?
I couldn't understand the difference between TimeDistributed and TimeDistributedDense? When will someone use…

Wasi Ahmad
- 35,739
- 32
- 114
- 161
14
votes
3 answers
How to change input shape in Sequential model in Keras
I have a sequential model that I built in Keras.
I try to figure out how to change the shape of the input. In the following example
model = Sequential()
model.add(Dense(32, input_shape=(500,)))
model.add(Dense(10,…

itamar kanter
- 1,170
- 3
- 10
- 25
13
votes
2 answers
What is the difference between a layer with a linear activation and a layer without activation?
I'm playing with Keras a little bit and I'm thinking about what is the difference between linear activation layer and no activation layer at all? Doesn't it have the same behavior? If so, what's the point of linear activation then?
I mean the…

T.Poe
- 1,949
- 6
- 28
- 59
13
votes
3 answers
Python Keras: An layer output exactly the same thing as input
I am using Keras to build a Network. During the process, I need a layer, which takes an LSTM input, doing nothing, just output exactly the same as input. i.e. if each input record of LSTM is like [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]], I am looking…

Edamame
- 23,718
- 73
- 186
- 320
13
votes
1 answer
Using Tensorflow Layers in Keras
I've been trying to build a sequential model in Keras using the pooling layer tf.nn.fractional_max_pool. I know I could try making my own custom layer in Keras, but I'm trying to see if I can use the layer already in Tensorflow. For the following…

Bart C
- 460
- 3
- 13
13
votes
2 answers
How to implement sklearn's PolynomialFeatures in tensorflow?
I am trying to implement scikit-learn's PolynomialFeatures as a layer in a feedforward neural network in tensorflow and Keras. I'll give an example using NumPy arrays for the sake of simplicity. If a batch has three samples and the activations of a…

Charlie Brummitt
- 651
- 6
- 11
13
votes
6 answers
Add a resizing layer to a keras sequential model
How can I add a resizing layer to
model = Sequential()
using
model.add(...)
To resize an image from shape (160, 320, 3) to (224,224,3) ?

Oblomov
- 8,953
- 22
- 60
- 106
11
votes
1 answer
How do I save and load BatchNormalization Layer in this Tensorflow model?
I am trying to save a model and then load it later to make some predictions; what happens is that the accuracy of the model after training is 95%+, but when I save it and then load it, the accuracy drops to nearly 10% on the same dataset.
To…

Ravish Jha
- 481
- 3
- 25
11
votes
3 answers
How to load the Keras model with custom layers from .h5 file correctly?
I built a Keras model with a custom layers, and it was saved to a .h5 file by the callback ModelCheckPoint.
When I tried to load this model after the training, the error message below showed up:
__init__() missing 1 required positional argument:…

liang
- 113
- 1
- 5
11
votes
1 answer
Extract encoder and decoder from trained autoencoder
I want to divide the autoencoder learning and applying into two parts following https://blog.keras.io/building-autoencoders-in-keras.html and using the fashion-mnist data for testing purposes:
Load the images, do the fitting that may take some…

tardis
- 1,280
- 3
- 23
- 48
11
votes
1 answer
Keras Dense layer's input is not flattened
This is my test code:
from keras import layers
input1 = layers.Input((2,3))
output = layers.Dense(4)(input1)
print(output)
The output is:
But What Happend?
The documentation says:
Note:…

yadong sun
- 113
- 1
- 4
11
votes
1 answer
How to Split the Input into different channels in Keras
I have 20 channel data each with 5000 values (total of 150,000+ records stored as .npy files on the HD).
I am following the keras fit_generator tutorial available on https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly.html to…

MuTaTeD
- 861
- 2
- 8
- 13