Questions tagged [keras-layer]

1512 questions
11
votes
1 answer

Custom connections between layers Keras

I would like to manually define connections in neural network between layers using keras with Python. By default connections are beween all pairs of neurons. I need to make connections as in picture below. How can I be done in Keras?
holocen
  • 227
  • 1
  • 3
  • 10
11
votes
2 answers

LSTM Model in Keras with Auxiliary Inputs

I have a dataset with 2 columns - Each column contains a set of documents. I have to match the document in Col A with documents provided in Col B. This is a supervised classification problem. So my training data contains a label column indicating…
Dataminer
  • 1,499
  • 3
  • 16
  • 21
11
votes
3 answers

How to implement a matrix multiplication in Keras?

I just want to implement a function that given a matrix X returns the covariance matrix of X (X^T*X), which is just a simple matrix multiplication. In Tensorflow it's gonna be easy: tf.matmul(X, tf.transpose(X)) But I didn't expect that it's a…
Rui Meng
  • 113
  • 1
  • 1
  • 4
11
votes
2 answers

Default activation function in Keras

Does anyone know the default activation function used in the recurrent layers in Keras? https://keras.io/layers/recurrent/ It says the default activation function is linear. But what about the default recurrent activation function. Nothing is…
11
votes
1 answer

How to use keras ImageDataGenerator with a Siamese or Tripple networks

I'm trying to build up both a Siamese neural network and triple neural network on a custom large dataset Keras has ImageDataGenerator which makes the generation of input data to a regular neural network very easy. I'm interesting to use…
oak
  • 2,898
  • 2
  • 32
  • 65
10
votes
1 answer

Cannot import name 'Merge' from 'keras.layers'

I have try run a code but I find a problem with merge layers of Keras. I'm using python 3 and keras 2.2.4 This is de code part of code import numpy as np import pandas as pd from keras.models import Sequential from keras.layers import LSTM,…
JSouza
  • 115
  • 1
  • 1
  • 7
10
votes
1 answer

What does the "[0][0]" of the layers connected to in keras model.summary mean?

As is depicted in the following table, what does the [0][0] of the input_1[0][0] mean? __________________________________________________ Layer (type) Output Shape Param # Connected to …
Wiles Dai
  • 123
  • 1
  • 5
10
votes
1 answer

Copying weights of a specific layer - keras

According to this the following copies weights from one model to another: target_model.set_weights(model.get_weights()) What about copying the weights of a specific layer, would this…
10
votes
1 answer

ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv1d_1/convolution/Conv2D

Binary classification problem: I want to have One input layer(optional), One Conv1D layer then output layer of 1 neuron predicting either 1 or 0. Here is my model: x_train = np.expand_dims(x_train,axis=1) x_valid =…
10
votes
1 answer

expected input to have 4 dimensions, but got array with shape

I have this error Error when checking input: expected input_13 to have 4 dimensions, but got array with shape (7, 100, 100) For the following code how should I reshape array to fit with 4-dimensions, I searched for it but didn't understand the…
10
votes
1 answer

How to implement custom layer with multiple input in Keras

I need to implement a custom layer like this: class MaskedDenseLayer(Layer): def __init__(self, output_dim, activation, **kwargs): self.output_dim = output_dim super(MaskedDenseLayer, self).__init__(**kwargs) …
muradin
  • 1,249
  • 2
  • 14
  • 34
10
votes
1 answer

How to use lambda layer in keras?

I want to define lambda layer to combine features with cross product, then merge those models,just like the fig. ,What should I do? Test model_1, get 128 dimensions form dense, use pywt get two 64 dimensions feature(cA,cD), then return cA*cD //of…
Ting Li
  • 133
  • 1
  • 1
  • 7
10
votes
1 answer

Adding a preprocessing layer to keras model and setting tensor values

How would one best add a preprocessing layer (e.g., subtract mean and divide by std) to a keras (v2.0.5) model such that the model becomes fully self contained for deployment (possibly in a C++ environment). I tried: def getmodel(): model…
dgorissen
  • 6,207
  • 3
  • 43
  • 52
10
votes
1 answer

Bidirectional LSTM with Batch Normalization in Keras

I was wondering how to implement biLSTM with Batch Normalization (BN) in Keras. I know that BN layer should be between linearity and nonlinearity, i.e., activation. This is easy to implement with CNN or Dense layers. But, how to do this with…
abolfazl
  • 203
  • 1
  • 2
  • 5
9
votes
2 answers

Is it still necessary to implement `compute_output_shape()` when defining a custom tf.keras Layer?

I have implemented a custom Layer in tf.keras, using TensorFlow 2.1.0. In the past, when using the stand-alone Keras, it was important to define the compute_output_shape(input_shape) method in any custom layer so that the computational graph could…
Daniele Grattarola
  • 1,517
  • 17
  • 25