Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload folders to Google Colab?

I want to run a notebook that uses many header files defined in the directory. So basically I want to upload the entire directory to Google Colab so that I can run the notebook. But I am unable to find any such options and only able to upload files not complete folders. So can someone tell me how to upload entire directory to google colab?

like image 714
Madhuparna Bhowmik Avatar asked Jun 04 '19 18:06

Madhuparna Bhowmik


4 Answers

I suggest you not to upload them just in Colab, since when you're restarting the runtime you will lose them (just need to re-upload them, but it can be an issue with very big datasets). I suggest you to use the google.colab package to manage files and folders in Colab. Just upload everything you need to your google drive, then import:

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

In this way, you just need to login to your google account through google authentication API, and you can use files/folders as if they were uploaded on Colab.

like image 69
mao95 Avatar answered Oct 02 '22 09:10

mao95


You can zip them, upload, then unzip it.

!unzip file.zip

like image 43
korakot Avatar answered Oct 02 '22 09:10

korakot


The easiest way to do this, if the folder/file is on your local drive:

  1. Compress the folder into a ZIP file.
  2. Upload the zipped file into colab using the upload button in the File section. Yes, there is a File section, see the left side of the colab screen.
  3. Use this line of code to extract the file. Note: The file path is from colab's File section.
from zipfile import ZipFile
file_name = file_path

with ZipFile(file_name, 'r') as zip:
  zip.extractall()
  print('Done')
  1. Click Refresh in the colab File section.
  2. Access the files in your folder through the file paths

Downside: The files will be deleted after the runtime is over.

You can use some part of these steps if your file is on a Google Drive, just upload the zipped file to colab from Google Drive.

like image 23
Temitope Babatola Avatar answered Oct 02 '22 08:10

Temitope Babatola


you can create a git repository and push the files and folders to it, and then can clone the repository in colaboratory with the command

!git clone https://github.com/{username}/{projectname}.git

i feel this method is faster. but if the file size is more than 100 mb you will have to zip the file or will have to add extentions to push it to github. for more information refer the link below.

https://help.github.com/en/github/managing-large-files/configuring-git-large-file-storage

like image 30
Lavanya V Avatar answered Oct 02 '22 07:10

Lavanya V