Using Google Colab

features

advantage

1. Free use of Tesla T4 for 12 hours per day

Wed Mar  8 05:57:41 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.85.12    Driver Version: 525.85.12    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla T4            Off  | 00000000:00:04.0 Off |                    0 |
| N/A   67C    P0    31W /  70W |      0MiB / 15360MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

CPU configuration

Intel(R) Xeon(R) CPU @ 2.30GHz
cpu cores	: 1

insert image description here
2. The environment for deep learning is basically complete, and there is basically no need for additional configuration environments

3. You can mount Google cloud disk, which is convenient to keep code, data set and weight

shortcoming

1. It is easy to end the session, and the running results must be saved in time.
2. It is necessary to surf the Internet scientifically

Note

1. The files generated on colab are temporary. If we need to save them, we must download them locally in time. Right-click the file you want to download. 2. The
environment configuration in colab will become invalid when the colab notebook is closed.
3. In The python terminal runs the command, you need to add ! before the command

!pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
!pip install tensorboard
!pip install tensorboardX

4. Run the shell command in the bash terminal, you need to add the % sign before the command

%cd "/drive/MyDrive/xxx"

basic operation

1. Switch (specify) the current working directory

import os
os.chdir('drive/MyDrive/xxx')

2. Execute python code

!python main.py

3. Set timing click script

If you do not move colab for a long time, the connection may be disconnected, and the program will stop at this time. Although the model that has been trained is still saved, the training is still not complete, so set up a script that clicks on the page regularly:

  • Press F12 on the web page to enter the debugging page - console console
  • Enter the code below and press Enter
function ClickConnect(){
    
    
    console.log("Clicked on connect button"); 
    document.querySelector("paper-button").click()
}
setInterval(ClickConnect,60000) 

If you want to stop the script, refresh the browser, colab will not disconnect.

4. Shortcut keys

Run a part of a cell: Select the code, Ctrl+Shift+Enter
to collapse the running result Ctrl+M+O
to run the cell Crtl+Enter
to run the cell and add a code cell Shift+Enter

key step

Train your own model with colab:

  • Upload project code: upload your own project code to goole cloud disk
  • upload data
  • Mount google cloud disk: use authorization code to mount google cloud disk
  • Configure the project operating environment
  • Run the python file: Execute the python file with the command in ipynb

Upload project code

Method 1 (recommended for small projects, small upload files)

  • Create a new project folder in Google Cloud Disk
  • Click [New], click [Upload Folder], and select the corresponding folder
    insert image description here
    Method 2 (recommended for large projects, large upload files)
  • Create a new project folder in Google Cloud Disk
  • mount google cloud disk
  • Upload the local project code to github
  • Switch the working directory and switch to the newly created project folder
import os
os.chdir('drive/MyDrive/xxx')
  • In colab, git clone downloads the project code:
!git clone https://github.com/WZMIAOMIAO/deep-learning-for-image-processing.git

upload data

Upload the data set to the google cloud disk. It is recommended to upload the compressed package directly. The speed is fast, and you can directly decompress it in Colab later.

#解压文件
!unzip /PATH/TO/images.zip -d /PATH/TO

dependency management

Export the dependent packages required for the project to run

pip freeze > ./requirements.txt

Install the dependencies required for the project to run

pip install -r ./requirements.txt

Guess you like

Origin blog.csdn.net/m0_46692607/article/details/129407603