博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
yolov5训练 SeaShip7000
阅读量:3722 次
发布时间:2019-05-22

本文共 2640 字,大约阅读时间需要 8 分钟。

1.数据集制作

1.1 转换格式

由于SeaShip数据集的格式不是标准的voc格式需要转换一下:

voc_seaship.py

import xml.etree.ElementTree as ETimport pickleimport osfrom os import listdir, getcwdfrom os.path import joinsets=[('SeaShip', 'train'), ('SeaShip', 'val')]classes = ["ore carrier", "general cargo ship", "bulk cargo carrier", "container ship", "fishing boat", "passenger ship"]def convert(size, box):    dw = 1./size[0]    dh = 1./size[1]    x = (box[0] + box[1])/2.0    y = (box[2] + box[3])/2.0    w = box[1] - box[0]    h = box[3] - box[2]    x = x*dw    w = w*dw    y = y*dh    h = h*dh    return (x,y,w,h)def convert_annotation(year, image_id):    in_file = open('Annotations/%s.xml'%(image_id))    out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w')    tree=ET.parse(in_file)    root = tree.getroot()    size = root.find('size')    w = int(size.find('width').text)    h = int(size.find('height').text)    for obj in root.iter('object'):        #difficult = obj.find('difficult').text        cls = obj.find('name').text        #if cls not in classes or int(difficult) == 1:        if cls not in classes:            continue        cls_id = classes.index(cls)        xmlbox = obj.find('bndbox')        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))        bb = convert((w,h), b)        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')wd = getcwd()for year, image_set in sets:    if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)):        os.makedirs('VOCdevkit/VOC%s/labels/'%(year))    image_ids = open('ImageSets/Main/%s.txt'%(image_set)).read().strip().split()    list_file = open('%s_%s.txt'%(year, image_set), 'w')    for image_id in image_ids:        list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id))        convert_annotation(year, image_id)    list_file.close()

目录结构:

.
├── Annotations
├── ImageSets
├── JPEGImages
├── SeaShip_train.txt
├── SeaShip_val.txt
├── VOCdevkit
└── voc_seaship.py

生成好后把label里面的.txt文件放进./VOCdevkit/VOCSeaShip/JPEGImages

里面这步很重要

1.2 环境搭建

e.g. 我用的是cuda10.1 和 pytorch 1.7

conda create -n yolov5 python=3.8

1.3 下载yolov5源码

官方网址:

cd yolov5

pip install -r requirements.txt

1.4修改yolov5配置文件

我们用yolov5s做测试因为这个速度最快:

1.4.1 制作自己的.yaml文件

复制 data/voc.yaml文件并改为自己的名字,只修改nc: 和names:

在这里插入图片描述

1.4.2 修改yolov5s.yaml文件

只需要修改model/yolov5s.yaml里面的nc:即可

2.开始训练

在yolov5的根目录下

python train.py --epochs 10 --cfg models/Shipyolov5s.yaml --data data/myshipvoc.yaml --weights yolov5s.pt --batch-size 32

测试

python detect.py --source data/images/ship-1.jpg --weights runs/train/exp14/weights/best.pt --conf 0.25

转载地址:http://ubbnn.baihongyu.com/

你可能感兴趣的文章
Vue 脚手架
查看>>
Element-UI 的基本使用
查看>>
01微信开发者工具文件介绍
查看>>
02模板语法wx:for
查看>>
03条件渲染wx:if
查看>>
04事件的绑定
查看>>
05常用组件
查看>>
06⼩程序⽣命周期
查看>>
vue脚手架搭建微信小程序
查看>>
在uni-app中使用sass
查看>>
4-2扩展操作码
查看>>
2.1进程与线程
查看>>
2.2定点数的表示与运算
查看>>
6.总线
查看>>
7.I/O系统
查看>>
2.2处理机调度
查看>>
2.3进程同步
查看>>
2.3浮点数的表示与运算
查看>>
2.4死锁
查看>>
2.4算术逻辑单元(ALU)
查看>>