Introduction
In a nutshell, Google Colaboratory is a free cloud service allowing us to play with GPU easily.
In this article, I would like to leave the basic usage of google colab(shorthand for google colaboratory) to other good entries below.
References for Introduction to Google Colaboratory
https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d
https://www.codexa.net/how-to-use-google-colaboratory/
Instead, I would like to talk about the difficulty which I have found while following the instructions.
Please use your target file to try the script in this entry
Easiest way to do
You can just upload the zipped files from the notebook directly
from google.colab import files
uploaded = files.upload()
then unzip your files
!unzip yourfile
this is the easiest way to do!lol
How to upload the data onto the accessible directory from colab?
For simplicity, let this be my current directory, and we want to read the text file from this ptb.valid.txt from Untitled0.ipynb.
Firstly, you open Untitled0.ipynb.
Then you will see this jupyter notebook on your browser.
So, from now we are trying to access to our target file.
At this moment, if you try the code below, it will return "false", because you don't mount or even create the drive directory.
import os
os.path.isfile("drive/Colab Notebooks/ptb.valid.txt")
So, let's create the folder named drive and mount it with your environment.
To mount it, you need a specific command called google-drive-ocamlfuse.
So let's get it executing scripts below.
I would like to mention that once i run this, I have got an error saying something weird,, sorry I didn't capture it though, when I run this again it went very well.
So don't give up by first error.
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
# output will go like this..
install some stuff.
...
Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=......
Wow,,, output is quite long and takes time to finish though, in the end you will be told to confirm the authentication of this access. So, following the order saying open the link, and you will visit some blue-ish page displaying your key. * I am not feeling comfortable to put that picture here..
Then try this command!
os.path.isfile("drive/Colab Notebooks/ptb.valid.txt")
# output
false
Ups...
We haven't finished creating or mounting anything yet.
So try this.
!mkdir drive
!google-drive-ocamlfuse drive
!ls drive/"Colab Notebooks"
# output
Test_20180513.ipynb Untitled0.ipynb ptb.valid.txt
Congrats, now you have mounted your directory with your environment.
Finally we can read/write the file from our jupyter notebook!!
f = open("drive/Colab Notebooks/ptb.valid.txt")
print(f.read(10))
# output
consumers
Thank you for reading.
References
how to upload local files on google colab
https://stackoverflow.com/questions/47320052/load-local-data-files-to-colaboratory
official tutorial: https://colab.research.google.com/notebook#fileId=/v2/external/notebooks/io.ipynb
google colab in japanese: https://qiita.com/tomo_makes/items/f70fe48c428d3a61e131