196 questions
435
votes
3
answers
382k
views
Keras input explanation: input_shape, units, batch_size, dim, etc
For any Keras layer (Layer class), can someone explain how to understand the difference between input_shape, units, dim, etc.?
For example the doc says units specify the output shape of a layer.
...
11
votes
2
answers
7k
views
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:
<tf.Tensor 'dense_2/add:0' shape=(?, 2, 4) dtype=float32&...
60
votes
4
answers
56k
views
How do you create a custom activation function with Keras?
Sometimes the default standard activations like ReLU, tanh, softmax, ... and the advanced activations like LeakyReLU aren't enough. And it might also not be in keras-contrib.
How do you create your ...
57
votes
5
answers
29k
views
When does keras reset an LSTM state?
I read all sorts of texts about it, and none seem to answer this very basic question. It's always ambiguous:
In a stateful = False LSTM layer, does keras reset states after:
Each sequence; or
...
3
votes
1
answer
4k
views
Specify connections in NN (in keras)
I am using keras and tensorflow 1.4.
I want to explicitly specify which neurons are connected between two layers. Therefor I have a matrix A with ones in it, whenever neuron i in the first Layer is ...
58
votes
10
answers
82k
views
Reset weights in Keras layer
I'd like to reset (randomize) the weights of all layers in my Keras (deep learning) model. The reason is that I want to be able to train the model several times with different data splits without ...
55
votes
4
answers
132k
views
How do I get the weights of a layer in Keras?
I am using Windows 10, Python 3.5, and tensorflow 1.1.0. I have the following script:
import tensorflow as tf
import tensorflow.contrib.keras.api.keras.backend as K
from tensorflow.contrib.keras.api....
38
votes
2
answers
16k
views
TimeDistributed(Dense) vs Dense in Keras - Same number of parameters
I'm building a model that converts a string to another string using recurrent layers (GRUs). I have tried both a Dense and a TimeDistributed(Dense) layer as the last-but-one layer, but I don't ...
21
votes
6
answers
57k
views
Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution'
I got this error message when declaring the input layer in Keras.
ValueError: Negative dimension size caused by subtracting 3 from 1 for
'conv2d_2/convolution' (op: 'Conv2D') with input shapes: [?,...
84
votes
4
answers
116k
views
How to add and remove new layers in keras after loading weights?
I am trying to do a transfer learning; for that purpose I want to remove the last two layers of the neural network and add another two layers. This is an example code which also output the same error.
...
73
votes
9
answers
171k
views
Error when checking model input: expected convolution2d_input_1 to have 4 dimensions, but got array with shape (32, 32, 3)
I want to train a deep network starting with the following layer:
model = Sequential()
model.add(Conv2D(32, 3, 3, input_shape=(32, 32, 3)))
using
history = model.fit_generator(get_training_data(),
...
62
votes
10
answers
149k
views
Tensorflow Allocation Memory: Allocation of 38535168 exceeds 10% of system memory
Using ResNet50 pre-trained Weights I am trying to build a classifier. The code base is fully implemented in Keras high-level Tensorflow API. The complete code is posted in the below GitHub Link.
...
100
votes
4
answers
86k
views
How to stack multiple lstm in keras?
I am using deep learning library keras and trying to stack multiple LSTM with no luck.
Below is my code
model = Sequential()
model.add(LSTM(100,input_shape =(time_steps,vector_size)))
model.add(LSTM(...
60
votes
20
answers
136k
views
How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"?
I am trying to run some code to create an LSTM model but i get an error:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
My code is as follows:
from keras.models import ...
51
votes
5
answers
58k
views
what is the difference between Flatten() and GlobalAveragePooling2D() in keras
I want to pass the output of ConvLSTM and Conv2D to a Dense Layer in Keras, what is the difference between using global average pooling and flatten
Both is working in my case.
model.add(ConvLSTM2D(...