I use Google Colaboratory then I want to save output images in my Google Drive or SSD, HHD but its directory is "/content"
import os
print(os.getcwd())
# "/content"
so is it possible to change path (HDD, SSD, googledrive)?
save("/content/drive/MyDrive/aa/xyz. jpeg") of PTL library works like magic. Below the overall code snippet. So you can easily read image from google drive and save image to google drive from google colab.
To save weights manually, use tf. keras. Model. save_weights .
You need to mount google drive to your Colab session.
from google.colab import drive
drive.mount('/content/gdrive')
Then you can simply write to google drive as you would to a local file system like so:
with open('/content/gdrive/My Drive/file.txt', 'w') as f:
f.write('content')
To save the weight you can run the following after training.
saver = tf.train.Saver()
save_path = saver.save(session, "data/dm.ckpt")
print('done saving at',save_path)
Check the location where the ckpt files were saved.
import os
print( os.getcwd() )
print( os.listdir('data') )
Finally download the file!
from google.colab import files
files.download( "data/dm.ckpt.meta" )
One of the other simple methods to save a file to Google Drive I found here is to use the command cp
after you mounted the drive.
Here is the code:
from google.colab import drive
drive.mount('/content/gdrive')
Then use this:
!cp -r <CURRENT FILE PATH> <PATH YOU WANT TO SAVE>
Example:
!cp -r './runs/exp0.h5' /content/drive/MyDrive/Exp1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With