Skip to content

Uploading Local or Google Drive Files to Use

Vương Tuấn Khanh edited this page Jun 7, 2022 · 2 revisions

📚 This guide explains the details of the AOT Dataset 🚀. UPDATED 25 August 2021.

This tutorial will show you how to upload local or Google Drive files to the cloud VM and run detections on them!

Method 1: Local Files

To upload local files just use our helper function by running upload() as seen below. Click Choose Files and select the image from your local machine that you want to upload to the cloud VM.

If this function doesn't work for you then click the Upload button in the File Explorer on the left side of your notebook.

The image should save to your root directory so that you can access it.

%cd ../<your image name>

Or you can use this pre-defined function:

# define helper functions
def upload():
  from google.colab import files
  uploaded = files.upload() 
  for name, data in uploaded.items():
    with open(name, 'wb') as f:
      f.write(data)
      print ('saved file', name)

upload()

Method 2: Google Drive

Images can also be uploaded from your Google Drive and easily have detections run on them.

You will want to run the below cell to mount your google drive into the cloud VM so that you can access its contents. It is that easy!

NOTE: We will be creating a symbolic link between /content/gdrive/My\ Drive/ and /mydrive.

This means we are just creating a shortcut '/mydrive' to map to the contents within the folder /content/gdrive/My\ Drive/.

The reason for this is that sometime having the space in 'My Drive' folder path can cause issues when running certain commands. This symbolic link will stop this from happening!

I recommend saving images within a folder called images at the root level of your Google Drive.

On Google Colab, you can use the following Python command:

from google.colab import drive
drive.mount('/content/gdrive')

# this creates a symbolic link so that now the path /content/gdrive/My\ Drive/ is equal to /mydrive
!ln -s /content/gdrive/My\ Drive/ /mydrive
!ls /mydrive

Download Files to Local Machine or Google Drive from Cloud VM

You can also easily download images from your cloud VM to save to your local machine or Google Drive.

Method 1: Local Machine

You can do it easily by using our helper function download() or by right clicking the image in the File Explorer on the left side of your notebook and hitting Download. Files will be saved to your Downloads folder.

This is useful if you want to download the predictions.jpg images that the object detector outputs.

# use this to download a file  
def download(path):
  from google.colab import files
  files.download(path)

download('predictions.jpg')

Method 2: Google Drive

A simple copy command can copy over any file to your Google Drive as it is already mounted. (you must run the mount command above if you have not already)

!cp <file to download> <destination to save file>