In GCP ai-platform I am trying to write simple logs to a file in addition to saving a tf.keras model. However, saving the model with tf.saved_model.save
works, while writing to a .txt using with open(file) as out:
does not and raises this:
FileNotFoundError: [Errno 2] No such file or directory: 'gs://my-test-bucket-001/keras-job-dir/mnist_model_export/results.txt'
Can anyone explain what is the difference in how ai-platform discovers file paths?
My request essentially looks like this (see 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
The relevant part of trainer/task.py script is this:
# 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)
NoSuchKey