# Questions tagged [keras-layer]

The keras-layer tag has no usage guidance.

851 questions

**0**

votes

**0**answers

17 views

### Concatenate input_layers in Keras raises AttributeError (Functional API) in R

I want to define a model in Keras, which has multiple inputs. Those inputs are similar in nature and should use the same layers in forward- and backward passes through the network.
If I define a ...

**2**

votes

**0**answers

16 views

### Custom RNN Layer with previous input and output time steps as Inputs

How can I extend the SimpleRNN or create a custom layer that could use not just the previous output y[n-1] but also the previous output y[n-2] and the previous inputs x[n-1], x[n-2]?
def call(self, ...

**1**

vote

**1**answer

20 views

### How to freeze specific layers of a model inside a model?

My keras model is made up of multiple models. Each "sub-model" has multiple layers. How do I call out the layers in the "sub-model" and set trainability / freeze specific layers?

**0**

votes

**1**answer

28 views

### keras pre-trained ResNet50 target shape

I am trying to use ResNet50 Pretrained network for segmentation problem.
I remove the last layer and add my desired layer. But when I try to fit, I get the following error:
ValueError: Error when ...

**1**

vote

**0**answers

23 views

### Mixing numerical and categorical data into keras sequential model with Dense layers

I have a training set in a Pandas dataframe, and I pass this data frame into model.fit() with df.values. Here is some information about the df:
df.values.shape
# (981, 5)
df.values[0]
# array([163, ...

**0**

votes

**0**answers

51 views

### 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:
...

**1**

vote

**1**answer

21 views

### What is the difference between dropout layer and dropout parameter in any keras layer

What is the difference between dropout layer and dropout parameter in any keras layer ,both are works for same purpose or different.
like :model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2))
...

**0**

votes

**0**answers

9 views

### reuse pre-trained embedding model in a new model only to evaluate - keras

I am looking for a way to reuse a trained embedding function in a new model, but only to evaluate.
For instance,
def embedding(x):
return Dense(2000)(x)
input = Input((4,200))
embedded = []
...

**-1**

votes

**0**answers

18 views

### No such file or directory: train-scene classification'/train

I am doing image classification in google labs, I have files like this.
ls/content/'train-scene classification'/
test.csv train/ train.csv
I trying to improve my accuracy, so I have applied ...

**0**

votes

**0**answers

10 views

### Keras Conv1D on DNA sequence

I would like to apply a 1D convolution on fixed size DNA sequence using keras.
Dna sequence is 45 bases long. Each sequence has been one-hot encoded. There is one filter with kernel size = 3. See ...

**0**

votes

**0**answers

51 views

### What is the meaning of ValueError in Keras? - 'Tensor conversion requested dtype complex64 for Tensor with dtype float32'

I have the following part of code -
...
model.add(Generic_act_func())
print('layer 1 output')
print(model.layers[1].output) #Here layers[1] is Generic_act_func() layer specified above
model.add(...

**-1**

votes

**2**answers

68 views

+100

### Custom pooling layer - minmax pooling - Keras - Tensorflow

I want to define my custom pooling layer, instead of returning the max values like the MaxPooling layer, it would output the k maximum values and the k minimum values.
I am using Tensorflow as the ...

**1**

vote

**2**answers

21 views

### Stacking functional models with python functions induce graph disconnection in Keras

I want to connect the model_1:
x_a = Input((5,))
hidden_a = Dense(2)(x_a)
hidden_b = Dense(2)(x_a)
model_1 = Model(x_a, [hidden_a, hidden_b])
and model_2:
x_b = Input((2,))
output = Dense(1)(x_b)
...

**0**

votes

**0**answers

31 views

### Keras Error: Variable does not exist, or was not created with tf.get_variable()

import tensorflow.keras as ks
def scope_error_test():
input_holder = tf.placeholder(dtype=tf.float32,
shape=(None, 368, 368, 3),
...

**1**

vote

**1**answer

23 views

### Error when checking target: expected concatenate_1 to have shape (1,) but got array with shape (851,)

I have some dimentional issue with a keras concatenation. It seems that the output array of the model (None, 851) is different from the dimention requiered in the error message. Here what I get:
...

**0**

votes

**0**answers

17 views

### tf.Keras - resetting the sequential input shape into custom layer

I've build a custom layer that I would like to train my data over 6 layers. The first input into my layer works just fine, but the input to the second layer doesn't. This is because of the _features = ...

**0**

votes

**1**answer

23 views

### Error when checking target: expected conv2d_29 to have 4 dimensions, but got array with shape (1255, 12)

I would like to train a deep learning model, where input image shape is (224,224,3) . And I would like to feed them into a u-net model.
After training I get the error : Error when checking target: ...

**0**

votes

**2**answers

37 views

### Keras/Tensorflow Input to RNN layers

I'm trying to build a RNN in Keras. I dont quite understand the required input format. I can build dense networks no problem, but I think that the RNN layers expect input dimension x batch x time step?...

**0**

votes

**1**answer

16 views

### Need of specifying the input shape in Keras

I am seeking help from put the right form of input_shape,
Let's say if I have the code like:
G = ImageGenerator(batch_size,args,****kwargs)
where G is a custom-made data_generator which specify ...

**1**

vote

**1**answer

50 views

### Keras (Tensorflow) Reshape Layer input error

I have a reshape input error and i don't know why.
The requested shape is 1058400, what is (1, 21168) multiplied with the batch size of 50.
What I do not understand is the apparent input size of ...

**1**

vote

**0**answers

23 views

### reading a pickle, IndexError: only integers, slices (`:`), ellipsis (`…`), numpy.newaxis (`None`) and integer or blean arrays are valid indices

train_features=load_photo_features('/home/feature/_0nX-El-ySo_83_93.pkl', train)
reading a pickle file , throws an error like "IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (...

**1**

vote

**0**answers

20 views

### how do I scatter a tensor with smaller shape to the bigger tensor?

I have an input tensor with shape (1,4,4,1), I want to concatenate this input with the output of conv layer with shape (1,28,28,1), but for this I want to put each value of the input to the new tensor ...

**-2**

votes

**2**answers

40 views

### How do you know which layers and how many layers to use? [closed]

I am new to machine learning and have spent some time learning python. I have started to learn TensorFlow and Keras for machine learning and I literally have no clue nor any understanding of the ...

**1**

vote

**0**answers

28 views

### preparing data with 6 time points in a sequential model: Keras for R

I have a question about pre-processing data in order to enter it into a sequential model in keras for R. I need to be sure that the input is correct for the model. The goal of the sequential model is ...

**1**

vote

**0**answers

27 views

### Jacobian of decoder in VAE

I am new to both ML and this forum, so please be kind.
What I would like to compute is the jacobian of the decoder part of the VAE w.r.t. the latent vectors. I have found the jacobian_batch function ...

**0**

votes

**1**answer

18 views

### How apply Gridsearch on autoencoder model?

I want to apply GridSearchCV on the autoencoder model. The code of the atuoencoder and GridSearchCV is added below please tell me how I change this code to run GridSearchCV successfully.
...

**0**

votes

**1**answer

41 views

### Keras 2D Dense Layer for Output

I am playing with a model which should take a 8x8 chess board as input, encoded as a 224x224 grey image, and then output a 64x13 one-hot-encoded logistic regression = probabilities of pieces on the ...

**0**

votes

**0**answers

22 views

### Unstacking a Keras tensor as a list

I have a keras tensor of size [61,80,?] with the '?' being for batch size in custom layer. When I am trying to unstack this tensor as a list of 2D tensor of size[61,80] using tf.unstack,I am getting ...

**-1**

votes

**0**answers

15 views

### how to add an inbuilt function in keras layer using lambda function

def dis(bin_image):
res=distance_transform_cdt(temp)
return res
out = Conv2D(1, (1, 1), activation='sigmoid') (c9)
outputs = lambda(dis)(c9)
this is what i am trying to do but it's saying ...

**0**

votes

**1**answer

19 views

### Dimensions for Keras RNN encoder-decoder architecture output

I've been unable to figure out the dimensions for an RNN encoder-decoder architecture. I understand how LSTMs work, but I am struggling to implement this one in Keras. After looking at the ...

**2**

votes

**1**answer

33 views

### Keras' convolution layer on images coming form 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 ...

**0**

votes

**0**answers

63 views

### how can I wrap function using lambda layer?

I want to do some processes on one of my layer in autoencoder and then send it to next layer but I can not use the predefined functions in Keras like add ,... and I think I should use lambda with ...

**0**

votes

**1**answer

69 views

### Tensorflow CuDNNLSTM keras error. TypeError: ('Keyword argument not understood:', 'time_major')

After I save a CuDNNLSTM model in tensorflow 1.13.1, I try to load it back immediately to use it.
I get the following error
TypeError: ('Keyword argument not understood:', 'time_major').
I looked ...

**0**

votes

**0**answers

14 views

### is it possible to send the output of layer in CNN to several layer that works in parallel and group convolution node?

I am a beginner in Keras and maybe my question will be simple, but I need your answers. suppose I have a CNN. usually, we send the output of layer as an input to the next layer. now, I want to know is ...

**0**

votes

**0**answers

10 views

### How do I add the value of cnn layers with special value during learning?

I have an autoencoder in keras and I want to do some processes on the encoder output layer before sending it to the next layer. the output of encoder part is a (1,28,28,1) tensor now I like to ...

**0**

votes

**0**answers

34 views

### How do I load a keras saved model with custom Optimizer

I have compiled and trained a keras model with a custom optimizer. I saved the model but when I try to load the model, it throws an error stating ValueError: Unknown optimizer: MyOptimizer. I tried to ...

**0**

votes

**0**answers

29 views

### Unable to stack keras 1D tensors to form 2D keras tensor

In my keras custom layer, i am trying to get the inner product of two same sized matrices and storing them in a 1D array. And then the 1D tensor have to be stacked as a 2D tensor. The code snippet is
...

**-1**

votes

**1**answer

36 views

### how can i implement Gaussian noise attack in keras?

I try to implement the code of https://arxiv.org/abs/1810.07248 that is about watermarking using deep learning, but I need to apply some attacks like Gaussian noise during learning. I used ...

**0**

votes

**1**answer

41 views

### Can I use a 3D input on a Keras Dense Layer?

As an exercise I need to use only dense layers to perform text classifications. I want to leverage words embeddings, the issue is that the dataset then is 3D (samples,words of sentence,embedding ...

**1**

vote

**0**answers

51 views

### Merging Models with Keras' Functional API

I am new to deep learning and am teaching myself some NLP concepts. I am trying to understand this by working on Quora's sentence similarity scoring model as explained in this excellent tutorial here. ...

**0**

votes

**1**answer

15 views

### what is the point of having a seperate build function in keras.layers

As per the following doc -->
https://keras.io/layers/writing-your-own-keras-layers/
It is used for initializing the weight matrix.. but my doubt is why not just do this initialization in the call ...

**0**

votes

**0**answers

9 views

### is it possible to select part of tensor for loss function?

I have an autoencoder with two inputs, image (28x28) and wtm(28x28). I add wtm with the output of the encoder part and send it to the decoder part. my main wtm was 4x4 but because I do not know how ...

**0**

votes

**0**answers

14 views

### How can I calculate BER in keras?

I have an autoencoder and it has two outputs and I want to calculate the BER between input and output, but I have some questions.
1. for calculating do we have any function in python for doing it? ...

**0**

votes

**1**answer

41 views

### nested model in lambda layer is not trainable

I have a model (i.e,spatial_model), which is nested inside the temporal model to construct a CNN-LSTM model. It seems that TimeDistributed layer does not accept two inputs while my spatial model needs ...

**0**

votes

**0**answers

21 views

### How to fuse an additional feature in training deep neural networks?

I am training a Convolutional Neural Network (CNN) to classify Spectrogram images (frequency over time). These Spectrograms were created from some signals on specific times, therefore the time of ...

**1**

vote

**1**answer

351 views

### TypeError: The added layer must be an instance of class Layer. Found: <keras.engine.input_layer.InputLayer object at 0x7fc6f1b92240>

I am trying to add vgg16 layers to Sequential model but getting the error mentioned in the Question Title
from keras.applications.vgg16 import VGG16
from tensorflow.contrib.keras.api.keras.models ...

**0**

votes

**1**answer

68 views

### What is the difference between SeparableConv2D and Conv2D layers?

I didn't find a clearly answer to this question online (sorry if it exists).
I would like to understand the differences between the two functions (SeparableConv2D and Conv2D), step by step with, for ...

**1**

vote

**0**answers

49 views

### How to implement low dimension embedding in TensorFlow

Assume I have an hign dimension vector v which dimension is (2000,1). And I want to get an embedding for v as following:
f=E*v where E is the embedding matrix with size (30, 2000); now the new ...

**0**

votes

**1**answer

83 views

### Keras Tokenization (fit on text)

When i am running this script-->
tokenizer.fit_on_texts(df['text'].values)
sequences = tokenizer.texts_to_sequences(df['text'].values)
word_index = tokenizer.word_index
print('Found %s unique tokens.'...

**0**

votes

**1**answer

61 views

### Keras: How to load a model having two outputs and a custom loss function?

I have trained a Keras (with Tensorflow backend) model which has two outputs with a custom loss function. I need help in loading the model from disk using the custom_objects argument.
When compiling ...