Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
功夫布鲁斯
classification
提交
69c60ce6
classification
项目概览
功夫布鲁斯
/
classification
与 Fork 源项目一致
Fork自
DataBall / classification
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
classification
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
69c60ce6
编写于
3月 08, 2021
作者:
DataBall
🚴🏻
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update data iter
上级
71513104
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
18 deletion
+23
-18
data_iter/datasets.py
data_iter/datasets.py
+23
-18
未找到文件。
data_iter/datasets.py
浏览文件 @
69c60ce6
...
...
@@ -97,7 +97,7 @@ def M_rotate_image(image , angle , cx , cy):
return
cv2
.
warpAffine
(
image
,
M
,
(
nW
,
nH
))
,
M
class
LoadImagesAndLabels
(
Dataset
):
# for training/testing
def
__init__
(
self
,
path
,
img_size
=
(
224
,
224
),
flag_agu
=
False
,
fix_res
=
True
,
val_split
=
[]):
def
__init__
(
self
,
path
,
img_size
=
(
224
,
224
),
flag_agu
=
False
,
fix_res
=
True
,
val_split
=
[]
,
have_label_file
=
False
):
print
(
'img_size (height,width) : '
,
img_size
[
0
],
img_size
[
1
])
labels_
=
[]
files_
=
[]
...
...
@@ -117,6 +117,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
self
.
img_size
=
img_size
self
.
flag_agu
=
flag_agu
self
.
fix_res
=
fix_res
self
.
have_label_file
=
have_label_file
def
__len__
(
self
):
return
len
(
self
.
files
)
...
...
@@ -129,22 +130,23 @@ class LoadImagesAndLabels(Dataset): # for training/testing
img
=
cv2
.
imread
(
img_path
)
# BGR
#--------------------------------------------
xml_
=
img_path
.
replace
(
".jpg"
,
".xml"
)
if
self
.
have_label_file
:
xml_
=
img_path
.
replace
(
".jpg"
,
".xml"
)
list_x
=
get_xml_msg
(
xml_
)
# 获取 xml 文件 的 object
list_x
=
get_xml_msg
(
xml_
)
# 获取 xml 文件 的 object
# 绘制 bbox
choose_idx
=
random
.
randint
(
0
,
int
(
len
(
list_x
)
-
1
))
for
j
in
range
(
len
(
list_x
)):
if
j
==
choose_idx
:
_
,
bbox_
=
list_x
[
j
]
x1
,
y1
,
x2
,
y2
=
bbox_
x1
=
int
(
np
.
clip
(
x1
,
0
,
img
.
shape
[
1
]
-
1
))
y1
=
int
(
np
.
clip
(
y1
,
0
,
img
.
shape
[
0
]
-
1
))
x2
=
int
(
np
.
clip
(
x2
,
0
,
img
.
shape
[
1
]
-
1
))
y2
=
int
(
np
.
clip
(
y2
,
0
,
img
.
shape
[
0
]
-
1
))
img
=
img
[
y1
:
y2
,
x1
:
x2
,:]
break
# 绘制 bbox
choose_idx
=
random
.
randint
(
0
,
int
(
len
(
list_x
)
-
1
))
for
j
in
range
(
len
(
list_x
)):
if
j
==
choose_idx
:
_
,
bbox_
=
list_x
[
j
]
x1
,
y1
,
x2
,
y2
=
bbox_
x1
=
int
(
np
.
clip
(
x1
,
0
,
img
.
shape
[
1
]
-
1
))
y1
=
int
(
np
.
clip
(
y1
,
0
,
img
.
shape
[
0
]
-
1
))
x2
=
int
(
np
.
clip
(
x2
,
0
,
img
.
shape
[
1
]
-
1
))
y2
=
int
(
np
.
clip
(
y2
,
0
,
img
.
shape
[
0
]
-
1
))
img
=
img
[
y1
:
y2
,
x1
:
x2
,:]
break
...
...
@@ -158,9 +160,12 @@ class LoadImagesAndLabels(Dataset): # for training/testing
if
self
.
flag_agu
==
True
and
random
.
random
()
>
0.6
:
cx
=
int
(
img
.
shape
[
1
]
/
2
)
cy
=
int
(
img
.
shape
[
0
]
/
2
)
angle
=
random
.
randint
(
-
45
,
45
)
offset_x
=
random
.
randint
(
-
3
,
3
)
offset_y
=
random
.
randint
(
-
3
,
3
)
# 手势(gesture)分类建议是全角度旋转, 对于 Stanford dogs 数据集适当角度旋转扰动,目的是为了符合真实样本旋转角度样本分布情况。
angle
=
random
.
randint
(
-
180
,
180
)
range_limit_x
=
int
(
min
(
6
,
img
.
shape
[
1
]
/
16
))
range_limit_y
=
int
(
min
(
6
,
img
.
shape
[
0
]
/
16
))
offset_x
=
random
.
randint
(
-
range_limit_x
,
range_limit_x
)
offset_y
=
random
.
randint
(
-
range_limit_y
,
range_limit_y
)
if
not
(
angle
==
0
and
offset_x
==
0
and
offset_y
==
0
):
img
,
_
=
M_rotate_image
(
img
,
angle
,
cx
+
offset_x
,
cy
+
offset_y
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录