gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:30:12 25 4
gpt4 key购买 nike

我尝试使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com