keras-layer

How to check the weights after every epoc in Keras model

霸气de小男生 提交于 2019-12-03 11:28:54
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_test)) Thanks in advance. What you are looking for is a CallBack function. A callback is a Keras

Why does a binary Keras CNN always predict 1?

巧了我就是萌 提交于 2019-12-03 07:25:39
I want to build a binary classifier using a Keras CNN. I have about 6000 rows of input data which looks like this: >> print(X_train[0]) [[[-1.06405307 -1.06685851 -1.05989663 -1.06273152] [-1.06295958 -1.06655996 -1.05969803 -1.06382503] [-1.06415248 -1.06735609 -1.05999593 -1.06302975] [-1.06295958 -1.06755513 -1.05949944 -1.06362621] [-1.06355603 -1.06636092 -1.05959873 -1.06173742] [-1.0619655 -1.06655996 -1.06039312 -1.06412326] [-1.06415248 -1.06725658 -1.05940014 -1.06322857] [-1.06345662 -1.06377347 -1.05890365 -1.06034568] [-1.06027557 -1.06019084 -1.05592469 -1.05537518] [-1.05550398

Keras 2.x - Get weights of layer

∥☆過路亽.° 提交于 2019-12-03 02:36:48
I am using Windows 10, Python 3.5, and tensorflow 1.1.0. I have the following script: import tensorflow as tf import tensorflow.contrib.keras.api.keras.backend as K from tensorflow.contrib.keras.api.keras.layers import Dense tf.reset_default_graph() init = tf.global_variables_initializer() sess = tf.Session() K.set_session(sess) # Keras will use this sesssion to initialize all variables input_x = tf.placeholder(tf.float32, [None, 10], name='input_x') dense1 = Dense(10, activation='relu')(input_x) sess.run(init) dense1.get_weights() I get the error: AttributeError: 'Tensor' object has no

Is there any way to get variable importance with Keras?

喜你入骨 提交于 2019-12-02 19:35:13
I am looking for a proper or best way to get variable importance in a Neural Network created with Keras. The way I currently do it is I just take the weights (not the biases) of the variables in the first layer with the assumption that more important variables will have higher weights in the first layer. Is there another/better way of doing it? Since everything will be mixed up along the network, the first layer alone can't tell you about the importante of each var. The following layers can also increase or decrease their importance, and even make one var affect the importance of another var.

How to have parallel convolutional layers in keras?

自古美人都是妖i 提交于 2019-12-02 18:23:47
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.add(Activation('relu')) model.add(MaxPooling2D(pool_size=pool_size)) model.add(Dropout(0.25)) model.add

How to add and remove new layers in keras after loading weights?

帅比萌擦擦* 提交于 2019-12-02 15:31:29
I am trying to do a transfer learning; for that purpose I want to remove the last two layers of the neural network and add another two layers. This is an example code which also output the same error. from keras.models import Sequential from keras.layers import Input,Flatten from keras.layers.convolutional import Convolution2D, MaxPooling2D from keras.layers.core import Dropout, Activation from keras.layers.pooling import GlobalAveragePooling2D from keras.models import Model in_img = Input(shape=(3, 32, 32)) x = Convolution2D(12, 3, 3, subsample=(2, 2), border_mode='valid', name='conv1')(in

how to know which node is dropped after using keras dropout layer

我与影子孤独终老i 提交于 2019-12-02 07:24:21
From nick blog it is clear that in dropout layer of CNN model we drop some nodes on the basis of bernoulli. But how to verify it, i.e. how to check which node is not selected. In DropConnect we leave some weights so I think with the help of model.get_weights() we can verify, but how in the case of dropout layer. model = Sequential() model.add(Conv2D(2, kernel_size=(3, 3), activation='relu', input_shape=input_shape)) model.add(Conv2D(4, (3, 3), activation='relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(8, activation='relu')) model

Error when checking target: expected time_distributed_5 to have 3 dimensions, but got array with shape (14724, 1)

你离开我真会死。 提交于 2019-12-02 06:12:05
问题 Trying to build a single output regression model, but there seems to be problem in the last layer inputs = Input(shape=(48, 1)) lstm = CuDNNLSTM(256,return_sequences=True)(inputs) lstm = Dropout(dropouts[0])(lstm) #aux_input auxiliary_inputs = Input(shape=(48, 7)) auxiliary_outputs = TimeDistributed(Dense(4))(auxiliary_inputs) auxiliary_outputs = TimeDistributed(Dense(7))(auxiliary_outputs) #concatenate output = keras.layers.concatenate([lstm, auxiliary_outputs]) output = TimeDistributed

AttributeError: 'NoneType' object has no attribute '_inbound_nodes' in Keras

ⅰ亾dé卋堺 提交于 2019-12-02 03:50:42
I want to define my own Lstm model as follows: from keras import backend as K from keras.callbacks import ModelCheckpoint from keras.layers.core import Dense, Activation, Flatten, Dropout from keras.layers import Input,Concatenate, Average, Maximum from keras.layers.normalization import BatchNormalization from keras.layers import LSTM, Bidirectional from keras.models import Model from keras.optimizers import Adam class LSTMModel(object): def __init__(self, config): self.num_batch = config['num_batch'] self.maxlen = config['maxlen'] self.embedding_dims = config['embedding_dims'] self.lstm_dims

Error when checking target: expected time_distributed_5 to have 3 dimensions, but got array with shape (14724, 1)

荒凉一梦 提交于 2019-12-01 22:46:14
Trying to build a single output regression model, but there seems to be problem in the last layer inputs = Input(shape=(48, 1)) lstm = CuDNNLSTM(256,return_sequences=True)(inputs) lstm = Dropout(dropouts[0])(lstm) #aux_input auxiliary_inputs = Input(shape=(48, 7)) auxiliary_outputs = TimeDistributed(Dense(4))(auxiliary_inputs) auxiliary_outputs = TimeDistributed(Dense(7))(auxiliary_outputs) #concatenate output = keras.layers.concatenate([lstm, auxiliary_outputs]) output = TimeDistributed(Dense(64, activation='linear'))(output) output = TimeDistributed(Dense(64, activation='linear'))(output)