Questions tagged [keras-layer]

1512 questions
9
votes
4 answers

Keras give input to intermediate layer and get final output

My model is a simple fully connected network like this: inp=Input(shape=(10,)) d=Dense(64, activation='relu')(inp) d=Dense(128,activation='relu')(d) d=Dense(256,activation='relu')(d) #want to give input here,…
Asim
  • 1,430
  • 1
  • 22
  • 43
9
votes
2 answers

How to use different activation functions in one Keras layer?

I am working on Keras in Python and I have a neural network (see code below). Currently it works with only a ReLu activation. For experimental reasons I would like to have some neurons on ReLu and some on softmax (or any other activation function).…
Nicolas
  • 392
  • 5
  • 14
9
votes
1 answer

Difference Between Keras Input Layer and Tensorflow Placeholders

I was hoping someone could explain the difference (if any) between the Input Layer in Keras and Placeholders within Tensorflow? The more I investigate, the more the two appear similar, but I am not convinced 100% either way thus far. Here is what I…
joshf
  • 251
  • 1
  • 3
  • 6
9
votes
2 answers

Keras embedding layer masking. Why does input_dim need to be |vocabulary| + 2?

In the Keras docs for Embedding https://keras.io/layers/embeddings/, the explanation given for mask_zero is mask_zero: Whether or not the input value 0 is a special "padding" value that should be masked out. This is useful when using recurrent…
Nigel Ng
  • 543
  • 1
  • 7
  • 21
9
votes
2 answers

How to use OpenCV functions in Keras Lambda Layer?

I am trying to use a function that uses some OpenCV function on the image. But the data I am getting is a tensor and I am not able to convert it into an image. def image_func(img): img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV) …
kauDaOtha
  • 1,140
  • 1
  • 14
  • 23
9
votes
1 answer

Keras intermediate layers output

I'm trying to get the intermediate layers output when using functional API of Keras. I'm able to get the output when using the standard Sequential API, but not with the functional API. I'm working on this working toy example: from keras.models…
Miguel
  • 2,738
  • 3
  • 35
  • 51
8
votes
6 answers

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

I am doing some task related to image captioning and I have loaded the weights of inception model like this model = InceptionV3(weights='imagenet') But I am getting error like this: AttributeError: module 'tensorflow' has no attribute…
Ayush Kushwaha
  • 93
  • 1
  • 1
  • 9
8
votes
1 answer

How to model a shared layer in keras?

I want to train a model with a shared layer in the following form: x --> F(x) ==> G(F(x),F(y)) y --> F(y) x and y are two separate input layers and F is a shared layer. G is the last layer after concatenating F(x) and F(y). Is it…
Amirhessam
  • 154
  • 1
  • 11
8
votes
3 answers

How to merge keras sequential models with same input?

I am trying to create my first ensemble models in keras. I have 3 input values and a single output value in my dataset. from keras.optimizers import SGD,Adam from keras.layers import Dense,Merge from keras.models import Sequential model1 =…
Eka
  • 14,170
  • 38
  • 128
  • 212
8
votes
1 answer

Why does a binary Keras CNN always predict 1?

I want to build a binary classifier using a Keras CNN. I have about 6000 rows of input data which looks like this: >> print(X_train[0]) [[[-1.06405307 -1.06685851 -1.05989663 -1.06273152] [-1.06295958 -1.06655996 -1.05969803 -1.06382503] …
mllamazares
  • 7,876
  • 17
  • 61
  • 89
8
votes
1 answer

Behavior of Dropout layers in test / training phase

According to the Keras documentation dropout layers show different behaviors in training and test phase: Note that if your model has a different behavior in training and testing phase (e.g. if it uses Dropout, BatchNormalization, etc.), you …
null
  • 1,369
  • 2
  • 18
  • 38
7
votes
6 answers

Keras Dense layer Output Shape

I am unable to understand the logic behind getting the output shape of the first hidden layer. I have taken some arbitrary examples as follows; Example 1: model.add(Dense(units=4,activation='linear',input_shape=(784,))) …
Navdeep
  • 823
  • 1
  • 16
  • 35
7
votes
1 answer

Keras' convolution layer on images coming from circular/cyclic domain

The Need Hello, I am experimenting the usage of CNNs on images which come from a cylindric domain, so I am interested to apply the Convolution layer in a circular (or cyclic) way. I mean a convolution layer that instead of padding the image with…
lurix66
  • 502
  • 1
  • 5
  • 14
7
votes
1 answer

TypeError: __init__() got an unexpected keyword argument 'trainable'

I am trying to load a RNN model architecture trained in Keras using keras.models.model_from_json and I am getting the mentioned error with open('model_architecture.json', 'r') as f: model = model_from_json(f.read(),…
Biswadip Mandal
  • 534
  • 1
  • 4
  • 15
7
votes
1 answer

Keras dot/Dot layer behavior on 3D tensors

The Keras documentation for the dot/Dot layer states that: "Layer that computes a dot product between samples in two tensors. E.g. if applied to a list of two tensors a and b of shape (batch_size, n), the output will be a tensor of shape …
Kate A Baumli
  • 123
  • 1
  • 6