【ERROR】FailedPreconditionError: checkpoint is not a directory

简介: 【ERROR】FailedPreconditionError: checkpoint is not a directory

贴一段代码:

import tensorflow as tf
import os
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
              metrics=['sparse_categorical_accuracy'])
checkpoint_save_path = "./checkpoint/mnist.ckpt"
if os.path.exists(checkpoint_save_path + '.index'):
    print('-------------load the model-----------------')
    model.load_weights(checkpoint_save_path)
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_save_path,
                                                 save_weights_only=True,
                                                 save_best_only=True)
history = model.fit(x_train, y_train, batch_size=32, epochs=5, validation_data=(x_test, y_test), validation_freq=1,
                    callbacks=[cp_callback])
model.summary()

这是北大公开课tensorflow笔记的代码,一个字没改。

在python3.10.11+tensorflow2.12.0的组合下,一直报错:

Epoch 1/5
1854/1875 [============================>.] - ETA: 0s - loss: 0.2607 - sparse_categorical_accuracy: 0.9253
FailedPreconditionError: checkpoint is not a directory

手动创建文件夹目录也没辙,一直报这个错。

将版本换回python3.7+tensorflow2.1,成功运行。

后来我拿python3.10.11+tensorflow2.12.0的组合跑tensorflow的官方案例,也报同样的错误。

好家伙。我一贯的风格就是能用最新版就直接上最新版,这一波操作直接把我整懵逼了,不过版本这玩意儿不应该向下兼容的嘛?

能力不够,没去扒tensorflow的源码,所以不知道这个报错啥情况也没法修改。

记录一下,免得后人再踩坑,有人碰到类似的情况,或者除了换版本有更好的解决办法,麻烦踢我一下。

目录
相关文章
ftok info: No such file or directory
ftok info: No such file or directory
204 0
|
存储
rman备份失败:ORA-00245: control file backup failed; target is likely on a local file system
rman备份失败:ORA-00245: control file backup failed; target is likely on a local file system
158 0
|
SQL 监控
backup log is terminating abnormally because for write on file failed: 112(error not found)
昨天遇到一个案例,YourSQLDba做事务日志备份时失败,检查YourSQLDba输出的错误信息如下:   yMaint.backups backup log [gewem] to disk = 'M:\DB_BACKUP\LOG_BACKUP\xxxx_[2016-11-22_01h11m05_Tue]_logs.
1240 0