keras-layer

Multi-Output Multi-Class Keras Model

試著忘記壹切 提交于 2019-12-07 08:12:30
问题 For each input I have, I have a 49x2 matrix associated. Here's what 1 input-output couple looks like input : [Car1, Car2, Car3 ..., Car118] output : [[Label1 Label2] [Label1 Label2] ... [Label1 Label2]] Where both Label1 and Label2 are LabelEncode and they have respectively 1200 and 1300 different classes. Just to make sure this is what we call a multi-output multi-class problem? I tried to flatten the output but I feared the model wouldn't understand that all similar Label share the same

How to merge two LSTM layers in Keras

爱⌒轻易说出口 提交于 2019-12-07 06:13:36
问题 I’m working with Keras on a sentence similarity task (using the STS dataset) and am having problems merging the layers. The data consists of 1184 sentence pairs each scored between 0 and 5. Below are the shapes of my numpy arrays. I’ve padded each of the sentences to 50 words and run them through and embedding layer, using the glove embedding’s with 100 dimensions. When merging the two networks I'm getting an error.. Exception: Error when checking model input: the list of Numpy arrays that

Understanding output of Dense layer for higher dimension

拜拜、爱过 提交于 2019-12-07 05:07:30
I don't have problem in understanding output shape of a Dense layer followed by a Flatten layer. Output shape is in accordance of my understanding i.e (Batch size, unit). nn= keras.Sequential() nn.add(keras.layers.Conv2D(8,kernel_size=(2,2),input_shape=(4,5,1))) nn.add(keras.layers.Conv2D(1,kernel_size=(2,2))) nn.add(keras.layers.Flatten()) nn.add(keras.layers.Dense(5)) nn.add(keras.layers.Dense(1)) nn.summary() Output is: _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d

How to split a Keras model, with a non-sequential architecture like ResNet, into sub-models?

放肆的年华 提交于 2019-12-06 21:03:27
My model is a resnet-152 i wanna cutting it into two submodels and the problem is with the second one i can't figure out how to build a model from an intermediate layer to the output I tried this code from this response and it doesn't work for me here is my code: def getLayerIndexByName(model, layername): for idx, layer in enumerate(model.layers): if layer.name == layername: return idx idx = getLayerIndexByName(resnet, 'res3a_branch2a') input_shape = resnet.layers[idx].get_input_shape_at(0) # which is here in my case (None, 55, 55, 256) layer_input = Input(shape=input_shape[1:]) # as keras

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

安稳与你 提交于 2019-12-06 15:51:32
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.6, 83, 0.52, # array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

Adding new features to the output of Flatten() layer in Keras

↘锁芯ラ 提交于 2019-12-06 11:52:23
I am doing image classification. Firstly I am feeding my images to my CNN model in Keras. I want to add new features at the output of Flatten layer in keras and then feed it to the dense layer(s). How do I write a code for it? Basically I am using Convolution for images and then at the end I want to add other features like Age Sex etc. max_pool_final = MaxPooling2D(pool_size=(2,2))(conv_final) flat = Flatten()(max_pool_final) dense = Dense(128)(flat) Before feeding flat as an input to the dense layer, I want to add a few features to flat. How do I do this? Thanks for help! You just have to use

Keras TimeDistributed Conv1D Error

末鹿安然 提交于 2019-12-06 10:36:28
This is my code: cnn_input = Input(shape=(cnn_max_length,)) emb_output = Embedding(num_chars + 1, output_dim=32, input_length=cnn_max_length, trainable=True)(cnn_input) output = TimeDistributed(Convolution1D(filters=128, kernel_size=4, activation='relu'))(emb_output) I want to train a character-level CNN sequence labeler and I keep receiving this error: Traceback (most recent call last): File "word_lstm_char_cnn.py", line 24, in <module> output = kl.TimeDistributed(kl.Convolution1D(filters=128, kernel_size=4, activation='relu'))(emb_output) File "/home/user/anaconda3/envs/thesisenv/lib/python3

How to wrap a tensorflow object as Keras layer?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 08:18:35
I would like to implement Hierarchical Multiscale LSTM as a Keras layer. It was published here and implemented in tensorflow here . My understanding is that there's a way to wrap such a tensorflow object in Keras as a layer. I'm not sure how complicated it is but I think it's feasible. Can you help me how to do it? This is usually done by implementing a custom Layer . To be more specific, you should inherit from keras.engine.topology.layer and provide a custom implementation for the following methods (and place the TensorFlow code within them): build(input_shape) : this is where you will

ValueError: Tensor:(…) is not an element of this graph

删除回忆录丶 提交于 2019-12-06 05:57:45
I am using keras' pre-trained model and the error came up when trying to get predictions. I have the following code in flask server: from NeuralNetwork import * @app.route("/uploadMultipleImages", methods=["POST"]) def uploadMultipleImages(): uploaded_files = request.files.getlist("file[]") getPredictionfunction = preTrainedModel["VGG16"] for file in uploaded_files: path = os.path.join(STATIC_PATH, file.filename) result = getPredictionfunction(path) This is what I have in my NeuralNetwork.py file: vgg16 = VGG16(weights='imagenet', include_top=True) def getVGG16Prediction(img_path): model =

Implementing a tensorflow graph into a Keras model

冷暖自知 提交于 2019-12-06 04:06:52
I am trying to implement roughly the following architecture in Keras (preferably) or Tensorflow. ___________ _________ _________ ________ ______ | Conv | | Max | | Dense | | | | | Input0--> | Layer 1 | --> | Pool 1 | --> | Layer | -->| | | | |_________| |________| |________| | Sum | | Out | | Layer |-->|_____| Input1 ----------- Converted to trainable weights-->| | |_______| |_______| In short, it is pretty much a model with two inputs, merged into one output using an Add([input0, input1]) layer. The trick is that one of the inputs must be seen as a variable = trainable weight. Keras layer Add