How to use Google Colaboratory and usage example (PyTorch x DCGAN)

Overview

Hello. Recently (as of March 2020), the coronavirus has caused a mood of self-restraint. I myself am working hard on my research activities at home just in case, but I'm tired because I've been staying up for the past week. This time, I'm going to take a break and use Google Colaboratory, which I've always been interested in, to study. キャプaaaaaチャ.PNG

Google Colaboratory is one of the development environments that can handle SaaS type notebooks that can be used on the net, and it is very convenient because it can be synchronized with Google Drive and the GPU can be used for free. For those who are usually researching individually, coding in notebook format may not be beneficial, but for those who develop in teams that require frequent code sharing, Isn't Google Colaboratory perfect for you?

By the way, in this article, ** I will introduce the introduction of Google Colaoratory, the basic usage, the mounting method of Google Drive, and finally the learning procedure using DCGAN and actually using GPU. .. ** **

How to use Google Colaboratory

First of all, as you probably have, please log in with your google account and enter google drive.

When you enter the personal Drive page, click "New"-> "Other"-> "Add App" on the left tab. The following screen will appear, so search for it with Colaboratory and install it. キャプチャ.PNG

Now you are ready to go. (Fast!) Go back to My Drive, right-click and select "Other"-> "Colaboratory" to bring up the screen below. キャプチャ2.PNG The interface is intuitive to operate, so you can easily understand it with a little tinkering.

キャプチャ3.PNG You can write the code as it is up.

キャプチャ4.PNG You can execute the cell by pressing the play button on the left. The output is displayed below that cell.

キャプチャ5.PNG The + code and + text at the top can be used to create new cells and insert text. The example in the image above is an example of inserting text. You can fill in in markdown format.

You can save it from "File"-> "Save". It will be saved on the drive.

How to mount Google Drive (latest version)

It seems that it took a lot of time and effort to execute the script as it is, but now it is easy to mount. キャプチャ6.PNG

If you open the file-like shape on the left tab, there is "Mount Drive", so just select it. You will be asked for permission when mounting, but yes is all right. The mount is now complete.

Now, let's actually refer to the Google Drive file in the code. Performing the above method will mount My Drive on ./drive/MyDrive. The following image is an example of reading and printing "a.png " placed on My Drive.

キャプチャ7.PNG

Learning example using GPU (DCGAN)

It's dull at this rate, so let's actually learn using the GPU. First, to use the GPU, select the GPU in "Hardware Accelerator" from "Edit"-> "Notebook Settings" on the upper tab. キャプチャ8.PNG

Implement DCGAN. I borrowed the code here. Refer to the mnist example on the above site. One thing to note is the destination directory. Since My Drive is mounted on ./drive/MyDrive, you need to pass it as an argument to refer to ./drive/MyDrive.

Now, copy the code, change the directory reference, and then press the play button to learn. キャプチャ9.PNG Learning will proceed.

After completion, the generated image example will be saved in the specified directory. キャプチャ10.PNG

Finally

This time, I used Google Colaboratory and tried to actually use DCGAN for learning from the mounting procedure. The above DCGAN code also has a Convolution layer, so it's a fairly heavy process, and it's tough on a PC with low specifications. It's a feeling that I used GPU, but it seems that Nvidia K80 is turning behind the scenes, so it's fast enough. I'm very grateful to think that it can be used on a laptop and for free. It seems that you can study on the go. If I have a chance in the future, I will use it more and more.

References

https://qiita.com/shoji9x9/items/0ff0f6f603df18d631ab

Recommended Posts

How to use Google Colaboratory and usage example (PyTorch x DCGAN)
How to use Google Colaboratory
How to use Spacy Japanese model in Google Colaboratory
[Implementation explanation] How to use the Japanese version of BERT in Google Colaboratory (PyTorch)
How to install and use Tesseract-OCR
[Memo] How to use Google MµG
How to use .bash_profile and .bashrc
How to install and use Graphviz
How to use Google Test in C
How to search Google Drive with Google Colaboratory
python: How to use locals () and globals ()
Use TPU and Keras with Google Colaboratory
Basics of PyTorch (1) -How to use Tensor-
How to use Python zip and enumerate
How to use is and == in Python
[Blender x Python] How to use modifiers
How to use pandas Timestamp and date_range
How to install fabric and basic usage
How to use lists, tuples, dictionaries, and sets
A simple example of how to use ArgumentParser
Introducing Sinatra-style frameworks and how to use them
How to use the Google Cloud Translation API
[Algorithm x Python] How to use the list
[Python] How to use hash function and tuple.
How to install Cascade detector and how to use it
How to use Service Account OAuth and API with Google API Client for python
How to use xml.etree.ElementTree
How to use virtualenv
[Python] [Django] How to use ChoiceField and how to add options
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
I tried to implement and learn DCGAN with PyTorch
How to use Virtualenv
Beginners! Basic Linux commands and how to use them!
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use the grep command and frequent samples
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
Julia Quick Note [01] How to use variables and constants
[Python] How to split and modularize files (simple, example)
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use argparse and the difference between optparse
How to use list []
How to analyze with Google Colaboratory using Kaggle API
How to use Django on Google App Engine / Python
How to use python-kabusapi
How to use Decorator in Django and how to make it
How to use OptParse