[PYTHON] Machine learning with Pytorch on Google Colab

Google Colab is amazing

Google Colab is amazing and seems to be easy to use GPU for free. I was taught how to use it on AWS, but it's an order of magnitude easier and I cry It ’s a story about doing machine learning with Pytorch.

merit

Demerit

In order to use it well, I will try it while looking at various Qiita and write down the method I made. Maybe there was a lot of old information and it was quite difficult

Install Pytorch on Colab & enable GPU

Runtime> Change Runtime Type> Select GPU

!pip install torch
import torch
torch.cuda.is_available()

If you execute True and get True, you can use the GPU It seems that Pytorch contains something called CUDA for using GPU and can be used (worst explanation)

I want to use a folder

There seems to be quite a way to use files.

① Upload from the side

② Enter some code and upload

from google.colab import files
uploaded = files.upload()

You can upload the file by entering

However, there are times when I want to use the entire dataset, so even if I can upload only the files, I'm in trouble. Is it possible to handle folders in this way?

③ Connect with Google Drive

This is good There are some difficult articles if you put in a lot of difficult code or if you don't want to authenticate, but I wonder if it has become convenient recently. It was really easy

First, click "Mount Drive" from> on the left side. Then the code below was added all the time

from google.colab import drive
drive.mount('/content/drive')

Just put it in, execute it, and copy something with the link that came out! / content / drive / My Drive / Untara If you write, it seems that you can treat it like a local folder, awesome ~ Thank you ~

Bonus: How to give an image

When I use colab to summarize things, I sometimes want to paste a reference image, but it is not connected to the local and there is no insertion. In such a case, first upload the image file from the side and name it Figure_1.png.

from IPython.display import Image,display_png
display_png(Image('Figure_1.png'))

If you execute, the image will not disappear even after a while, so it's good. There is a feeling of first aid

Recommended Posts

Machine learning with Pytorch on Google Colab
About learning with google colab
Machine learning Minesweeper with PyTorch
Play with Turtle on Google Colab
Deep Learning with Shogi AI on Mac and Google Colab
Deep Learning with Shogi AI on Mac and Google Colab Chapter 11
Deep Learning with Shogi AI on Mac and Google Colab Chapters 1-6
Deep Learning with Shogi AI on Mac and Google Colab Chapter 7
Deep Learning with Shogi AI on Mac and Google Colab Chapter 10 6-9
Deep Learning with Shogi AI on Mac and Google Colab Chapter 10
Deep Learning with Shogi AI on Mac and Google Colab Chapter 7 5-7
Deep Learning with Shogi AI on Mac and Google Colab Chapter 9
Deep Learning with Shogi AI on Mac and Google Colab Chapter 12 1-2
Deep Learning with Shogi AI on Mac and Google Colab Chapter 12 3
Deep Learning with Shogi AI on Mac and Google Colab Chapter 12 3 ~ 5
Deep Learning with Shogi AI on Mac and Google Colab Chapter 7 9
Deep Learning with Shogi AI on Mac and Google Colab Chapter 8 5-9
Deep Learning with Shogi AI on Mac and Google Colab Chapter 8 1-4
Deep Learning with Shogi AI on Mac and Google Colab Chapter 12 3
Deep Learning with Shogi AI on Mac and Google Colab Chapter 7 8
Deep Learning with Shogi AI on Mac and Google Colab Chapter 7 1-4
Learn with Shogi AI Deep Learning on Mac and Google Colab Use Google Colab
Deep Learning on Mac and Google Colab Words Learned with Shogi AI
Machine learning learned with Pokemon
Machine learning with Python! Preparation
Beginning with Python machine learning
Try machine learning with Kaggle
How to set up a Google Colab environment with Coursera's advanced machine learning courses
An error that stumbled upon learning YOLO on Google Colab
Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)
Feature Engineering for Machine Learning Beginning with Part 3 Google Colaboratory-Scaling
[PyTorch Tutorial ⑤] Learning PyTorch with Examples (Part 2)
I tried machine learning with liblinear
Machine learning with python (1) Overall classification
Try machine learning with scikit-learn SVM
[PyTorch Tutorial ⑤] Learning PyTorch with Examples (Part 1)
Quantum-inspired machine learning with tensor networks
Get started with machine learning with SageMaker
"Scraping & machine learning with Python" Learning memo
Machine Learning with docker (42) Programming PyTorch for Deep Learning By Ian Pointer
Machine learning
Use MeCab and neologd with Google Colab
Predict power demand with machine learning Part 2
Notes on PyQ machine learning python grammar
Amplify images for machine learning with python
Machine learning imbalanced data sklearn with k-NN
A story about machine learning with Kyasuket
[Shakyo] Encounter with Python for machine learning
Image segment using Oxford_iiit_pet on Google Colab
Verify coordinates on Google Map with Geocoder
Build AI / machine learning environment with Python
[Python] Easy introduction to machine learning with python (SVM)
[Super Introduction to Machine Learning] Learn Pytorch tutorials
Machine learning starting with Python Personal memorandum Part2
Detect app releases on the App Store
Play with Turtle on Google Colab
Feature Engineering for Machine Learning Beginning with Part 2 Google Colaboratory-Logarithmic Transformation and Box-Cox Transformation
Machine learning starting with Python Personal memorandum Part1
I tried running YOLO v3 on Google Colab
Notes on machine learning (updated from time to time)
[Python] Collect images with Icrawler for machine learning [1000 images]
Machine learning starting from scratch (machine learning learned with Kaggle)