简体   繁体   中英

Google Cloud can't save Tensorflow model from Jupyter Notebook

I am creating and training a TensorFlow model in Google Cloud in their JupyterLab AI Notebooks but for some reason I cannot find a way to save my model after it's been created.

Typically, I'd use created_model.save(str('/saved_model_file')) in Colab to save to the local directory.

But JuptyerLab in Google Cloud responds with a "Permission Denied" error, I've tried giving all possible maximum permissions in AIM, I'm the only person on the count. But the error persists.

But I do seem capable of saving blobs to Buckets by using blob.upload_from_filename(source_file_name) or blob.upload_from_string(source_file_name) which saving to buckets seems like a more appropriate strategy.

But neither one of these will take the trained model created by TensorFlow since it's more of a function and not a file type they seem to be looking for. The tutorials seem to casually mention that you should save your model to a bucket but completely neglect to provide any simple code examples, apparently I'm the only guy on earth who wasn't born knowing how to do this.

Would be a great if someone could provide some code examples on how to save a TensorFlow model to a bucket. I also need for this function to be done automatically by the python code. Thanks!

It seems you just need to create the path with the OS module first then the TF function will work. This seems kind of odd, other platforms I've used let the TF function create the path by its self. Apparently Google Cloud doesn't like that, perhaps there's some user permission buried in a hierarchy somewhere that is causing this problem.

MODEL_NAME = 'model_directory'
model_version = int(time.time())
model_path = os.path.join(MODEL_NAME, str(model_version))
os.makedirs(model_path)
tf.saved_model.save(model, model_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM