How to set up a Google Colab environment with Coursera's advanced machine learning courses

How to use Google Colab for advanced machine learning programming tasks in Coursera. Also serves as a private memo.

Background

I started taking advanced machine learning courses about two days ago, but in the programming task of the third week, I finally said, "It can be executed in the environment provided by Coursera, but it takes 2 hours to train the model because it is a CPU! I was told, so I switched to Google Colaboratory, which can use GPU, as soon as possible.

Coursera programming assignment submission mechanism

In Coursera's (or rather this course?) Programming task, at each checkpoint, send variable values (such as model predictions and total number of parameters) to Coursera to see if the values are acceptable. It is a mechanism that you can get points by doing so. There are about 6 checkpoints for each task. At this time, we are using our own module called grading_utils. The main purpose of this time is to make this module callable from Colab.

File download

In fact, Coursera has prepared a file called "setup_google_colab.py" so that you can build an environment with Colab. First, download this file.

  1. First, open the assignment note and click on the COURSERA logo in the upper left. スクリーンショット 2020-03-05 3.26.16.png

  2. Then a list of files will be displayed. Select "setup_google_colab.py" to open it. スクリーンショット 2020-03-05 3.28.54.png

  3. You can download the file to your PC by selecting Download from the File tab on the upper left. スクリーンショット 2020-03-05 3.29.06.png

  4. In the same way, drop the .ipynb of the assignment to your PC.

  5. Upload the dropped file on your google drive.

Google Drive mount

Then mount Drive so that Colab can access the files on your Google Drive.

  1. First, open the uploaded issue file in Colab.
  2. Execute the following command.
from google.colab import drive
drive.mount('/content/drive')
  1. When you execute it, a link will appear like this. Go to the link to get the authorization code and enter your authorization code: to complete the mount. スクリーンショット 2020-03-05 3.45.15.png

  2. Click on the'three' mark next to it and you'll see that the files on your drive are under the'drive' directory. スクリーンショット 2020-03-05 3.54.45.png

Setup module import

All you have to do now is import the module through the path. For example, in my case, the location of the file is "My Drive / HOME / Coursera / setup_google_colab.py", so the following command will add the path to sys.path.

import sys
sys.path.append('/content/drive/My Drive/HOME/Cousera/')

You can now import it.

import setup_google_colab

Setup In setup_google_colab, the function for setting for each issue is defined, and when executed, the necessary external modules and files are automatically downloaded to the folder of colab. This time it's issue 3, so

setup_google_colab.setup_week3()
スクリーンショット 2020-03-05 4.05.34.png

that's all. The assignment notes will now run on Colab.

Finally

After all, I made a mistake in the structure of the model and retrained it about 3 times, so I thought I would do it with the CPU and it would be a cold sweat. By the way, I wrote in the notebook that it takes 1 hour and 30 minutes for CPU, but the calculation was completed in just over 4 minutes for GPU. As expected ...

Recommended Posts

How to set up a Google Colab environment with Coursera's advanced machine learning courses
How to set up a Python environment using pyenv
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS with anaconda
How to create a serverless machine learning API with AWS Lambda
Machine learning with Pytorch on Google Colab
How to quickly create a machine learning environment using Jupyter Notebook on macOS Sierra with anaconda
How to set up a local development server
Build a Python machine learning environment with a container
How to run AutoGluon in Google Colab GPU environment
Build a machine learning application development environment with Python
How to set up and compile your Cython environment
Set up a Python development environment with Sublime Text 2
Create a machine learning environment from scratch with Winsows 10
About learning with google colab
Build a machine learning environment
Set up a Python development environment with Visual Studio Code
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
[Google Colab] How to interrupt learning and then resume it
Launching a machine learning environment using Google Compute Engine (GCE)
How to build a python2.7 series development environment with Vagrant
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
How to interactively draw a machine learning pipeline with scikit-learn and save it in HTML
I want to set up a GUI development environment with Python or Golang on Mac
How to connect to Cloud SQL PostgreSQL on Google Cloud Platform from a local environment with Java
How to set a shortcut to switch full-width and half-width with IBus
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
How to make a crawler --Advanced
How to set up the development environment of ev3dev [Windows version]
How to collect machine learning data
How to make a face image data set used in machine learning (3: Face image generation from candidate images Part 1)
Send mail with mailx to a dummy SMTP server set up with python.
How to set up a jupyter notebook on ssh destination (AWS EC2)
Try to set up a Vim test environment quite seriously (for Python)
A beginner of machine learning tried to predict Arima Kinen with python
[Development environment] How to create a data set close to the production DB
Building a machine learning environment with Tellus GPU server (Sakura high-power computing)
Summary of how to build a LAMP + Wordpress environment with Sakura VPS
How to use VS Code (code server) with Google Colab in just 3 lines
[Blender] How to set shape_key with script
Introduction to Machine Learning: How Models Work
scikit-learn How to use summary (machine learning)
How to build a sphinx translation environment
How to add a package with PyCharm
Set up a Samba server with Docker
How to set up SVM using Optuna
A story about machine learning with Kyasuket
[Colab] How to copy a huge dataset
How to search Google Drive with Google Colaboratory
How to enjoy Coursera / Machine Learning (Week 10)
Creating a development environment for machine learning
Build AI / machine learning environment with Python
How to create a face image data set used in machine learning (1: Acquire candidate images using WebAPI service)
From nothing on Ubuntu 18.04 to setting up a Deep Learning environment in Tensor
How to drop Google Docs in one folder in a .txt file with python
Machine learning beginners tried to make a horse racing prediction model with python
[Machine learning] Create a machine learning model by performing transfer learning with your own data set
Instructions for connecting Google Colab. To the local runtime in a Windows environment
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer