在 GCP ai-platform 中,除了保存 tf.keras 模型外,我还尝试将简单日志写入文件。但是,使用tf.saved_model.save
作品保存模型,而写入 .txt 使用with open(file) as out:
不会并会引发以下问题:
FileNotFoundError: [Errno 2] No such file or directory: 'gs://my-test-bucket-001/keras-job-dir/mnist_model_export/results.txt'
谁能解释 ai-platform 如何发现文件路径有什么区别?
我的请求基本上看起来像这样(请参阅https://cloud.google.com/ai-platform/docs/getting-started-keras)
...
JOB_DIR = gs://my-test-bucket-001/keras-job-dir
gcloud ai-platform jobs submit training $JOB_NAME \
--package-path trainer/ \
--module-name trainer.task \
--region $REGION \
--python-version 3.7 \
--runtime-version 2.1 \
--job-dir $JOB_DIR \
--stream-logs
trainer/task.py 脚本的相关部分是这样的:
# use this path to save outputs
export_path = os.path.join(args.job_dir, 'mnist_model_export')
# this works
tf.saved_model.save(mnist_model, export_path)
# this fails when included
with open(os.path.join(export_path, 'results.txt'), 'a+') as out:
log_str = "Job finished! {}\n".format(time.strftime('%Y-%m-%d %H:%M:%S'))
out.write(log_str)