没有合适的资源?快使用搜索试试~ 我知道了~
【小白CV】手把手教你用YOLOv5训练自己的数据集(从Windows环境配置到模型部署)_梁瑛平的博客-CSDN博客.pdf
需积分: 0 300 下载量 119 浏览量
2021-12-02
17:12:38
上传
评论 7
收藏 6.47MB PDF 举报
温馨提示
试读
2页
【小白CV】手把手教你用YOLOv5训练自己的数据集(从Windows环境配置到模型部署)_梁瑛平的博客-CSDN博客.pdf
资源推荐
资源详情
资源评论
【⼩⽩CV】⼿把⼿教你⽤YOLOv5训练⾃⼰的数据集(从Windows环境配置
到模型部署)
BIT可达鸭
20688
收藏 395
分类专栏:
深度学习-计算机视觉
⽂章标签: python
深度学习
⽬标检测
图像处理
计算机视觉
2020-12-04 18:43:39 版权
【⼩⽩CV】⼿把⼿教你⽤YOLOv5训练⾃⼰的数据集(从环境配置到模型部署)
本⽂禁⽌转载
前⾔:
1. 安装Anaconda:
2. 创建虚拟环境:
3. 安装pytorch:
4. 下载源码和安装依赖库:
5. 数据标注:
5. 数据预处理:
6. 下载预训练模型:
7. 开始训练:
关注我的公众号:
本⽂禁⽌转载
前⾔:
今天有时间,就写⼀下⽤yolov5训练⾃⼰数据集的博客吧。
1. 安装Anaconda:
Anaconda官⽹:https://www.anaconda.com/
下载完成后打开⼀路Yes即可,只需要注意这⾥要将conda添加到PATH:
安装完成后打开cmd:
输⼊conda -V,查看是否安装成功:
出现版本号即为安装成功。
2. 创建虚拟环境:
这⾥我们需要为yolov5单独创建⼀个环境,输⼊:
选y:
等待相关库安装:
安装完成后,输⼊:
激活环境:
3. 安装pytorch:
yolov5最新版本需要pytorch1.6版本以上,因此我们安装pytorch1.7版本。由于我事先安装好了CUDA10.1,因此在环境中输⼊:
即可安装:
然后查看CUDA是否可⽤:
这⾥显示True表明正常安装。
4. 下载源码和安装依赖库:
源码地址:https://github.com/ultralytics/yolov5
下载后解压,在⽬录内打开cmd并激活环境:
安装依赖库:
5. 数据标注:
数据标注我们要⽤labelimg,使⽤pip即可安装:
这⾥我⽤百度爬⾍爬取图像:
代码:
cmd输⼊labelimg打开标注软件:
打开后选取图像所在⽂件夹,进⾏标注:
标注完成后,每张图像会⽣成对应的xml标注⽂件:
深度学习-模型压缩(
…
68篇
深度学习-计算机视觉
124篇
基于深度学习的脑电
…
14篇
强化学习
2篇
数字图像处理
6篇
图计算系统/图神经⽹络
8篇
⽬录
【⼩⽩CV】⼿把⼿教你⽤YOLOv5训练
…
本⽂禁⽌转载
前⾔:
1. 安装Anaconda:
2. 创建虚拟环境:
3. 安装pytorch:
4. 下载源码和安装依赖库:
5. 数据标注:
5. 数据预处理:
6. 下载预训练模型:
7. 开始训练:
关注我的公众号:
分类专栏
深度学习-计算机视觉
专栏收录该内容
124 篇⽂章64 订阅
¥99.00
¥29.90
会员免费订 9折续费
conda create -n torch107 python=3.7
1
activate torch107
1
pip install torch==1.7.0+cu101 torchvision==0.8.1+cu101 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
1
pip install -r requirements.txt
1
pip install labelimg
1
import os
import re
import sys
import urllib
import json
import socket
import urllib.request
import urllib.parse
import urllib.error
#
设置超时
from random import randint
import time
timeout = 5
socket.setdefaulttimeout(timeout)
class Crawler:
#
睡眠时⻓
__time_sleep = 0.1
__amount = 0
__start_amount = 0
__counter = 0
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
__per_page = 30
#
获取图⽚
url
内容等
# t
下载图⽚时间间隔
def __init__(self, t=0.1):
self.time_sleep = t
#
获取后缀名
@staticmethod
def get_suffix(name):
m = re.search(r'\.[^\.]*$', name)
if m.group(0) and len(m.group(0)) <= 5:
return m.group(0)
else:
return '.jpeg'
#
保存图⽚
def save_image(self, rsp_data, word):
if not os.path.exists("./" + word):
os.mkdir("./" + word)
#
判断名字是否重复,获取图⽚⻓度
self.__counter = len(os.listdir('./' + word)) + 1
for image_info in rsp_data['data']:
try:
if 'replaceUrl' not in image_info or len(image_info['replaceUrl']) < 1:
continue
obj_url = image_info['replaceUrl'][0]['ObjUrl']
thumb_url = image_info['thumbURL']
url = 'https://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=%s&thumburl=%s'
urllib.parse.quote(obj_url), urllib.parse.quote(thumb_url))
time.sleep(self.time_sleep)
suffix = self.get_suffix(obj_url)
#
指定
UA
和
referrer
,减少
403
opener = urllib.request.build_opener()
opener.addheaders = [
('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
]
urllib.request.install_opener(opener)
#
保存图⽚
filepath = './{}/PME_{}_A{}'.format(word, randint(
1000000, 500000000), str(self.__counter) + str(suffix))
for _ in range(5):
urllib.request.urlretrieve(url, filepath)
if os.path.getsize(filepath) >= 5:
break
if os.path.getsize(filepath) < 5:
print("下载到了空⽂件,跳过!")
os.unlink(filepath)
continue
except urllib.error.HTTPError as urllib_err:
print(urllib_err)
continue
except Exception as err:
time.sleep(1)
print(err)
print("产⽣未知错误,放弃保存")
continue
else:
print("图+1,已有" + str(self.__counter) + "张图")
self.__counter += 1
return
#
开始获取
def get_images(self, word):
search = urllib.parse.quote(word)
# pn int
图⽚数
pn = self.__start_amount
while pn < self.__amount:
url = 'https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%s&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=©right=&word=%s&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&expermode=&force=&pn=%s&rn=%d&gsm=1e&1594447993172='
search, search, str(pn), self.__per_page)
#
设置
header
防
403
try:
time.sleep(self.time_sleep)
req = urllib.request.Request(url=url, headers=self.headers)
page = urllib.request.urlopen(req)
rsp = page.read()
except UnicodeDecodeError as e:
print(e)
print('-----UnicodeDecodeErrorurl:', url)
except urllib.error.URLError as e:
print(e)
print("-----urlErrorurl:", url)
except socket.timeout as e:
print(e)
print("-----socket timout:", url)
else:
#
解析
json
try:
rsp_data = json.loads(rsp)
self.save_image(rsp_data, word)
#
读取下⼀⻚
print("下载下⼀⻚")
pn += 60
except Exception as e:
continue
finally:
page.close()
print("下载任务结束")
return
def start(self, word, total_page=2, start_page=1, per_page=30):
"""
爬⾍⼊⼝
:param word: 抓取的关键词
:param total_page: 需要抓取数据⻚数 总抓取图⽚数量为 ⻚数 x per_page
:param start_page:起始⻚码
:param per_page: 每⻚数量
:return:
"""
self.__per_page = per_page
self.__start_amount = (start_page - 1) * self.__per_page
self.__amount = total_page * self.__per_page + self.__start_amount
self.get_images(word)
if __name__ == '__main__':
crawler = Crawler(0.05) #
抓取延迟为
0.05
crawler.start('玩⼿机')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
博客 专栏课程 下载 问答 社区 插件 认证
⽬标检测
搜索
会员中⼼ 收藏 动态 消息
创作
资源评论
叫我胡胡
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 软件工程项目验收系列文档.doc
- content_1713513663833.xmind
- 数据流图(Data Flow Diagram,简称DFD).md
- 基于Mybatis-Plus的Maven代码生成插件设计源码
- 67e1bc92-b0ee-45c1-b46f-9d519bbd6925.ofd
- npcsvpwm.v
- Java项目:基于Springboot+vue实现的校园志愿者管理系统(源码+数据库+环境配置和运行指导视频+系统讲解视频)
- 驱动开发,驱动加载工具,支持安装、启动、停止、卸载、关闭功能
- UTS 32146 Data Visualisation and Visual Analytics A1
- 西门子1200PLC 六部十层电梯程序案例,WINCC RT Advanced界面,博图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功