keras

Pytorch Batchnorm layer different from Keras Batchnorm

核能气质少年 提交于 2021-02-19 03:38:08
问题 I'm trying to copy pre-trained BN weights from a pytorch model to its equivalent Keras model but I keep getting different outputs. I read Keras and Pytorch BN documentation and I think that the difference lies in the way they calculate the "mean" and "var". Pytorch: The mean and standard-deviation are calculated per-dimension over the mini-batches source: Pytorch BatchNorm Thus, they average over samples. Keras: axis: Integer, the axis that should be normalized (typically the features axis).

How can I save an object containing keras models?

情到浓时终转凉″ 提交于 2021-02-19 03:33:07
问题 Here is my code skeleton: def build_model(x, y): model = tf.keras.models.Sequential() model.add(tf.keras.layers.Dense(1, activation='relu')) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(x, y) return model class MultiModel(object): def __init__(self, x1, y1, x2, y2): self.model1 = build_model(x1, y1) self.model2 = build_model(x2, y2) if __name__ == '__main__': # code that builds x1, x2, y1, y2 mm = MultiModel(x1, y1, x2, y2) # How to save mm ? The issue is I don't know

Why val_loss and val_acc are not displaying?

六月ゝ 毕业季﹏ 提交于 2021-02-19 03:19:38
问题 When the training starts, in the run window only loss and acc are displayed, the val_loss and val_acc are missing. Only at the end, these values are showed. model.add(Flatten()) model.add(Dense(512, activation="relu")) model.add(Dropout(0.5)) model.add(Dense(10, activation="softmax")) model.compile( loss='categorical_crossentropy', optimizer="adam", metrics=['accuracy'] ) model.fit( x_train, y_train, batch_size=32, epochs=1, validation_data=(x_test, y_test), shuffle=True ) this is how the

Discrepancy between R's Keras and Python's Keras — Accuracy bug?

我们两清 提交于 2021-02-19 02:31:20
问题 I'm playing with some 2D CNN using Keras to predict Bike Sharing Demand. R performs very poorly vs Python, which reach good accuracy easily. I thought it was because of arrays shape (and some differences between R and Python), so I play with that for a while, ultimately using all possible shapes. I created the CombinationGrid object elsewhere and it looks like this: +------+------+------+------+-------+ | Dim1 | Dim2 | Dim3 | Dim4 | Order | +------+------+------+------+-------+ | 8887 | 3 | 2

tf.keras: Evaluating model.updates breaks when using a tf.data.Dataset as input

别来无恙 提交于 2021-02-19 02:01:09
问题 Note: All code for a self-contained example to reproduce my problem can be found below. I have a tf.keras.models.Model() instance and would like to train that with a custom low-level TensorFlow API training loop. As part of this training loop, I need to make sure that my custom training loop updates all stateful variables from layer types such as tf.keras.layers.BatchNormalization . In order for this to happen, I understand from this answer by Francois Chollet that I need to evaluate model

Keras TypeError: can't pickle _thread.RLock objects

巧了我就是萌 提交于 2021-02-19 01:48:23
问题 from keras.layers import Embedding, Dense, Input, Dropout, Reshape from keras.layers.convolutional import Conv2D from keras.layers.pooling import MaxPool2D from keras.layers import Concatenate, Lambda from keras.backend import expand_dims from keras.models import Model from keras.initializers import constant, random_uniform, TruncatedNormal class TextCNN(object): def __init__( self, sequence_length, num_classes, vocab_size, embedding_size, filter_sizes, num_filters, l2_reg_lambda=0.0): #

Train multiple keras/tensorflow models on different GPUs simultaneously

有些话、适合烂在心里 提交于 2021-02-19 01:42:07
问题 I would like to train multiple models on multiple GPUs at the simultaneously from within a jupyter notebook. I am working on a node with 4GPUs. I would like to assign one GPU to one model and train 4 different models at the same time. Right now, I select a GPU for one notebook by (e.g.): import os os.environ['CUDA_VISIBLE_DEVICES'] = '1' def model(...): .... model.fit(...) In four different notebooks. Though, then the results and the output of the fitting procedure is distributed in four

ValueError: Shape mismatch: The shape of labels (received (15,)) should equal the shape of logits except for the last dimension (received (5, 3))

*爱你&永不变心* 提交于 2021-02-18 23:26:25
问题 I am getting this error when trying to fit a model: ValueError: Shape mismatch: The shape of labels (received (15,)) should equal the shape of logits except for the last dimension (received (5, 3)). The code that's producing the error: history = model.fit_generator( train_generator, epochs=10, validation_data=validation_generator) This is the train_generator, validation generator is similar: train_datagen = ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory

Keras Embedding ,where is the “weights” argument?

感情迁移 提交于 2021-02-18 22:33:28
问题 I have seen such kind of code as follow: embed_word = Embedding(params['word_voc_size'], params['embed_dim'], weights=[word_embed_matrix], input_length = params['word_max_size'] , trainable=False, mask_zero=True) When I look up the document in Keras website [https://faroit.github.io/keras-docs/2.1.5/layers/embeddings/][1] I didnt see weights argument, keras.layers.Embedding(input_dim, output_dim, embeddings_initializer='uniform', embeddings_regularizer=None, activity_regularizer=None,

CTC LOSS ERROR InvalidArgumentError: Not enough time for target transition sequence

≯℡__Kan透↙ 提交于 2021-02-18 19:53:17
问题 CTC LOSS ERROR InvalidArgumentError: Not enough time for target transition sequence 回答1: your ground-truth (GT) text is too long. Your input matrix for the CTC loss function has a time-axis with length T. Your GT text must not be longer than T. Example: input matrix has length 4, your GT text is "world" with length 5, then there is no way that the matrix can contain this text, because it can encode at most 4 chars. If the GT text contains duplicate chars (like in pi zz a), then the CTC