keras-layer

No Inbound Nodes - Keras CNN Model

ⅰ亾dé卋堺 提交于 2020-06-28 05:28:08
问题 I had trained a CNN model in keras with the following structure model_11 = Sequential() #Convolutional Layers model_11.add(Reshape((55, 1))) model_11.add(Conv1D(50, kernel_size=5, strides=1, padding="same", activation = 'relu')) model_11.add(Conv1D(24, kernel_size=4, strides=5, padding="same", activation = 'relu')) model_11.add(Conv1D(23, kernel_size=2, strides=1, padding="same", activation = 'relu')) #Dense Layers model_11.add(Flatten()) model_11.add(Dense(units=30, activation='relu')) model

Keras embedding layer masking. Why does input_dim need to be |vocabulary| + 2?

不羁的心 提交于 2020-06-25 02:38:07
问题 In the Keras docs for Embedding https://keras.io/layers/embeddings/, the explanation given for mask_zero is mask_zero: Whether or not the input value 0 is a special "padding" value that should be masked out. This is useful when using recurrent layers which may take variable length input. If this is True then all subsequent layers in the model need to support masking or an exception will be raised. If mask_zero is set to True, as a consequence, index 0 cannot be used in the vocabulary (input

Cannot import keras.initializers

纵饮孤独 提交于 2020-06-18 11:58:05
问题 I have imported all necessary modules from keras into jupyter notebook from keras.preprocessing.text import Tokenizer from keras.preprocessing.sequence import pad_sequences from keras.models import Sequential from keras.layers import Embedding, Dense, Dropout, Reshape, Merge, BatchNormalization, TimeDistributed, Lambda, Activation, LSTM, Flatten, Convolution1D, GRU, MaxPooling1D from keras.regularizers import l2 from keras.callbacks import Callback, ModelCheckpoint, EarlyStopping from keras

Loading a model Raise ValueError Unknown loss function

时间秒杀一切 提交于 2020-06-01 06:50:05
问题 this is the code after i try to save and load my model: model.save('path_to_my_model.h5') del model model = tf.keras.models.load_model('path_to_my_model.h5', custom_objects={'Wraparound2D': Wraparound2D}) import tensorflow.keras.backend as K inp = model.input # input placeholder outputs = [layer.output for layer in model.layers] # all layer outputs functor = K.function(inp, outputs) # evaluation function layer_outs = functor([X_test, 1.]) # Plot activations of different neurons in different

Custom activation with parameter

落花浮王杯 提交于 2020-05-27 07:24:46
问题 I'm trying to create an activation function in Keras that can take in a parameter beta like so: from keras import backend as K from keras.utils.generic_utils import get_custom_objects from keras.layers import Activation class Swish(Activation): def __init__(self, activation, beta, **kwargs): super(Swish, self).__init__(activation, **kwargs) self.__name__ = 'swish' self.beta = beta def swish(x): return (K.sigmoid(beta*x) * x) get_custom_objects().update({'swish': Swish(swish, beta=1.)}) It

Custom activation with parameter

故事扮演 提交于 2020-05-27 07:23:15
问题 I'm trying to create an activation function in Keras that can take in a parameter beta like so: from keras import backend as K from keras.utils.generic_utils import get_custom_objects from keras.layers import Activation class Swish(Activation): def __init__(self, activation, beta, **kwargs): super(Swish, self).__init__(activation, **kwargs) self.__name__ = 'swish' self.beta = beta def swish(x): return (K.sigmoid(beta*x) * x) get_custom_objects().update({'swish': Swish(swish, beta=1.)}) It

TimeDistributed of a KerasLayer in Tensorflow 2.0

醉酒当歌 提交于 2020-05-15 19:22:05
问题 I'm trying to build a CNN + RNN using a pre-trained model from tensorflow-hub: base_model = hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/4', input_shape=(244, 244, 3) base_model.trainable = False model = Sequential() model.add(TimeDistributed(base_model, input_shape=(15, 244, 244, 3))) model.add(LSTM(512)) model.add(Dense(256, activation='relu')) model.add(Dense(3, activation='softmax')) adam = Adam(learning_rate=learning_rate) model.compile(loss='categorical

TimeDistributed of a KerasLayer in Tensorflow 2.0

こ雲淡風輕ζ 提交于 2020-05-15 19:21:08
问题 I'm trying to build a CNN + RNN using a pre-trained model from tensorflow-hub: base_model = hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/4', input_shape=(244, 244, 3) base_model.trainable = False model = Sequential() model.add(TimeDistributed(base_model, input_shape=(15, 244, 244, 3))) model.add(LSTM(512)) model.add(Dense(256, activation='relu')) model.add(Dense(3, activation='softmax')) adam = Adam(learning_rate=learning_rate) model.compile(loss='categorical

How do I load a keras saved model with custom Optimizer

拥有回忆 提交于 2020-05-14 18:24:09
问题 I have compiled and trained a keras model with a custom optimizer. I saved the model but when I try to load the model, it throws an error stating ValueError: Unknown optimizer: MyOptimizer . I tried to pass MyOptimizer as a custom object something like : models.load_model('myModel.h5', custom_objects={'optimizer':MyOptimizer}) and it still throws an error. How do I load the model a keras model with custom Objects? 回答1: I ran into the same problem :) I made it work by loading the model with

how to keep the values of tensors in each epoch in one layer and pass it to Next epoch in tensorflow

时光总嘲笑我的痴心妄想 提交于 2020-05-12 08:52:28
问题 I have a general question. I am developing a new layer to incorporate into an autoencoder. To be more specific, the layer is something like the KCompetitive class over here. What I want is that I need to save the output of this layer in a variable let's call it previous_mat_values , and then pass it to that same layer in the next epoch as well. To put it another way, I want to be able to save the output of this layer of epoch 1 in one variable, and then in epoch 2 , again use that same matrix