-1

I am using one of the above methods to save my model. But I get this below error , can some one help me . I am very new to this tensor flows. My Code is

Model Creation

model = Sequential()
model.add(Embedding(vocab_size, 8, input_length=max_length))
model.add(Flatten())
model.add(Dense(512,  activation='relu'))
model.add(Dense(256,  activation='relu'))
model.add(Dropout(.2))
model.add(Dense(128,  activation='relu'))
model.add(Dense(64,  activation='relu'))
model.add(Dense(number_of_classes,  activation='softmax'))
# compile the model

##only use if pre-trained
sgd = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
input_shape = X.shape  
model.build(input_shape)     
# summarize the model
model.summary()

checkpoint = ModelCheckpoint('Files5.hdf5', monitor='val_acc', verbose=1, save_best_only=True, mode='max')


history = model.fit(X_train, Y_train, validation_data=(X_val, Y_val), epochs=10, batch_size=20, callbacks=[checkpoint_callback], verbose=2)

return model, history

NotImplementedError: Layer ModuleWrapper has arguments in __init__ and therefore must override get_config

I referred these ones - but still no luck

Layer ModuleWrapper has arguments in `__init__` and therefore must override `get_config`. in Colab

How to save final model using keras?

Thank you

Morgan
  • 27
  • 5

3 Answers3

0

I also encountered a similar problem. Later I found out that the error was caused by mixing keras and tensorflow.keras. By removing tensorflow.keras, I successfully solved the error.

yuancf1024
  • 67
  • 1
  • 5
0

The above answer worked for me, except I kept getting deep copy errors on updating, so commented out the update resolves this:

    def get_config(self):

        config = super().get_config().copy()
#         config.update({
#             'labels': self.labels_array,
#             'num_labels': self.num_labels,
#         })
        return config

Now the keras model saves callback checkpoints with the new softmax derivative layer I implemented. [tensorflow 1.15, using tf.keras]

Thanks for the assist!

Edward Burgin
  • 176
  • 14
0

This can be resolved by converting all your imports to tensorflow.keras.

example :

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, LeakyReLU, ReLU, Dropout
Stanley
  • 801
  • 2
  • 10
  • 20