This is the 18th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

The environment

  • google colab
  • YOLOv5

What is colab

Colab is a Google Jupyter Notebook tool that supports Google Drive, TensorFlow and other Google buckets. Colab is mainly used for machine learning development and research. Colab’s greatest benefit is that it provides AI developers with free GPU resources on which they can easily run deep learning frameworks like TensorFlow, PyTorch, keras, etc.

YOLOv5 model training

Go to Google Drive and click New in the upper left

Create a new folder colab

Next, upload the prepared mask data set to the colab folder. This data set, which we used in the YOLOv5 model training, can be downloaded from the following address

The original link public. Roboflow. Ai/object – dete…

CSDN download download.csdn.net/download/dj…

Baidu cloud pan.baidu.com/s/15GSPiJ59… , extract code: WJA4

To create colab, click New > More > Google Colaboratory

After creating the Notebook, go to Modify > Notebook Settings to set GPU acceleration

Hardware Accelerator, select GPU, save

Click on the connection in the upper right corner and select Connect to managed code executor

After the GPU environment is set up, we can view the GPU resources provided by Colab in the notebook. Use! Nvidia – smi command

As you can see, the hardware provided by Google is a Tesla P100 with 16 GIGABytes of video memory. However, it seems that the GPU allocated by Colab is different each time. Sometimes it is P100, sometimes it is T4, which is sufficient for most applications

Let’s look at the pyTorch installation and execute

import torch
torch.__version__
Copy the code

As you can see, the platform is installed by default, version 1.6, CUDA version 10.1

If you need to install third-party libraries, you can install them directly in a cell, such as! pip3 install torchvision

Next, mount Google Drive so that you can use the resources in Google Drive in Colab

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

path = "/content/drive/My Drive"

os.chdir(path)
os.listdir(path)
Copy the code

Executing the code in the above cells requires an input captcha

Google Drive will then be mounted to the/Content/Drive directory, and you can perform subsequent operations on files in Google Drive

With all the preparation done, we can download the source code for YOLOv5 and execute it in a cell

! git clone https://github.com/ultralytics/yolov5.gitCopy the code

And then switch to the Google drive, modify yolov5 / models/yolov5s yaml, the original nc: 80 to nc: 2

You can then go to Colab, go to the yolov5 directory, and execute the training command in the cell

! python train.py --data .. /mask/data.yaml --cfg models/yolov5s.yaml --weights '' --batch-size 64Copy the code

During training, there was an error in the Pyyaml module. This is due to the low version of Pyyaml, which can be resolved by upgrading

pip install -U pyyaml
Copy the code

Continue training

Done!

The resources

  • Github.com/ultralytics…
  • Xugaoxiang.com/2020/07/02/…
  • Xugaoxiang.com/2020/06/17/…