How to open and work on files stored in Google drive from Google colab? - google-colaboratory

So I cannot successfully install miniconda and decided to work in Google Colab. But my local repository is in Google Drive. All of the jupyter notebook that I want to work on is store in Google Drive. I want to work on them in Google Colab. However, I cannot open the files other than the ones stored in Colab folder of Google drive. What should I do now?

What works for me is opening the notebook from Google Drive, not from Colab.
The following steps:
Open Google Drive in your browser, go to the notebook (ipynb) file in your repo (sub)folder;
Right-click the file and select 'Open with Google Colaboratory', now Colab opens with the notebook;
For this you might have to install the 'Open in Colab' chrome extension
Mount Google Drive from Colab (if not mounted yet), see code snippet;
Change directory to the folder where you want to run your notebook, see code snippet;
Now I can run my notebook
Mount drive:
from google.colab import drive
drive.mount('/content/drive')
Change directory to your repository folder:
%cd drive/My Drive/ColabNotebooks/(YOUR_REPO_PATH)

To open and work a notebook in your Google drive, open it from Google Drive UI in Chrome. From the Google colab UI menu -> Open notebook, we can only open those in Colab Notebooks folder.
Easy way would be to save all your notebooks in the Colab Notebooks folder.

First you need to mount google drive and then
from google.colab import drive
drive.mount('/content/gdrive')
Click the link on colb and authenticate (copy password and paste in colab) to mount and access your gdrive.
You can access your folder as shown below
path_to_data = '/content/gdrive/My Drive/MyFolder_where_data_stored'
Unique_Labels_List = os.listdir(path_to_data)
After running model, save the model, zip and download to local.
!zip -r ./MyFolder.zip /content/MyFolder
files.download("/content/MyFolder.zip")
There are many other things you can do. Check this resource for some more commands and you can find many more by searching in google. Thanks!

Related

How do I download python notebook (.ipynb) file with Output saved in it from Google Colab?

How can I download the complete Jupyter notebook (.ipynb) I created on Google Colab, including the code, comments, and outputs, as I am only able to download the notebook with the code and comments, but not the output?
I tried to downlaod .ipynb file manually from file > Download > .ipynb on Google Colab

not able to find shared library files in google colab

I am working on deep learning architecture which uses shared library files which are built on the local system, now my computer is not having space to run my code, so I want to run my code in colab. To run on colab, the colab is not showing my shared libraries file which I am trying to build on google colab.
You need to mount your GDrive and copy the files from Colab cloud working directory
!mv /content/filename /content/gdrive/My\ Drive/

Accessing contents of /contents folder in Google Colab?

I want to train yolo on my own data and am using Google Colab but unable to edit .cfg files stored in contents folder. One solution I can think of is to fuse the google drive and installing darknet in gmail drive and running the program with drive as my working directory.

Open Google Colab notebook from URL

I have a Python file available under some URL, for example
https://gist.githubusercontent.com/messa/d19ad7fd4dc0f95df9caf984caef127c/raw/4d0daebdcfcf16ea3b7914ee6186bd98dbfb3c20/demo.py
In reality it will not be gist but some courseware/homework review software.
How can I open such URL using Google Colab so I can for example run the Python code?
I know I can build colab URL for Github gists or repositories, but can I do it for any arbitrary URL?
There is currently no way to do what you are asking for – to construct a URL that will cause Colab to automatically load the contents of a .py file at a particular URL into a new Colab notebook.
The closest thing to this is to host a notebook on github, and then use a Colab url to open it: e.g.
http://github.com/username/repository/path/to/notebook.ipynb can be opened in Colab using http://colab.research.google.com/github/username/repository/path/to/notebook.ipynb
http://gist.github.com/username/hash/filename.ipynb can be opened in Colab using http://colab.research.google.com/gist/username/hash/filename.ipynb

Sync chroot folder with Google Drive or Dropbox in Chrome OS

I have crouton running on a chromebook 11 with ubuntu precise in it. I am looking for a way to sync files in some folders in the ubuntu chroot with Google Drive. I am thinking I can create a link between the mounted chroot partition and a sync'ed folder in the Chrome OS, but I can't find where the synced Google Drive folder is in Chrome OS.
Could anyone please help?
Bottom line I want to sync files I create in the chroot to an online service, Google Drive or Dropbox, whatever works.
Thank you in advance
SUMMARY
The best way to sync files (code, in my case) is to use git and bitbucket/github. Install git in the chroot, and sync the code into the Downloads folder so it can be accessed from both ChromeOS and the chroot (and compiled and ran locally on both computers). I stored all other files in Google Drive so they could be accessed from ChromeOS, other computers, and the chroot.
Here are the options I looked into, but did not end up using
Accessing the Google Drive cache directly on the chromebook
Google drive in the chrome os stores the file data in
/home/chronos/user/GCache/v1/files
However, it does not name the files how they are named in google drive (it names them by some uuid, and stores meta in another folder).
3rd party tools to mount Google Drive folder in linux
https://github.com/dsoprea/GDriveFS
I was able to get GDriveFS working, but it was slow and chmod does not work in its file system. The permission are all static at 666, so programs will not execute.
https://github.com/astrada/google-drive-ocamlfuse/
I was not able to get ocamlfuse working on an arm Chromebook.
https://github.com/Grive/grive
I was able to get Grive working, but it has some problems and hasn't been updated in over a year. Would not recommend if there is a chance of merge conflicts.