Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is dumped file in Google Colab?

When I wrote this code in google colab:

import pickle
x=10;
output = open('data.pkl', 'wb')
pickle.dump(x,output)

x is saved and also in another window in Google Colab I can access this file and read it but I don't know where is the file. Does anybody know where is it?

like image 696
Saber MalekzadeH Avatar asked Feb 01 '18 08:02

Saber MalekzadeH


People also ask

Where are files stored in Google Colab?

Using Colab. Colab notebooks are stored in Google Drive, or can be loaded from GitHub. Colab notebooks can be shared just as you would with Google Docs or Sheets. Simply click the Share button at the top right of any Colab notebook, or follow these Google Drive file sharing instructions.

How do I move a output file from colab to drive?

Save image to drive directly Path to save in drive can be found easily by clicking files on left side, navigating to folder and right click to choose Copy path . This will save the image to folder named Delete in Google Drive.


2 Answers

It’s in the current directory. You can also download it back to your local machine with

from google.colab import files
files.download(‘data.pkl’)
like image 67
korakot Avatar answered Oct 10 '22 11:10

korakot


You can upload it to your Google drive:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)  

# get the folder id where you want to save your file
file = drive.CreateFile({'parents':[{u'id': folder_id}]})
file.SetContentFile('data.pkl')
file.Upload() 

This code basically fetches the data.pkl from the cloud VM and upload it permanently to your Google Drive under a specific folder.

If you choose not to specify a folder, the file will be uploaded under the root of your Google Drive.

like image 30
Ahmed Besbes Avatar answered Oct 10 '22 09:10

Ahmed Besbes