层 ModuleWrapper 在 `__init__` 中有参数,因此必须覆盖 `get_config`.在科拉布 [英] Layer ModuleWrapper has arguments in `__init__` and therefore must override `get_config`. in Colab

查看:26
本文介绍了层 ModuleWrapper 在 `__init__` 中有参数,因此必须覆盖 `get_config`.在科拉布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作 keras 模型检查点代码.但是每当我启动代码时,就会发生 get_config 错误.下面是我的 keras 代码.

I'm trying to make keras modelcheckpoint code. But Whenever I started the code, that get_config error occured. Below is my keras code.

model = keras.Sequential()
model.add(keras.layers.Flatten(input_shape=(8,)))
model.add(keras.layers.Dense(512))
model.add(LeakyReLU(alpha=0.2))
model.add(keras.layers.Dropout(0.1))
model.add(keras.layers.Dense(1))
model.compile(optimizer = keras.optimizers.Adam(learning_rate =0.0001),
            loss = keras.losses.MeanSquaredError(reduction="auto"),
            metrics = 'mae')


mc2 = keras.callbacks.ModelCheckpoint('best_model_scaled'+str(fold_no)+'.h5', 
monitor='val_loss', mode='min', save_best_only=True,verbose=1)
es=keras.callbacks.EarlyStopping(monitor='val_loss', mode='min', patience=1500)
history = model.fit(x_train2, y_train2, batch_size=16,epochs=2000, validation_data = (x_val2, y_val2), callbacks = [es,mc2])

我看到了其他问题,发现def get_config(self):"代码解决了问题.但我没有Class():"get_config(self)"的代码.请帮我解决问题.谢谢!

I saw other questions and found that "def get_config(self):" code solves the problem. But I have no "Class():" code for "get_config(self)". Please help me solve the problem. Thanks!

推荐答案

这个问题是由 kerastf.keras 库之间的混合导入引起的,这不是支持.

This problem is caused by mixing imports between the keras and tf.keras libraries, which is not supported.

您应该永远不要在这些库之间混合导入,因为它不会工作并产生各种奇怪的错误消息.这些错误随着 kerastensorflow 的版本而变化.

You should never mix imports between these libraries, as it will not work and produces all kinds of strange error messages. These errors change with versions of keras and tensorflow.

这篇关于层 ModuleWrapper 在 `__init__` 中有参数,因此必须覆盖 `get_config`.在科拉布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆