keras-layer

Why does the first LSTM in a Keras model have more params than the subsequent one?

假如想象 提交于 2019-12-11 15:14:58
问题 I was just looking at the Keras model details from a fairly straightforward sequential model where I have multiple LSTM layers, one after another. I was surprised to see that the first layer always has more params despite having the same definition as the subsequent LSTM layer. The model definition here shows it clearly: Layer (type) Output Shape Param # ================================================================= lstm_1 (LSTM) (None, 400, 5) 380 _________________________________________

Why do we need to include_top=False if we need to change the input_shape?

▼魔方 西西 提交于 2019-12-11 14:23:59
问题 As far as I know, the input tuple enters from the convolution blocks. So if we want to change the input_tuple shape, modifying convolutions would make sense. Why do we need to include_top=False and remove the fully connected layers at the end? On the other hand, if we have different number of classes,Keras has an option to change the softmax layer using no_of_classes I know that I am the one missing something here. Please help me Example: For Inception Resnet V2 input_shape: optional shape

Keras TimeDistributed layer with multiple inputs

久未见 提交于 2019-12-11 11:05:40
问题 I'm trying to make the following lines of code working: low_encoder_out = TimeDistributed( AutoregressiveDecoder(...) )([X_tf, embeddings]) Where AutoregressiveDecoder is a custom layer that takes two inputs. After a bit of googling, the problem seems to be that the TimeDistributed wrapper doesn't accept multiple inputs. There are solutions that proposes to merge the two inputs before feeding it to the layer, but since their shape is X_tf.shape: (?, 16, 16, 128, 5) embeddings.shape: (?, 16,

ValueError: Input 0 is incompatible with layer layer_1: expected ndim=3, found ndim=2

﹥>﹥吖頭↗ 提交于 2019-12-11 08:07:57
问题 I am trying to build text-summarizer using word Embeddings and encoder-decoder architecture. This is my first shot at Keras and I am not able to understand why layer_1 requires ndim=3 . I am not able to figure this out. Below is my code: vocab_size = 16828 n_embeddings = 200 def model_builder(embeds): model = keras.Sequential() model.add(Embedding(weights=[embeds], name="embedding_1", input_dim=vocab_size, output_dim=n_embeddings)) for i in range(3): lstm = LSTM(rnn_size, name="layer_%s" %(i)

Keras model - Unet Image Segmentation

橙三吉。 提交于 2019-12-11 07:28:12
问题 I am attempting to recreate a UNet using the Keras model API, I have collected images of cells, and the segmented version of it and I am attempting to train a model with it. In doing so I could upload a different cell and get the segmented version of the image as a prediction. https://github.com/JamilGafur/Unet from __future__ import print_function from matplotlib import pyplot as plt from keras import losses import os from keras.models import Model from keras.layers import Input, concatenate

Extending a Keras Pre-trained model to images with additional channels or bands

為{幸葍}努か 提交于 2019-12-11 06:46:36
问题 I was just hoping to clarify some information about a previous post that discusses how a Keras pre-trained model like VGG or InceptionV3 can be extended to different sized images. My problem is that I have some satellite images that come in 8-bands. So an image might be 650x650x8 instead of the usual RBG 3 band images. I wanted to know if I can use a Keras pre-trained model on images with 8 bands instead of 3 bands. Now there is an original post and deals with something similar to this. The

Keras - Modifying lambda layer after `compile()`

人盡茶涼 提交于 2019-12-11 04:26:32
问题 In Keras, how do I change a lambda layer after the model is compiled? More specifically, let's say I want a lambda layer that computes y=a*x+b with a and b being changed every epoch. import keras from keras.layers import Input, Lambda, Dense import numpy as np np.random.seed(seed=42) a = 1 b = 2 def f(x, a, b): return a * x + b inputs = keras.layers.Input(shape=(3,)) lam = Lambda(f, arguments={"a": a, "b": b})(inputs) out = keras.layers.Dense(5)(lam) model = keras.models.Model(inputs, out)

ValueError: Input 0 is incompatible with layer dense_6 in keras

人盡茶涼 提交于 2019-12-11 02:32:30
问题 I am trying to build a deep autoencoder by following this link, but I got this error: ValueError: Input 0 is incompatible with layer dense_6: expected axis -1 of input shape to have value 128 but got shape (None, 32) The code: input_img = Input(shape=(784,)) encoded = Dense(128, activation='relu')(input_img) encoded = Dense(64, activation='relu')(encoded) encoded = Dense(32, activation='relu')(encoded) decoded = Dense(64, activation='relu')(encoded) decoded = Dense(128, activation='relu')

How to correctly use an intermediate layer of a vgg model

泄露秘密 提交于 2019-12-10 22:42:18
问题 What I did is: from keras.applications.vgg16 import VGG16 from keras.layers import * from keras.models import Model import numpy as np vgg_model = VGG16(weights='imagenet', include_top=False, input_shape = (224,224, 3)) block5_conv3 = vgg_model.get_layer("block5_conv3").output input_image = Input(shape=(224,224, 3), name='image_input') vgg_out = vgg_model(input_image) f0 = Flatten()(block5_conv3) test_model = Model(inputs=input_image, outputs=f0) print(test_model.summary()) But I got the

Keras Custom Layer - AttributeError: 'Tensor' object has no attribute '_keras_history'

十年热恋 提交于 2019-12-10 20:28:39
问题 So big picture, I'm trying to make a keras w2v auto-encoder. I tried to follow the CustomVariationalLayer class from this official example. My class is this: class custom_ae_layer(Layer): """custom keras layer to handle looking up wv inputs example from https://github.com/fchollet/keras/blob/master/examples/variational_autoencoder.py """ def __init__(self, **kwargs): self.is_placeholder = True super(custom_ae_layer, self).__init__(**kwargs) def ae_loss(self, reconstruction,emb_lookup): loss =