当前位置:网站首页>Ship detection in SAR image based on yolov5
Ship detection in SAR image based on yolov5
2022-07-28 06:27:00 【I have two candies】
List of articles
stay yolov5 Environment building After completion , You can train the model by yourself , This article focuses on the use of yolov5 Realization SAR Detection of ships in images .
1. Data set production
1.1 Download datasets
SSDD The data set can be in Baidu SkyDrive , Data set comparison , Don't wait too long
link :https://pan.baidu.com/s/1aXeDJ1-bd3-Wftgk4_7glg
Extraction code :2022
1.2 Dataset format
What we have on hand SSDD The data set format is as follows :
- SSDD
- Annotations
- 000001.xml
- 000002.xml
- ...
- JPEGImages
- 000001.JPG
- 000002.JPG
- ...
among ,Annotations Labels for all pictures , every last xml The tag file contains the target type , The location of the target ( The center position, width and height of the frame )
YOLOV5 Datasets in this format are not supported , We can modify the data set to COCO Format :
- ships
- images
- train (JPG images)
- 000341.JPG
- 000024.JPG
- ...
- test (JPG images)
- val (JPG images)
- labels
- train (txt files)
- 000341.txt
- 000024.txt
- ...
- test (txt files)
- val (txt files)
- ...
You can see , Data set containing /images and /labels,images in It contains three folders to store three types of data sets , Corresponding labels Three types of labels are also stored in , It is worth noting that ,labels Not in yes xml file , It is txt file , every last txt The contents of the document are as follows :
Format :<object-class> <x> <y> <width> <height>
0 0.41416 0.61538 0.31607 0.11242
1.3 format conversion
It's more difficult to deal with , I wrote a function , Can be placed with the original SSDD Folder in the same directory , Automatically generate corresponding after running COCO Data set in format ships_dataset, Code download address :
link :https://pan.baidu.com/s/1GMODNViP0WaquqJUyme_YA
Extraction code :2022
The effect after operation is as follows :
You can generate ships_dataset Throw it yolov5 In the table of contents , To be used later .
1.4 establish yaml file
stay yolov5 You can find it in the source code directory coco Data sets yaml file , It is used to describe the location of the data set and the number of sample types included :
The contents are as follows :
# YOLOv5 by Ultralytics, GPL-3.0 license
# COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Example usage: python train.py --data coco128.yaml
# parent
# ├── yolov5
# └── datasets
# └── coco128 ← downloads here (7 MB)
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128 # dataset root dir
train: images/train2017 # train images (relative to 'path') 128 images
val: images/train2017 # val images (relative to 'path') 128 images
test: # test images (optional)
# Classes
nc: 80 # number of classes
names: ['person', 'bicycle', 'car', ...] # class names
among ,path It points out the directory where the data set is stored ,train Point out the training set picture The position of ,val Indicates the validation set picture The position of ,test It's not necessary .
Corresponding , We created ships.yaml, The contents are as follows :
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./ships_dataset # dataset root dir
train: images/train # train images (relative to 'path') 128 images
val: images/val # val images (relative to 'path') 128 images
test: images/test # test images (optional)
# Classes
nc: 1 # number of classes
names: ['ship'] # class names
2. debugging
Use the following command to train the model :
python train.py --img 320 --batch-size 8 --epochs 10 --data data/ships.yaml --cfg models/yolov5s.yaml --weights yolov5s.pt --device 0
For parameter descriptions in the command, please refer to Official explanation and This blog , Notice here that we have just created yaml file ( These parameters can be found in train.py Set the default value in , You can also specify... In the command )
First training , Need to download some small files , The code automatically passes Github Download from the official website , It may be due to inaccessibility Github Report errors , Change code directly :
take yolov5/utils/downloads.py All in github.com Change to mirror URL hub.xn--p8jhe.tw
response = requests.get(f'https://hub.xn--p8jhe.tw/repos/
In this way, it can be executed normally , run 10 individual epoch Some ships can be detected , But the accuracy is not high ,100 epoches Can basically achieve 94% About the detection rate .
3. Optimize
Because it's still Xiaobai , There is no experience in adjusting parameters , At present, we first improve the accuracy through image enhancement , Reference resources Blog
stay yolov5\data\hyps You can see that there are many files related to super parameter settings , Create your own hyp.ships.yaml, Copy first hyp.scratch-low.yaml The whole content of , Value to modify the image enhancement part :
hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
hsv_s: 0.5 # image HSV-Saturation augmentation (fraction)
hsv_v: 0.3 # image HSV-Value augmentation (fraction)
degrees: 0 # image rotation (+/- deg)
translate: 0.1 # image translation (+/- fraction)
scale: 0.75 # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)
perspective: 0.003 # image perspective (+/- fraction), range 0-0.001
flipud: 0.4 # image flip up-down (probability)
fliplr: 0.5 # image flip left-right (probability)
mosaic: 1.0 # image mosaic (probability)
mixup: 0.0 # image mixup (probability)
copy_paste: 0.0 # segment copy-paste (probability)
After using image enhancement, you need to train.py Set the parameter value to
parser.add_argument('--hyp', type=str, default=ROOT / 'data/hyps/hyp.ships.yaml', help='hyperparameters path')
3. Training and results
After using image enhancement , Retraining 150 individual epoches( wait for 3 Hours ):
150 epochs completed in 3.510 hours.
Optimizer stripped from runs\train\exp40\weights\last.pt, 14.3MB
Optimizer stripped from runs\train\exp40\weights\best.pt, 14.3MB
Validating runs\train\exp40\weights\best.pt...
Fusing layers...
YOLOv5s summary: 213 layers, 7012822 parameters, 0 gradients, 15.8 GFLOPs
Class Images Labels P R [email protected] [email protected]:.95: 100%|██████████| 15/15 [00:04<0
all 232 578 0.95 0.865 0.947 0.526
Results saved to runs\train\exp40
Can be in yolov5/runs/train/exp40 View results :
You can also take the trained weight/best.pt File predictions ( Next, predict the pictures in all test sets ):
python detect.py --iou-thres 0.3 --weights ./runs/train/exp40/weights/best.pt --source ./ships_dataset/images/test --save-txt --save-crop
Can be in yolov5/runs/detect View results
边栏推荐
- AEM testpro K50 and south Guangdong survey
- clickhouse建宽表多少列最合适?
- 【服务器使用记录】通过跳板机登录远程服务器并进行文件传输
- 听说你也在实习|当我采访了几个大三实习生之后。
- mixup_ratio
- PyTorch 学习笔记 3 —— DATASETS & DATALOADERS & TRANSFORMS
- Efficient Net_V2
- (PHP graduation project) based on PHP student daily behavior management system access
- USB network native driver for esxi updated to support esxi7.0.1
- Install visual studio 2019 steps and vs2019 offline installation package on win7
猜你喜欢

Agilent Agilent e5071 test impedance and attenuation are normal, except crosstalk ng--- Repair plan

Detailed explanation of creepage distance and electrical clearance

DSX2-8000如何校准?校准流程?

Analysis of MOSFET damage at the moment of power failure of isolated power supply

听说你也在实习|当我采访了几个大三实习生之后。

Graduation thesis | how to write literature review

Led selection - hardware learning notes 3

An example of bill printing

Surge impact immunity experiment (surge) -emc series Hardware Design Notes 6

Ctfshow single dog -- Web
随机推荐
Cronbach’s α?KMO系数?因子载荷?史上最易懂的问卷信效度分析教程!!!(SPSS和AMOS)
An example of bill printing
(PHP graduation project) based on thinkphp5 community property management system
保研面试中常见的英语问题有哪些?
Led selection - hardware learning notes 3
权重衰减 weight decay
福禄克DSX2-5000 网络线缆测试仪为什么每年都要校准一次?
ConNeXt
EXFO 730c optical time domain reflectometer only has IOLm optical eye to upgrade OTDR (open OTDR permission)
Perl入门学习(九)引用
当mysql表从压缩表变成普通表会发生什么
论文神器 VS Code + LaTex + LaTex Workshop
ASP. Net read database bound to treeview recursive mode
Detailed explanation of creepage distance and electrical clearance
低功耗设计-isolation cell
When to replace jack socket for dsx-pc6 jumper module?
Fluke fluke aircheck WiFi tester cannot configure file--- Ultimate solution experience
Mae mask self encoding is scalable learning
(PHP graduation project) obtained based on thinkphp5 campus news release management system
set_ case_ analysis