How to use Google Colab for advanced machine learning programming tasks in Coursera. Also serves as a private memo.
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.
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.
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.
First, open the assignment note and click on the COURSERA logo in the upper left.
Then a list of files will be displayed. Select "setup_google_colab.py" to open it.
You can download the file to your PC by selecting Download from the File tab on the upper left.
In the same way, drop the .ipynb of the assignment to your PC.
Upload the dropped file on your google drive.
Then mount Drive so that Colab can access the files on your Google Drive.
from google.colab import drive
drive.mount('/content/drive')
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.
Click on the'three' mark next to it and you'll see that the files on your drive are under the'drive' directory.
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()
that's all. The assignment notes will now run on Colab.
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