当前位置:网站首页>Yolov5 code reproduction and server operation
Yolov5 code reproduction and server operation
2022-07-02 15:24:00 【Shallow thoughts 52】
List of articles
Preface
Mentioned in the previous article , There are two ways of target detection , One is one_stage( Single stage ) Such as YOLO One is two_stage( Two stage ) Such as Faster_Rcnn,Mask_Rcnn. As I mentioned earlier Faster_Rcnn, This article mainly introduces YOLOV5 Code reproduction process , And the modification of the configuration file .
One 、YOLO brief introduction
YOLO It is a network framework for target detection , The detection speed is very fast , Suitable for some real-time detection ,YOLO Now after several generations of versions , It's now V5 edition ,V5 Provides 5l,5m,5s,5x Several versions , This article uses 5s Model of .
Two 、 The code download
You can download to Baidu online disk by yourself , Link attached :
link : Baidu SkyDrive
Extraction code :qnn5
3、 ... and 、 Data set preparation
In the last article , It introduces xml turn txt Code process of document , You can check it by yourself , Link attached :
Code
After the transformation , It can also be divided into training set and test set 
images Place the file
labels place txt file
What we should pay attention to here is , The folder name must be images Follow labels, The original code is as follows :
def img2label_paths(img_paths):
# Define label paths as a function of image paths
sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings
return [sb.join(x.rsplit(sa, 1)).rsplit('.', 1)[0] + '.txt' for x in img_paths]
Four 、 Modification of configuration file
1.data Under the yaml

modify data Under directory VOCyaml file ,
Before the change :
path: ../datasets/VOC
train: # train images (relative to 'path') 16551 images
- images/train2012
- images/train2007
- images/val2012
- images/val2007
val: # val images (relative to 'path') 4952 images
- images/test2007
test: # test images (optional)
- images/test2007
After modification
train: # train images (relative to 'path') 16551 images
- /mnt/wu/images/train
val: # val images (relative to 'path') 4952 images
- /mnt/wu/images/val
Modify the data path here 
Before the change :
nc: 20 # number of classes
names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] # class names
After modification :
nc: 4 # number of classes
names: ["Traffic_Light_go","Traffic_Light_stop","Traffic_Light_warning",'Traffic_Light_ambiguous'] # class names
Change here nc Follow the label
nc: It indicates how many categories of data you train .
2.models Under the yaml

What we use here is 5s Model of , change yolov5s.yaml file 
It just needs to be changed nc Sure , How many categories of data represent your training .
3. Training train

- change YOLOV5s The path of the model
parser.add_argument('--weights', type=str, default=ROOT / 'yolov5s.pt', help='initial weights path')
2. Change the above modification models Of yaml File path
parser.add_argument('--cfg', type=str, default='models/traffic.yaml', help='model.yaml path')
3. Change the above modification data Of yaml File path
parser.add_argument('--data', type=str, default=ROOT / 'data/traffic.yaml', help='dataset.yaml path')
4. Training batch
parser.add_argument('--epochs', type=int, default=50)
5. Batch size ,batch_size If there is insufficient video memory during training, it can be reduced batch_size Size
parser.add_argument('--batch-size', type=int, default=64, help='total batch size for all GPUs, -1 for autobatch')
5、 ... and 、 Training with server
image YOLO This depth frame , It's best to train with a server , Bloggers use moment pool cloud , Link attached Quechi cloud
Attach invitation code :BQlYmrQhDiex1lZ
1. Upload data
Before renting a server , Upload data first , If the data is large , Uploading after renting a server will waste time , It costs money .
Enter my online disk , Upload data .
2. Rent servers
Choose the model of the graphics card here , Rent .
Environmental choice yolov5 Environmental Science , Omit the link of matching the environment .
3.pycharm Connect to server
After renting , Enter the rental interface , Display the details of the leased server .
Use here ssh Connect .
1. add to ssh

According to the ssh link , Input host , user name , port .
2. Input password

3. Configure the server environment path and code mapping path

Open the link , Access terminal .
Input conda env list View the environment path 
Configure the environment path , Code mapping path
mnt The path below is your own network disk path .
As shown in the figure , Configuration complete .
4. Decompress data
Open the terminal ,cd To the compressed data set directory ,unzip file name unpack , As shown in the figure below :

5. Start training
Wait for the code to be uploaded to the server , Follow the server dataset path , modify data Below yaml Data set path in file , You can train .
As shown in the figure below : It is to train with a server .

As shown in the figure , Start training .

End of training .
Under this path is the weight file generated by training .

best.ph Is the best weight file .
last.ph It is the weight file of the last training .
6. Download the file locally
We can go through winscp This software , A good folder for training , Download to local
1. Enter host name , Port number , user name , password , Connect to server 
As shown in the figure , Successful connection 
2. Find the folder , Download to local .
6、 ... and 、 test
We can test according to the trained weight .
Test code detect.py
Weight file path
parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'runs/train/exp6/weights/best.pt', help='model path(s)')
The test image , Video path ,0 Indicates that the camera is turned on .
parser.add_argument('--source', type=str, default="traffic.mp4", help='file/dir/URL/glob, 0 for webcam')
After setting, you can test .


Testing is completed , The save path... Will be displayed .
Open folder , See the effect .
summary
That's all YOLOV5 The whole process of Server Replication , Everyone is in the process of reproduction , Problems encountered , You can feed back to the comment area .
边栏推荐
- How to avoid 7 common problems in mobile and network availability testing
- kibana 基础操作
- Application and practice of Jenkins pipeline
- Key points of compilation principle examination in 2021-2022 academic year [overseas Chinese University]
- Leetcode - Search 2D matrix
- Tidb environment and system configuration check
- 【C语言】详解指针的初阶和进阶以及注意点(1)
- TiDB混合部署拓扑
- Application of CDN in game field
- Implementation of n queen in C language
猜你喜欢

编译原理课程实践——实现一个初等函数运算语言的解释器或编译器

【C语言】详解指针的初阶和进阶以及注意点(1)

19_ Redis_ Manually configure the host after downtime

Have you learned the wrong usage of foreach

06_ Stack and queue conversion

03_ Linear table_ Linked list

.NET Core 日志系统

百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香

The past and present lives of visual page building tools

飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
随机推荐
03_ Linear table_ Linked list
TiDB混合部署拓扑
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
Solve the problem that El radio group cannot be edited after echo
Application of CDN in game field
05_ queue
Printf function and scanf function in C language
PHP method to get the index value of the array item with the largest key value in the array
实用调试技巧
TiDB跨数据中心部署拓扑
Practical debugging skills
MFC timer usage
Base64 coding can be understood this way
解决el-radio-group 回显后不能编辑问题
2021-2022学年编译原理考试重点[华侨大学]
. Net core logging system
Real estate market trend outlook in 2022
Case introduction and problem analysis of microservice
语义分割学习笔记(一)
N皇后问题的解决