keras-layer

How to change input shape in Sequential model in Keras

自古美人都是妖i 提交于 2019-11-30 13:27:03
I have a sequential model that I built in Keras. I try to figure out how to change the shape of the input. In the following example model = Sequential() model.add(Dense(32, input_shape=(500,))) model.add(Dense(10, activation='softmax')) model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy']) let's say that I want to build a new model with different input shape, conceptual this should looks like this: model1 = model model1.layers[0] = Dense(32, input_shape=(250,)) is there a way to modify the model input shape? Think about what changing the input shape in that

Keras error “You must feed a value for placeholder tensor 'bidirectional_1/keras_learning_phase' with dtype bool”

落花浮王杯 提交于 2019-11-30 08:14:14
I get the following error for the code snippet below: You must feed a value for placeholder tensor 'bidirectional_1/keras_learning_phase' with dtype bool If I add the dropout layer model.add(Dropout(dropout)) , it works. Anyone knows why? The back-end is Tensorflow, Keras 2.0.1 def prep_model1(embedding_layer1, embedding_layer2, dropout=0.5): model0 = Sequential() model0.add(embedding_layer1) model0.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout))) model1 = Sequential() model1.add(embedding_layer2) model1.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout)

Error when checking model input: expected convolution2d_input_1 to have 4 dimensions, but got array with shape (32, 32, 3)

末鹿安然 提交于 2019-11-30 02:43:12
I want to train a deep network starting with the following layer: model = Sequential() model.add(Conv2D(32, 3, 3, input_shape=(32, 32, 3))) using history = model.fit_generator(get_training_data(), samples_per_epoch=1, nb_epoch=1,nb_val_samples=5, verbose=1,validation_data=get_validation_data() with the following generator: def get_training_data(self): while 1: for i in range(1,5): image = self.X_train[i] label = self.Y_train[i] yield (image,label) (validation generator looks similar). During training, I get the error: Error when checking model input: expected convolution2d_input_1 to have 4

How to convert predicted sequence back to text in keras?

天涯浪子 提交于 2019-11-30 01:13:46
问题 I have a sequence to sequence learning model which works fine and able to predict some outputs. The problem is I have no idea how to convert the output back to text sequence. This is my code. from keras.preprocessing.text import Tokenizer,base_filter from keras.preprocessing.sequence import pad_sequences from keras.models import Sequential from keras.layers import Dense txt1="""What makes this problem difficult is that the sequences can vary in length, be comprised of a very large vocabulary

How do you make TensorFlow + Keras fast with a TFRecord dataset?

走远了吗. 提交于 2019-11-29 20:29:45
What is an example of how to use a TensorFlow TFRecord with a Keras Model and tf.session.run() while keeping the dataset in tensors w/ queue runners? Below is a snippet that works but it needs the following improvements: Use the Model API specify an Input() Load a dataset from a TFRecord Run through a dataset in parallel (such as with a queuerunner) Here is the snippet, there are several TODO lines indicating what is needed: from keras.models import Model import tensorflow as tf from keras import backend as K from keras.layers import Dense, Input from keras.objectives import categorical

Dimension mismatch in Keras during model.fit

本秂侑毒 提交于 2019-11-29 12:43:10
I put together a VAE using Dense Neural Networks in Keras. During model.fit I get a dimension mismatch, but not sure what is throwing the code off. Below is what my code looks like from keras.layers import Lambda, Input, Dense from keras.models import Model from keras.datasets import mnist from keras.losses import mse, binary_crossentropy from keras.utils import plot_model from keras import backend as K import keras import numpy as np import matplotlib.pyplot as plt import argparse import os (x_train, y_train), (x_test, y_test) = mnist.load_data() image_size = x_train.shape[1] original_dim =

Keras error “You must feed a value for placeholder tensor 'bidirectional_1/keras_learning_phase' with dtype bool”

ε祈祈猫儿з 提交于 2019-11-29 11:55:33
问题 I get the following error for the code snippet below: You must feed a value for placeholder tensor 'bidirectional_1/keras_learning_phase' with dtype bool If I add the dropout layer model.add(Dropout(dropout)) , it works. Anyone knows why? The back-end is Tensorflow, Keras 2.0.1 def prep_model1(embedding_layer1, embedding_layer2, dropout=0.5): model0 = Sequential() model0.add(embedding_layer1) model0.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout))) model1 = Sequential()

How does the Flatten layer work in Keras?

自古美人都是妖i 提交于 2019-11-29 06:21:56
问题 I am using the TensorFlow backend. I am applying a convolution, max-pooling, flatten and a dense layer sequentially. The convolution requires a 3D input (height, width, color_channels_depth). After the convolution, this becomes (height, width, Number_of_filters). After applying max-pooling height and width changes. But, after applying the flatten layer, what happens exactly? For example, if the input before flatten is (24, 24, 32), then how it flattens it out? Is it sequential like (24 * 24)

How to get word vectors from Keras Embedding Layer

若如初见. 提交于 2019-11-29 03:58:07
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? 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 embedding vectors): # if you have access to the embedding layer explicitly embeddings = emebdding_layer.get

Keras verbose training progress bar writing a new line on each batch issue

情到浓时终转凉″ 提交于 2019-11-29 03:42:29
running a Dense feed-forward neural net in Keras. there are class_weights for two outputs, and sample_weights for a third output. fore some reason it prints the progress verbose display for each batch calculated, and not updating the print on the same line as its supposed to... Did this ever happens to you? How is it fixed? From the shell: 42336/747322 [====>.........................] - ETA: 79s - loss: 20.7154 - x1_loss: 9.5913 - x2_loss: 10.0536 - x3_loss: 1.0705 - x1_acc: 0.6930 - x2_acc: 0.4433 - x3_acc: 0.6821 143360/747322 [====>.........................] - ETA: 78s - loss: 20.7387 - x1