keras-layer

How to have parallel convolutional layers in keras?

回眸只為那壹抹淺笑 提交于 2019-12-20 09:03:52
问题 I am a little new to neural networks and keras. I have some images with size 6*7 and the size of the filter is 15. I want to have several filters and train a convolutional layer separately on each and then combine them. I have looked at one example here: model = Sequential() model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1], border_mode='valid', input_shape=input_shape)) model.add(Activation('relu')) model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1])) model

math_ops.floor equivalent in Keras

筅森魡賤 提交于 2019-12-20 01:46:52
问题 I'm trying to implement a custom layer in Keras where I need to convert a tensor of floats [a, 1+a) to a binary tensor for masking. I can see that Tensorflow has a floor function that can do that, but Keras doesn't seem to have it in keras.backend . Any idea how I can do this? 回答1: As requested by OP, I will mention the answer I gave in my comment and elaborate more: Short answer: you won't encounter any major problems if you use tf.floor() . Long answer: Using Keras backend functions (i.e.

Keras reset layer numbers

你说的曾经没有我的故事 提交于 2019-12-18 17:27:22
问题 Keras assigns incrementing ID numbers to layers of the same type, e.g. max_pooling1d_7 , max_pooling1d_8 , max_pooling1d_9 ,etc. Each iteration of my code constructs a new model, starting with model = Sequential() and then adding layers via model.add() . Even though each cycle creates a new Sequential object, the layer ID numbers continue incrementing from the previous cycle. Since my process is long-running these ID numbers can grow very large. I am concerned that this could cause some

How to correctly get layer weights from Conv2D in keras?

筅森魡賤 提交于 2019-12-18 11:57:08
问题 I have Conv2D layer defines as: Conv2D(96, kernel_size=(5, 5), activation='relu', input_shape=(image_rows, image_cols, 1), kernel_initializer=initializers.glorot_normal(seed), bias_initializer=initializers.glorot_uniform(seed), padding='same', name='conv_1') This is the first layer in my network. Input dimensions are 64 by 160, image is 1 channel. I am trying to visualize weights from this convolutional layer but not sure how to get them. Here is how I am doing this now: 1.Call layer.get

How to stack multiple lstm in keras?

那年仲夏 提交于 2019-12-18 10:05:08
问题 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(100)) The above code returns error in the third line Exception: Input 0 is incompatible with layer lstm_28: expected ndim=3, found ndim=2 The input X is a tensor of shape (100,250,50). I am running keras on tensorflow backend 回答1: You need to add return_sequences=True to the first layer so that

Extract encoder and decoder from trained autoencoder

纵然是瞬间 提交于 2019-12-18 05:06:38
问题 I want to divide the autoencoder learning and applying into two parts following https://blog.keras.io/building-autoencoders-in-keras.html and using the fashion-mnist data for testing purposes: Load the images, do the fitting that may take some hours or days and use a callback to save the best autoencoder model. That process can be some weeks before the following part. Use this best model (manually selected by filename) and plot original image, the encoded representation made by the encoder of

How to get word vectors from Keras Embedding Layer

孤街醉人 提交于 2019-12-18 04:00:38
问题 I'm currently working with a Keras model which has a embedding layer as first layer. In order to visualize the relationships and similarity of words between each other I need a function that returns the mapping of words and vectors of every element in the vocabulary (e.g. 'love' - [0.21, 0.56, ..., 0.65, 0.10]). Is there any way to do it? 回答1: You can get the word embeddings by using the get_weights() method of the embedding layer (i.e. essentially the weights of an embedding layer are the

ImportError: cannot import name '_obtain_input_shape' from keras

自作多情 提交于 2019-12-18 03:54:50
问题 In Keras, I'm trying to import _obtain_input_shape as follows: from keras.applications.imagenet_utils import _obtain_input_shape However, I get the following error: ImportError: cannot import name '_obtain_input_shape' The reason I'm trying to import _obtain_input_shape is so that I can determine the input shape(so as to load VGG-Face as follows : I'm using it to determine the correct input shape of the input tensor as follow: input_shape = _obtain_input_shape(input_shape, default_size=224,

ImportError: cannot import name '_obtain_input_shape' from keras

送分小仙女□ 提交于 2019-12-18 03:54:26
问题 In Keras, I'm trying to import _obtain_input_shape as follows: from keras.applications.imagenet_utils import _obtain_input_shape However, I get the following error: ImportError: cannot import name '_obtain_input_shape' The reason I'm trying to import _obtain_input_shape is so that I can determine the input shape(so as to load VGG-Face as follows : I'm using it to determine the correct input shape of the input tensor as follow: input_shape = _obtain_input_shape(input_shape, default_size=224,

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

非 Y 不嫁゛ 提交于 2019-12-17 23:12:31
问题 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: https://github.com/IntellijSys/tensorflow/blob/master/Keras.ipynb 回答1: By default, Convolution2D (https://keras.io/layers/convolutional/) expects the input to