keras-layer

Dimensions not matching in keras LSTM model

大兔子大兔子 提交于 2019-12-10 18:04:48
问题 I want to use an LSTM neural Network with keras to forecast groups of time series and I am having troubles in making the model match what I want. The dimensions of my data are: input tensor: (data length, number of series to train, time steps to look back) output tensor: (data length, number of series to forecast, time steps to look ahead) Note: I want to keep the dimensions exactly like that, no transposition. A dummy data code that reproduces the problem is: import numpy as np from keras

TypeError when trying to create a BLSTM network in Keras

早过忘川 提交于 2019-12-10 16:44:49
问题 I'm a bit new to Keras and deep learning. I'm currently trying to replicate this paper but when I'm compiling the second model (with the LSTMs) I get the following error: "TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'" The description of the model is this: Input (length T is appliance specific window size) Parallel 1D convolution with filter size 3, 5, and 7 respectively, stride=1 , number of filters=32 , activation type=linear , border mode=same Merge layer which

How to implement a matrix multiplication in Keras?

旧时模样 提交于 2019-12-10 13:44:22
问题 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 nightmare with Keras. The APIs in Keras like multiply and dot don't fit my request. I also tried different ways (Lambda layer and mixed with TF operations) but still failed, occurred lots of errors. Hope someone may help. Thanks. 回答1: Actually you do

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

耗尽温柔 提交于 2019-12-10 11:32:43
问题 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

adding data to decoder in autoencoder during learning

谁说胖子不能爱 提交于 2019-12-10 10:06:20
问题 I want to implement an autoencoder using Keras and this structure is a large network that some operations is done on the output of autoencoder and then we should consider two loss I attached an image that shows my proposed structure. the link is below. autoencoder structure w has the same size as the input image and in this autoencoder, I do not use max pooling so the output of each phase has the same size as the input image. I want to send w and latent space representation to decoder part

Average weights in keras models

萝らか妹 提交于 2019-12-10 04:47:33
问题 How to average weights in Keras models, when I train few models with the same architecture with different initialisations? Now my code looks something like this? datagen = ImageDataGenerator(rotation_range=15, width_shift_range=2.0/28, height_shift_range=2.0/28 ) epochs = 40 lr = (1.234e-3) optimizer = Adam(lr=lr) main_input = Input(shape= (28,28,1), name='main_input') sub_models = [] for i in range(5): x = Conv2D(32, kernel_size=(3,3), strides=1)(main_input) x = BatchNormalization()(x) x =

How to merge keras sequential models with same input?

拥有回忆 提交于 2019-12-10 04:06:34
问题 I am trying to create my first ensemble models in keras. I have 3 input values and a single output value in my dataset. from keras.optimizers import SGD,Adam from keras.layers import Dense,Merge from keras.models import Sequential model1 = Sequential() model1.add(Dense(3, input_dim=3, activation='relu')) model1.add(Dense(2, activation='relu')) model1.add(Dense(2, activation='tanh')) model1.compile(loss='mse', optimizer='Adam', metrics=['accuracy']) model2 = Sequential() model2.add(Dense(3,

How to fix “AttributeError: module 'tensorflow' has no attribute 'get_default_graph'”?

雨燕双飞 提交于 2019-12-09 16:01:22
问题 I am trying to run some code to create an LSTM model but i get an error: AttributeError: module 'tensorflow' has no attribute 'get_default_graph' My code is as follows: from keras.models import Sequential model = Sequential() model.add(Dense(32, input_dim=784)) model.add(Activation('relu')) model.add(LSTM(17)) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) I have found someone else with a similar problem and they

How to check the weights after every epoc in Keras model

喜夏-厌秋 提交于 2019-12-09 08:56:06
问题 I am using the sequential model in Keras. I would like to check the weight of the model after every epoch. Could you please guide me on how to do so. model = Sequential() model.add(Embedding(max_features, 128, dropout=0.2)) model.add(LSTM(128, dropout_W=0.2, dropout_U=0.2)) model.add(Dense(1)) model.add(Activation('sigmoid')) model.compile(loss='binary_crossentropy',optimizer='adam',metrics['accuracy']) model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=5 validation_data=(X_test, y

Avoiding vanishing gradient in deep neural networks

安稳与你 提交于 2019-12-08 14:57:27
I'm taking a look at Keras to try to dive into deep learning. From what I know, stacking just a few dense layers effectively stops back propagation from working due to vanishing gradient problem. I found out that there is a pre-trained VGG-16 neural network you can download and build on top of it. This network has 16 layers so I guess, this is the territory where you hit the vanishing gradient problem. Suppose I wanted to train the network myself in Keras. How should I do it? Should I divide the layers into clusters and train them independently as autoecoders and than stack a classifier on top