keras-layer

Keras backend mean function: “ 'float' object has no attribute 'dtype' ”?

北城以北 提交于 2019-12-13 02:49:55
问题 I am trying to introduce a new kernel regularize for a network using Keras. But, it gives me the error: 'float' object has no attribute 'dtype' How can I fix it? I found the code here: KL divergence in keras(tensorflow backend) Here is my code: from keras import backend as K kullback_leibler_divergence = keras.losses.kullback_leibler_divergence def kl_divergence_regularizer(inputs): means = K.mean((inputs)) return 0.5 *(0.01 * (kullback_leibler_divergence(0.05, means) + kullback_leibler

Keras ValueError: Unknown layer:name, when trying to load model to another platform

此生再无相见时 提交于 2019-12-13 01:16:55
问题 I have trained a convolutional neural network using Keras 2.2.4 on Nvidia Quadro board. I have saved the trained model in tow separate files: one file (model.json) that describes the architecture and another file (model.h5) that has all the weights. I want to load the saved model on the Nvidia Jetson TX2 board that runs Keras 2.2.2 and I'm trying to do it as follows: # load json and create model json_file = open(prefix+'final_model.json', 'r') loaded_model_json = json_file.read() json_file

In Keras, how to use Reshape layer with None dimension?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 01:16:19
问题 In my model, a layer has a shape of [None, None, 40, 64] . I want to reshape this into [None, None, 40*64] . However, if I simply do the following: reshaped_layer = Reshape((None, None, 40*64))(my_layer) It throws an error complaining that None values not supported . (Just to be clear, this is not tf.keras , this is just Keras). 回答1: First of all, the argument you pass to Reshape layer is the desired shape of one sample in the batch and not the whole batch of samples. So since each of the

Conditional Batch Normalization in Keras

家住魔仙堡 提交于 2019-12-13 00:08:00
问题 I'm trying to implement Conditional Batch Normalization in Keras. I assumed that I will have to create a custom layer, hence, I extended from the Normalization source code from Keras team. The idea: I will have 3 conditions, so, I will need 3 different beta and gamma parameters to be initialized. Then, I just incorporated conditional statements where its needed. Note that my condition changes after every iteration randomly and trying to set the condition based on 3 global Keras variables, c1,

Multi-input and multi-output models based on keras2.0

白昼怎懂夜的黑 提交于 2019-12-12 17:02:28
问题 I'm searching for a long time on the net. But I don't found nothing. Please help me or try to give me some ideas about how to achieve this. I have built the 3-inputs and 2-outputs model which is shown below. the code block is from def build_srgan_model in class SRGANNetwork: ip = Input(shape=(self.img_width, self.img_height,3), name='x_generator') ip_gan = Input(shape=(large_width, large_height,3), name='x_discriminator') ip_vgg = Input(shape=(large_width, large_height,3), name='x_vgg') sr

Keras - Merging layers - Keras 2.0

偶尔善良 提交于 2019-12-12 15:38:21
问题 I am trying to merge two networks. I can accomplish this by doing the following: merged = Merge([CNN_Model, RNN_Model], mode='concat') But I get a warning: merged = Merge([CNN_Model, RNN_Model], mode='concat') __main__:1: UserWarning: The `Merge` layer is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc. So I tried this: merged = Concatenate([CNN_Model, RNN_Model]) model = Sequential() model.add(merged) and got this

Selecting number of strides and filters in CNN (Keras)

大兔子大兔子 提交于 2019-12-12 04:55:23
问题 I am using keras to build a cnn model for signal classification. What is the best way in keras for hyper parameter tuning and selection for the number of strides,and number filters. 回答1: Welcome to main question of deep learning. There is no valid, single solution which fits to all problems. There are some patterns though, like starting with few filters in early layers and increase filter count while reducing the sizes. For you, the best would be to start reading existing architectures like

Lambda layer in Keras with keras.backend.one_hot gives TypeError

懵懂的女人 提交于 2019-12-11 22:04:14
问题 I'm trying to train a character level CNN using Keras. I take as input a single word. I have already transformed the words into lists of indices, but when I try to feed it into one_hot , I get a TypeError . >>> X_train[0] array([31, 14, 23, 29, 27, 18, 12, 30, 21, 10, 27, 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,

load_model and Lamda layer in Keras

青春壹個敷衍的年華 提交于 2019-12-11 18:12:44
问题 How to load model that have lambda layer? Here is the code to reproduce behaviour: MEAN_LANDMARKS = np.load('data/mean_shape_68.npy') def add_mean_landmarks(x): mean_landmarks = np.array(MEAN_LANDMARKS, np.float32) mean_landmarks = mean_landmarks.flatten() mean_landmarks_tf = tf.convert_to_tensor(mean_landmarks) x = x + mean_landmarks_tf return x def get_model(): inputs = Input(shape=(8, 128, 128, 3)) cnn = VGG16(include_top=False, weights='imagenet', input_shape=(128, 128, 3)) x =

keras limiting output min max value

北城余情 提交于 2019-12-11 16:57:53
问题 My question is simple. How do I make keras output to be limited with boundaries - min and max? Some people suggest me to make a custom activation function to converts the output to transform in min and max values. I want it to be my last option. I thought kernel_constraint and bias_constraint on Dense layer with min_max_norm will work but it turns out to be not working. 回答1: If you can sacrifice the linearity of the activation function, then this is easy, you can use Sigmoid to get between 0