-
-
Save bzamecnik/bd3786a074f8cb891bc2a397343070f1 to your computer and use it in GitHub Desktop.
I am getting following error when trying to load_weights that are saved from cudnngru model.
AttributeError: 'Dataset' object has no attribute 'reshape'
Architecture code on GPU machine:
input_layer = Input(shape=(sequence_length,))
embedding_layer = Embedding(embedding_matrix.shape[0], embedding_matrix.shape[1],
weights=[embedding_matrix], trainable=False)(input_layer)
x = Bidirectional(CuDNNGRU(recurrent_units, return_sequences=True))(embedding_layer)
x = Dropout(dropout_rate)(x)
x = Bidirectional(CuDNNGRU(recurrent_units, return_sequences=True))(x)
x_max = GlobalMaxPool1D()(x)
x_avg = GlobalAveragePooling1D()(x)
x = concatenate([x_max, x_avg])
# x = Dense(dense_size, activation="relu")(x)
output_layer = Dense(6, activation="sigmoid")(x)
model = Model(inputs=input_layer, outputs=output_layer)
model.compile(loss='binary_crossentropy', optimizer=RMSprop(clipvalue=1, clipnorm=1), metrics=['accuracy'])
Code to save the weights on GPU machine:
model.save_weights("model0_weights.h5")
Architecture code on CPU machine:
input_layer = Input(shape=(sequence_length,))
embedding_layer = Embedding(embedding_matrix.shape[0], embedding_matrix.shape[1],
weights=[embedding_matrix], trainable=False)(input_layer)
x = Bidirectional(GRU(recurrent_units, reset_after=True, recurrent_activation='sigmoid', return_sequences=True))(embedding_layer)
x = Dropout(dropout_rate)(x)
x = Bidirectional(GRU(recurrent_units, reset_after=True, recurrent_activation='sigmoid', return_sequences=True))(x)
x_max = GlobalMaxPool1D()(x)
x_avg = GlobalAveragePooling1D()(x)
x = concatenate([x_max, x_avg])
output_layer = Dense(6, activation="sigmoid")(x)
model = Model(inputs=input_layer, outputs=output_layer)
model.compile(loss='binary_crossentropy', optimizer=RMSprop(clipvalue=1, clipnorm=1), metrics=['accuracy'])
Code to reload the saved weights:
model_0_weights = model.load_weights("model0_weights.h5")
Please let me know if I am doing something wrong.
@bzamecnik, Could you please respond to my comment. I have a trained model with CudNNGRU trained on GPU, but I am not able to make them use on CPU environment for predictions. Thanks in advance.
Having the same error:
AttributeError: 'Dataset' object has no attribute 'reshape'
@SatishDivakarla: Sorry, I missed your comment... Don't you have the original stack trace? If I remember correctly I saw something similar in Keras issues and the cause was that the weights were a h5py Dataset instead of a numpy array. I'm not sure about resolution.
@SatishDivakarla: Aah, keras-team/keras#9112 (comment). Fixed in keras-team/keras#9662 (2018-03-15). Will be released in Keras 2.1.6.
In the resulting PR it's even possible to convert GRU weights to CuDNNGRU and LSTM weights to CuDNNLSTM!