Running machine learning model on Google Colab

Yash Jain
2 min readApr 19, 2019

--

Suppose you have written a machine learning model which is modular in nature with multiple python files and want to run this model on a GPU being provided by Google Colab

Here are the simple steps

Upload the code on Github

Navigate to Colab through the Gmail account and follow the below steps to execute the model

Go to File → New Python 3 notebook

Execute the command “!git clone <<git repo path>>” (Remember this need to be a public project else you have to supply the username and password as well in the link)

Cloning git project in colab

Type “!ls” to see the cloned files

To navigate inside a folder we can use the command “cd <<folder name>>”

ls and cd command

To execute the model just say “!python <<python file to execute>>”. This should run the model in Colab

To enable GPU backend for the notebook click “Edit ->Notebook settings”

Enable GPU

To push to the git repository use the below command

!git remote set-url origin https://{Username}:{password}!@github.com/{Username}/project.git

In case you are getting the following error while executing commit command in

  • ** Please tell me who you are. Run git config — global user.email “you@example.com” git config — global user.name “Your Name” to set your account’s default identity. Omit — global to set the identity only in this repository. fatal: unable to auto-detect email address (got ‘root@276ca37e26ec.(none)’)

Execute the following command

!git config — global user.email “{Username}”

Boom ! Start training the model

--

--

No responses yet