当前位置:网站首页>(novice to) detailed tutorial on machine / in-depth learning with colab from scratch
(novice to) detailed tutorial on machine / in-depth learning with colab from scratch
2022-06-13 02:08:00 【liyihao76】
( Novice ) Use from scratch Colab Carry out the machine / In depth study of detailed tutorials
During the epidemic, you can only practice at home , Simple machine learning with a notebook can barely make do with it , In depth learning it takes days and nights to train a model at random . But if we use Google Colab Of GPU resources , Any computer can play deep learning !
What is? Colab
Quote the official introduction :
Colaboratory It's a free Jupyter Notebook environment , You don't need to make any settings to use , And run completely in the cloud .
With the help of Colaboratory, You can write and execute code 、 Save and share analysis results , And use powerful computing resources , All of these can be used for free through the browser .
Colab It's a server , We can apply for his resources to use . Choose to use colab The biggest advantage of deep learning is its powerful GPU/TPU resources , Network training for deep learning , For parallel computing gpu The speed is comparable cpu Much faster .
You can colab The following commands are used to view colab What can be provided to us GPU To configure :
! /opt/bin/nvidia-smi
This is all we can use for free GPU resources , If you can't meet your requirements, you can buy colab pro Or go to Taobao to rent a server .
How to use Colab
After all, it's a Google product , First you need a Google account , We should also be able to access the Internet scientifically .
Let's start with the simplest , First of all , How to create a Colab file .
Right click to create in your Google cloud docs , Pictured :
You can't find it when you use it for the first time , stay more -> Connect more applications Just search and add in the .
Now you have created a file , Let me talk about several ways to use it .
Colab Several ways to use
image Jupyter Notebook The use of
For us Anaconda Of Jupyter Notebook More familiar with , It is easy to add code and comments , And can display the operation results in time , Very suitable for teaching presentation . Here you can be like notebook The use of colab, Even their file formats are the same , Yours notebook Files can be sent directly to the Google cloud and used colab open .
Here's an example :
You can see the usage and notebook It's the same . Familiarity colab After the use of the simple calculation, I like to use colab To calculate , After all, old computers are slow to open any software , How about picking up some wool from Google .
How to use GPU Speed up
For deep learning, use GPU Words , We must adjust the settings first . Pictured :
stay Execute code program -> Change the runtime type ->GPU Only in this way can we use GPU Resources for our in-depth learning .
In exchange for GPU After resources , You can use the following code to test whether you are really connected GPU resources :
import tensorflow as tf
device_name = tf.test.gpu_device_name()
if device_name != '/device:GPU:0':
raise SystemError('GPU device not found')
print('Found GPU at: {}'.format(device_name))
If the output is Found GPU at: /device:GPU:0
It proves that you are connected successfully .
Here, if you can't use gpu If you accelerate, you'd better not choose , Because each account can be used every day GPU The acceleration time is limited , I used to use... For a while GPU, result colab It will be automatically disconnected for me in about twelve hours , When you want to connect again, you will be reminded that there is nothing left GPU resources , In this case, you can wait until the next day GPU Or create a new Google account and run .
Whether it's for use GPU Accelerate or not , There is an upper limit to how long the program can run , It's usually 24 Hours , But this is not a certain value , It will change at any time with the use of the server .
How to use Colab Run our program
We write our own programs or from GitHub How does a program that is copied on run normally ?
Linux The user can just press the command directly ,Colab It's the same thing .
mount Google Cloud disk
This is the first step in running our program , because Colab The operating principle of is actually to assign you a remote belt GPU The host , So its original path is not your Google cloud disk ( That is, your code file ) Path . So the first step is to mount the Google cloud disk to the remote host :
from google.colab import drive
drive.mount('/content/gdrive')
Click the link after running , Then copy code Just type in .
After connecting to the cloud disk , In fact, other operations are similar to Linux It doesn't make much difference .
Carry out orders
colab And notebook The difference is , Its code box can not only execute code , Can also execute commands .
For command statements , We need to add before `!
For example, some common commands :
import os
os.chdir("/content/gdrive/My Drive/3dunet/3DUnetCNN-master")
Jump to an address on your Google cloud disk
ls '/content/gdrive/My Drive/3dunet/3DUnetCNN-master'
View the contents under the path
%cd brats
Get into brasts Folder , Note that there cd Order to use % instead of !
!pip install nipype
or
! pip install git+https://github.com/qubvel/segmentation_models
Install the required libraries
!pip install tensorflow==1.15.0
Install a version of the library . Here's a little bit of attention , We are GitHub Many of the projects I saw were written some time ago , So I used tensorflow Version may be different from colab Its own version is different . We can use the following command to view the current colab Of tensorflow edition
import tensorflow as tf
tf.__version__
What I am showing is '2.2.0'
, And the project may try tensorflow It was written in a little version , At this time, you need to change the version through the above command , After changing the version , Programs often need to be rerun .
And a little bit more , at present 1.15.0 Version of tensorflow It's supporting GPU Running , Many earlier versions do not support GPU, So if you lower it to, say 1.5.0 edition , Can't use GPU Of .
! python train.py
perform train.py file
In fact, these are related to our linux The next operation is the same , But now it is put into the Google cloud disk to execute .
Project operation
How to run in github On other people's projects ?
First, you should transfer other people's projects and required data sets to your own Google cloud disk , Reuse colab perform .
Note that the free space of Google cloud disk is only 15G, If your data set is large , Be careful that some images may be generated during the execution process, resulting in space overload , That will give you an error . You can buy a member , Less than ten yuan 100G, I feel it is much easier to use than the speed limit of Baidu cloud .
1. Mount Google cloud , I said just now
from google.colab import drive
drive.mount('/content/gdrive')
2. Go to the project address to be processed
import os
os.chdir("/content/gdrive/My Drive/3dclassification/3DUnetCNN-master")
3. Install the required libraries
use pip
Command to install one by one , But most projects have requirements.txt file , You can directly
! pip install -r requirements.txt
Install all required libraries at once .
4. Execute project procedures
! python train.py
Training network
! python evaluate.py
Evaluate performance
Project preparation
colab Not suitable for writing large programs , After all, are notebook file . but notebook The benefit of is intuitive , It is convenient for us to observe the output and debug , If you want to write a project , Simple projects written in one file are easy to say , But if you want to call functions in other files , First of all notebook file (.ipynb) To py File recall .
Download directly in the file as py Just send the file to your Google cloud disk .
边栏推荐
- The first cell of devaxpress CXGRID after inserting a row is in focus editing status
- [printf function and scanf function] (learning note 5 -- standard i/o function)
- Leetcode 93 recovery IP address
- Ten thousand words make it clear that synchronized and reentrantlock implement locks in concurrency
- Sensorless / inductive manufacturing of brushless motor drive board based on stm32
- Rsync transport exclusion directory
- STM32 external interrupt Usage Summary
- Implementation of pointer linked list
- [the third day of actual combat of smart lock project based on stm32f401ret6 in 10 days] communication foundation and understanding serial port
- Calculation of accuracy, recall rate, F1 value and accuracy rate of pytorch prediction results (simple implementation)
猜你喜欢
Gome's ambition of "folding up" app
Mac使用Docker安装Oracle
Installing Oracle with docker for Mac
Decoding iFLYTEK open platform 2.0 is a fertile land for developers and a source of industrial innovation
【Unity】打包WebGL項目遇到的問題及解决記錄
华为设备配置虚拟专用网FRR
【Unity】打包WebGL项目遇到的问题及解决记录
[the second day of actual combat of smart lock project based on stm32f401ret6 in 10 days] GPIO and register
Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)
[the second day of the actual combat of the smart lock project based on stm32f401ret6 in 10 days] light up with the key ----- input and output of GPIO
随机推荐
Delphi 10.4.2 release instructions and installation methods of three patches
STM32 steering gear controller
STM32 sensorless brushless motor drive
Functional translation
Decompression and compression of chrome resource file Pak
SQLserver2008 拒绝了对对象 '****' (数据库 '****',架构 'dbo')的 SELECT 权限
C语言压缩字符串保存到二进制文件,从二进制文件读取压缩字符串后解压。
Opencv camera calibration (1): internal and external parameters, distortion coefficient calibration and 3D point to 2D image projection
一、搭建django自动化平台(实现一键执行sql)
如何解决通过new Date()获取时间写出数据库与当前时间相差8小时问题【亲测有效】
Basic exercise of test questions Yanghui triangle (two-dimensional array and shallow copy)
rsync 傳輸排除目錄
Répertoire d'exclusion du transport rsync
SQL server deletes all tables and all stored procedures in the database
华为设备配置私网IP路由FRR
Restful interface specification annotation of pringboot (2)
[the second day of actual combat of smart lock project based on stm32f401ret6 in 10 days] GPIO and register
Can't use typedef yet? C language typedef detailed usage summary, a solution to your confusion. (learning note 2 -- typedef setting alias)
Establishment of microservice development environment
记录:如何解决MultipartFile类的transferTo()上传图片报“系统找不到指定的路径“问题【亲测有效】