python - “顺序”对象没有属性 '_in_multi_worker_mode'

标签 python tensorflow sequential

我尝试使用Google colab资源保存CNN模型权重,但出现此错误。我尝试使用Google搜索,但没有任何帮助。

'Sequential' object has no attribute '_in_multi_worker_mode'



我的代码:
checkpoint_path = "training_1/cp.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)
cp_callback = tf.keras.callbacks.ModelCheckpoint(checkpoint_path, save_weights_only=True, verbose=1)


cnn_model = Sequential()
cnn_model.add(Conv2D(filters = 64, kernel_size = (3,3), activation = "relu", input_shape = Input_shape ))
cnn_model.add(Conv2D(filters = 64, kernel_size = (3,3), activation = "relu"))
cnn_model.add(MaxPooling2D(2,2))
cnn_model.add(Dropout(0.4))

cnn_model = Sequential()
cnn_model.add(Conv2D(filters = 128, kernel_size = (3,3), activation = "relu"))
cnn_model.add(Conv2D(filters = 128, kernel_size = (3,3), activation = "relu"))
cnn_model.add(MaxPooling2D(2,2))
cnn_model.add(Dropout(0.3))


cnn_model.add(Flatten())

cnn_model.add(Dense(units = 512, activation = "relu"))
cnn_model.add(Dense(units = 512, activation = "relu"))

cnn_model.add(Dense(units = 10, activation = "softmax"))

history = cnn_model.fit(X_train, y_train, batch_size = 32,epochs = 1, 
shuffle = True, callbacks = [cp_callback])

堆栈跟踪:
AttributeError                            Traceback (most recent call last)
<ipython-input-19-35c1db9636b7> in <module>()
----> 1 history = cnn_model.fit(X_train, y_train, batch_size = 32,epochs = 1, shuffle = True, callbacks = [cp_callback])

4 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/callbacks.py in on_train_begin(self, logs)
    903   def on_train_begin(self, logs=None):
    904     # pylint: disable=protected-access
--> 905     if self.model._in_multi_worker_mode():
    906       # MultiWorkerTrainingState is used to manage the training state needed
    907       # for preemption-recovery of a worker in multi-worker training.

AttributeError: 'Sequential' object has no attribute '_in_multi_worker_mode'

最佳答案

我最近也遇到过同样的问题

代替,

from tensorflow.keras.callbacks import ModelCheckpoint

用,
from keras.callbacks import ModelCheckpoint

关于python - “顺序”对象没有属性 '_in_multi_worker_mode',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58650715/

相关文章:

python - 退出状态为 128 的子进程调用

python - 如何使用保存的模型在 google colab 中恢复训练?

java - 如何读取hadoop顺序文件?

javascript - 简单但困难。如何强制外部库函数按顺序运行?

MySQL 连续连续行字段,即使在删除和插入时也是如此

python - 如何将一列中的文本拆分为多行?

python - 如何将第一列设置为空 np.zeros numPy 矩阵的常数值?

python - 如何在scrapy Spider中访问管道数据库池

python - 无法连接 Keras Lambda 层

tensorflow - 为二维张量创建索引