1

at the moment, I work with 400+ images and upload them with

from google.colab import files
uploaded = files.upload()

This one's working fine but I have to reupload all the images every time I leave my colaboratory. Pretty annoying because the upload takes like 5-10 minutes.

Any possibilities to prevent this? It seems like Colaboratory is saving the files only temporarily.

I have to use Google Colaboratory because I need their GPU.

Thanks in advance :)

Kirschbrot
  • 83
  • 2
  • 8

2 Answers2

6

As far as I know, there is no way to permanently store data on a Google Colab VM, but there are faster ways to upload data on Colab than files.upload().

For example you can upload your images on Google Drive once and then 1) mount Google Drive directly in your VM or 2) use PyDrive to download your images on your VM. Both of these options should be way faster than uploading your images from your local drive.

Mounting Drive in your VM

  1. Mount Google Drive:

    from google.colab import drive
    drive.mount('/gdrive')
    
  2. Print the contents of foo.txt located in the root directory of Drive:

    with open('/gdrive/foo.txt') as f:
        for line in f:
            print(line)
    

Using PyDrive

Take a look at the first answer to this question.

ninjin
  • 808
  • 7
  • 11
0

First Of All Mount Your Google Drive:

# Load the Drive helper and mount
from google.colab import drive

# This will prompt for authorization.
drive.mount('/content/drive')

Result is :

Mounted at /content/drive

For Checking Directory Mounted Run this command:

# After executing the cell above, Drive
# files will be present in "/content/drive/My Drive".
!ls "/content/drive/My Drive"

Result is Something Like This:

07_structured_data.ipynb       Sample Excel file.xlsx
BigQuery recipes           script.ipynb
Colab Notebooks            TFGan tutorial in Colab.txt
Copy of nima colab.ipynb       to_upload (1).ipynb
created.txt            to_upload (2).ipynb
Exported DataFrame sheet.gsheet    to_upload (3).ipynb
foo.txt                to_upload.ipynb
Pickle + Drive FUSE example.ipynb  variables.pickle
Sample Excel file.gsheet
Masoud Bimar
  • 5,860
  • 4
  • 22
  • 29