keras-layer

Can't add random noise to weights inside a Keras Layer

Can't add random noise to weights inside a Keras Layer Question: I am trying to add a random noise during forward pass to a convolutional layer in Keras. I wrote a wrapper class where it would add noise to the weights before computing convolution. Any addition or modifications to self.weights has no effect to the …

Total answers: 1

AttributeError: 'Sequential' object has no attribute 'model'

AttributeError: 'Sequential' object has no attribute 'model' Question: from tensorflow.keras.layers import Dense, Activation from tensorflow.keras.models import Sequential, load_model from tensorflow.keras.optimizers import Adam def build_dqn(lr, n_actions, input_dims, fc1_dims, fc2_dims): model = Sequential([ Dense(fc1_dims, input_shape=(input_dims,)), Activation(‘relu’), Dense(fc2_dims), Activation(‘relu’), Dense(n_actions)]) model.compile(optimizer=Adam(lr=lr), loss=’mse’) return model I am trying to understand Double Deep Q-Learning. There is a pretty good lecture …

Total answers: 1

How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"?

How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"? Question: 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 Sequential model = Sequential() model.add(Dense(32, input_dim=784)) model.add(Activation(‘relu’)) model.add(LSTM(17)) model.add(Dense(1, activation=’sigmoid’)) model.compile(loss=’binary_crossentropy’, optimizer=’adam’, …

Total answers: 19

Tensorflow Allocation Memory: Allocation of 38535168 exceeds 10% of system memory

Tensorflow Allocation Memory: Allocation of 38535168 exceeds 10% of system memory Question: 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. Source Code: Classification Using RestNet50 Architecture The file size of the …

Total answers: 10

what is the difference between Flatten() and GlobalAveragePooling2D() in keras

what is the difference between Flatten() and GlobalAveragePooling2D() in keras Question: 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(filters=256,kernel_size=(3,3))) model.add(Flatten()) # or model.add(GlobalAveragePooling2D()) model.add(Dense(256,activation=’relu’)) Asked By: user239457 || Source …

Total answers: 5

Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution'

Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution' Question: 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: [?,1,28,28], [3,3,28,32]. My code is like this model.add(Convolution2D(32, 3, 3, activation=’relu’, input_shape=(1,28,28))) Sample application: …

Total answers: 6

How do you create a custom activation function with Keras?

How do you create a custom activation function with Keras? Question: 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 own activation function? Asked By: Martin Thoma || Source Answers: Credits to this …

Total answers: 4

How do I get the weights of a layer in Keras?

How do I get the weights of a layer in Keras? Question: 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.keras.layers import Dense tf.reset_default_graph() init = tf.global_variables_initializer() sess = tf.Session() K.set_session(sess) # Keras will use this sesssion to initialize …

Total answers: 4

Resizing an input image in a Keras Lambda layer

Resizing an input image in a Keras Lambda layer Question: I would like my keras model to resize the input image using OpenCV or similar. I have seen the use of ImageGenerator, but I would prefer to write my own generator and simply resize the image in the first layer with keras.layers.core.Lambda. How would I …

Total answers: 1