Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小毕学习代码
yolov7-obb
提交
66cc7347
Y
yolov7-obb
项目概览
小毕学习代码
/
yolov7-obb
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yolov7-obb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
66cc7347
编写于
1月 31, 2023
作者:
E
Egrt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改数据加载为obb
上级
6b5ec0ad
变更
6
展开全部
显示空白变更内容
内联
并排
Showing
6 changed file
with
1053 addition
and
1147 deletion
+1053
-1147
2007_train.txt
2007_train.txt
+939
-939
2007_val.txt
2007_val.txt
+105
-105
nets/yolo_training.py
nets/yolo_training.py
+3
-3
train.py
train.py
+1
-1
utils/dataloader.py
utils/dataloader.py
+4
-98
voc_annotation.py
voc_annotation.py
+1
-1
未找到文件。
2007_train.txt
浏览文件 @
66cc7347
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
2007_val.txt
浏览文件 @
66cc7347
此差异已折叠。
点击以展开。
nets/yolo_training.py
浏览文件 @
66cc7347
...
@@ -137,7 +137,7 @@ class YOLOLoss(nn.Module):
...
@@ -137,7 +137,7 @@ class YOLOLoss(nn.Module):
#-------------------------------------------#
#-------------------------------------------#
xy
=
prediction_pos
[:,
:
2
].
sigmoid
()
*
2.
-
0.5
xy
=
prediction_pos
[:,
:
2
].
sigmoid
()
*
2.
-
0.5
wh
=
(
prediction_pos
[:,
2
:
4
].
sigmoid
()
*
2
)
**
2
*
anchors
[
i
]
wh
=
(
prediction_pos
[:,
2
:
4
].
sigmoid
()
*
2
)
**
2
*
anchors
[
i
]
angle
=
(
prediction_pos
[:,
4
:
5
].
sigmoid
()
-
0.5
)
*
torc
h
.
pi
angle
=
(
prediction_pos
[:,
4
:
5
].
sigmoid
()
-
0.5
)
*
mat
h
.
pi
box_theta
=
torch
.
cat
((
xy
,
wh
,
angle
),
1
)
box_theta
=
torch
.
cat
((
xy
,
wh
,
angle
),
1
)
#-------------------------------------------#
#-------------------------------------------#
# 对真实框进行处理,映射到特征层上
# 对真实框进行处理,映射到特征层上
...
@@ -150,7 +150,7 @@ class YOLOLoss(nn.Module):
...
@@ -150,7 +150,7 @@ class YOLOLoss(nn.Module):
# 计算预测框和真实框的回归损失
# 计算预测框和真实框的回归损失
#-------------------------------------------#
#-------------------------------------------#
kldloss
=
self
.
kldbbox
(
box_theta
,
selected_tbox_theta
)
kldloss
=
self
.
kldbbox
(
box_theta
,
selected_tbox_theta
)
loss
+=
kldloss
.
mean
()
box_loss
+=
kldloss
.
mean
()
#-------------------------------------------#
#-------------------------------------------#
# 根据预测结果的iou获得置信度损失的gt
# 根据预测结果的iou获得置信度损失的gt
#-------------------------------------------#
#-------------------------------------------#
...
@@ -299,7 +299,7 @@ class YOLOLoss(nn.Module):
...
@@ -299,7 +299,7 @@ class YOLOLoss(nn.Module):
grid
=
torch
.
stack
([
gi
,
gj
],
dim
=
1
).
type_as
(
fg_pred
)
grid
=
torch
.
stack
([
gi
,
gj
],
dim
=
1
).
type_as
(
fg_pred
)
pxy
=
(
fg_pred
[:,
:
2
].
sigmoid
()
*
2.
-
0.5
+
grid
)
*
self
.
stride
[
i
]
pxy
=
(
fg_pred
[:,
:
2
].
sigmoid
()
*
2.
-
0.5
+
grid
)
*
self
.
stride
[
i
]
pwh
=
(
fg_pred
[:,
2
:
4
].
sigmoid
()
*
2
)
**
2
*
anch
[
i
][
idx
]
*
self
.
stride
[
i
]
pwh
=
(
fg_pred
[:,
2
:
4
].
sigmoid
()
*
2
)
**
2
*
anch
[
i
][
idx
]
*
self
.
stride
[
i
]
pangle
=
(
fg_pred
[:,
4
:
5
].
sigmoid
()
-
0.5
)
*
torc
h
.
pi
pangle
=
(
fg_pred
[:,
4
:
5
].
sigmoid
()
-
0.5
)
*
mat
h
.
pi
pxywh
=
torch
.
cat
([
pxy
,
pwh
,
pangle
],
dim
=-
1
)
pxywh
=
torch
.
cat
([
pxy
,
pwh
,
pangle
],
dim
=-
1
)
pxyxys
.
append
(
pxywh
)
pxyxys
.
append
(
pxywh
)
...
...
train.py
浏览文件 @
66cc7347
...
@@ -41,7 +41,7 @@ if __name__ == "__main__":
...
@@ -41,7 +41,7 @@ if __name__ == "__main__":
# Cuda 是否使用Cuda
# Cuda 是否使用Cuda
# 没有GPU可以设置成False
# 没有GPU可以设置成False
#---------------------------------#
#---------------------------------#
Cuda
=
Fals
e
Cuda
=
Tru
e
#---------------------------------------------------------------------#
#---------------------------------------------------------------------#
# distributed 用于指定是否使用单机多卡分布式运行
# distributed 用于指定是否使用单机多卡分布式运行
# 终端指令仅支持Ubuntu。CUDA_VISIBLE_DEVICES用于在Ubuntu下指定显卡。
# 终端指令仅支持Ubuntu。CUDA_VISIBLE_DEVICES用于在Ubuntu下指定显卡。
...
...
utils/dataloader.py
浏览文件 @
66cc7347
...
@@ -74,8 +74,8 @@ class YoloDataset(Dataset):
...
@@ -74,8 +74,8 @@ class YoloDataset(Dataset):
# 序号为4的部分,为真实框的旋转角度
# 序号为4的部分,为真实框的旋转角度
# 序号为5的部分,为真实框的种类
# 序号为5的部分,为真实框的种类
#---------------------------------------------------#
#---------------------------------------------------#
box
[:,
2
:
4
]
=
box
[:,
2
:
4
]
-
box
[:,
0
:
2
]
#
box[:, 2:4] = box[:, 2:4] - box[:, 0:2]
box
[:,
0
:
2
]
=
box
[:,
0
:
2
]
+
box
[:,
2
:
4
]
/
2
#
box[:, 0:2] = box[:, 0:2] + box[:, 2:4] / 2
#---------------------------------------------------#
#---------------------------------------------------#
# 调整顺序,符合训练的格式
# 调整顺序,符合训练的格式
...
@@ -105,102 +105,8 @@ class YoloDataset(Dataset):
...
@@ -105,102 +105,8 @@ class YoloDataset(Dataset):
# 获得预测框
# 获得预测框
#------------------------------#
#------------------------------#
box
=
np
.
array
([
np
.
array
(
list
(
map
(
int
,
box
.
split
(
','
))))
for
box
in
line
[
1
:]])
box
=
np
.
array
([
np
.
array
(
list
(
map
(
int
,
box
.
split
(
','
))))
for
box
in
line
[
1
:]])
image
=
image
.
resize
((
w
,
h
),
Image
.
BICUBIC
)
if
not
random
:
image_data
=
np
.
array
(
image
,
np
.
float32
)
scale
=
min
(
w
/
iw
,
h
/
ih
)
nw
=
int
(
iw
*
scale
)
nh
=
int
(
ih
*
scale
)
dx
=
(
w
-
nw
)
//
2
dy
=
(
h
-
nh
)
//
2
#---------------------------------#
# 将图像多余的部分加上灰条
#---------------------------------#
image
=
image
.
resize
((
nw
,
nh
),
Image
.
BICUBIC
)
new_image
=
Image
.
new
(
'RGB'
,
(
w
,
h
),
(
128
,
128
,
128
))
new_image
.
paste
(
image
,
(
dx
,
dy
))
image_data
=
np
.
array
(
new_image
,
np
.
float32
)
#---------------------------------#
# 对真实框进行调整
#---------------------------------#
if
len
(
box
)
>
0
:
np
.
random
.
shuffle
(
box
)
box
[:,
[
0
,
2
]]
=
box
[:,
[
0
,
2
]]
*
nw
/
iw
+
dx
box
[:,
[
1
,
3
]]
=
box
[:,
[
1
,
3
]]
*
nh
/
ih
+
dy
box
[:,
0
:
2
][
box
[:,
0
:
2
]
<
0
]
=
0
box
[:,
2
][
box
[:,
2
]
>
w
]
=
w
box
[:,
3
][
box
[:,
3
]
>
h
]
=
h
box_w
=
box
[:,
2
]
-
box
[:,
0
]
box_h
=
box
[:,
3
]
-
box
[:,
1
]
box
=
box
[
np
.
logical_and
(
box_w
>
1
,
box_h
>
1
)]
# discard invalid box
return
image_data
,
box
#------------------------------------------#
# 对图像进行缩放并且进行长和宽的扭曲
#------------------------------------------#
new_ar
=
iw
/
ih
*
self
.
rand
(
1
-
jitter
,
1
+
jitter
)
/
self
.
rand
(
1
-
jitter
,
1
+
jitter
)
scale
=
self
.
rand
(.
25
,
2
)
if
new_ar
<
1
:
nh
=
int
(
scale
*
h
)
nw
=
int
(
nh
*
new_ar
)
else
:
nw
=
int
(
scale
*
w
)
nh
=
int
(
nw
/
new_ar
)
image
=
image
.
resize
((
nw
,
nh
),
Image
.
BICUBIC
)
#------------------------------------------#
# 将图像多余的部分加上灰条
#------------------------------------------#
dx
=
int
(
self
.
rand
(
0
,
w
-
nw
))
dy
=
int
(
self
.
rand
(
0
,
h
-
nh
))
new_image
=
Image
.
new
(
'RGB'
,
(
w
,
h
),
(
128
,
128
,
128
))
new_image
.
paste
(
image
,
(
dx
,
dy
))
image
=
new_image
#------------------------------------------#
# 翻转图像
#------------------------------------------#
flip
=
self
.
rand
()
<
.
5
if
flip
:
image
=
image
.
transpose
(
Image
.
FLIP_LEFT_RIGHT
)
image_data
=
np
.
array
(
image
,
np
.
uint8
)
#---------------------------------#
# 对图像进行色域变换
# 计算色域变换的参数
#---------------------------------#
r
=
np
.
random
.
uniform
(
-
1
,
1
,
3
)
*
[
hue
,
sat
,
val
]
+
1
#---------------------------------#
# 将图像转到HSV上
#---------------------------------#
hue
,
sat
,
val
=
cv2
.
split
(
cv2
.
cvtColor
(
image_data
,
cv2
.
COLOR_RGB2HSV
))
dtype
=
image_data
.
dtype
#---------------------------------#
# 应用变换
#---------------------------------#
x
=
np
.
arange
(
0
,
256
,
dtype
=
r
.
dtype
)
lut_hue
=
((
x
*
r
[
0
])
%
180
).
astype
(
dtype
)
lut_sat
=
np
.
clip
(
x
*
r
[
1
],
0
,
255
).
astype
(
dtype
)
lut_val
=
np
.
clip
(
x
*
r
[
2
],
0
,
255
).
astype
(
dtype
)
image_data
=
cv2
.
merge
((
cv2
.
LUT
(
hue
,
lut_hue
),
cv2
.
LUT
(
sat
,
lut_sat
),
cv2
.
LUT
(
val
,
lut_val
)))
image_data
=
cv2
.
cvtColor
(
image_data
,
cv2
.
COLOR_HSV2RGB
)
#---------------------------------#
# 对真实框进行调整
#---------------------------------#
if
len
(
box
)
>
0
:
np
.
random
.
shuffle
(
box
)
box
[:,
[
0
,
2
]]
=
box
[:,
[
0
,
2
]]
*
nw
/
iw
+
dx
box
[:,
[
1
,
3
]]
=
box
[:,
[
1
,
3
]]
*
nh
/
ih
+
dy
if
flip
:
box
[:,
[
0
,
2
]]
=
w
-
box
[:,
[
2
,
0
]]
box
[:,
0
:
2
][
box
[:,
0
:
2
]
<
0
]
=
0
box
[:,
2
][
box
[:,
2
]
>
w
]
=
w
box
[:,
3
][
box
[:,
3
]
>
h
]
=
h
box_w
=
box
[:,
2
]
-
box
[:,
0
]
box_h
=
box
[:,
3
]
-
box
[:,
1
]
box
=
box
[
np
.
logical_and
(
box_w
>
1
,
box_h
>
1
)]
return
image_data
,
box
return
image_data
,
box
...
...
voc_annotation.py
浏览文件 @
66cc7347
...
@@ -56,7 +56,7 @@ def convert_annotation(year, image_id, list_file):
...
@@ -56,7 +56,7 @@ def convert_annotation(year, image_id, list_file):
continue
continue
cls_id
=
classes
.
index
(
cls
)
cls_id
=
classes
.
index
(
cls
)
xmlbox
=
obj
.
find
(
'rotated_bndbox'
)
xmlbox
=
obj
.
find
(
'rotated_bndbox'
)
b
=
(
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_cx'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_cy'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_w'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_h'
).
text
)),
float
(
xmlbox
.
find
(
'rotated_bbox_theta'
).
text
))
b
=
(
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_cx'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_cy'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_w'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_h'
).
text
)),
int
(
float
(
xmlbox
.
find
(
'rotated_bbox_theta'
).
text
)
))
list_file
.
write
(
" "
+
","
.
join
([
str
(
a
)
for
a
in
b
])
+
','
+
str
(
cls_id
))
list_file
.
write
(
" "
+
","
.
join
([
str
(
a
)
for
a
in
b
])
+
','
+
str
(
cls_id
))
nums
[
classes
.
index
(
cls
)]
=
nums
[
classes
.
index
(
cls
)]
+
1
nums
[
classes
.
index
(
cls
)]
=
nums
[
classes
.
index
(
cls
)]
+
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录