Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
f8150efe
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
116
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f8150efe
编写于
5月 12, 2022
作者:
G
gaotingquan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: (h, w) -> (w, h)
上级
e4380ce5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
17 deletion
+12
-17
ppcls/data/dataloader/multi_scale_dataset.py
ppcls/data/dataloader/multi_scale_dataset.py
+2
-2
ppcls/data/dataloader/multi_scale_sampler.py
ppcls/data/dataloader/multi_scale_sampler.py
+6
-6
ppcls/data/preprocess/ops/operators.py
ppcls/data/preprocess/ops/operators.py
+4
-9
未找到文件。
ppcls/data/dataloader/multi_scale_dataset.py
浏览文件 @
f8150efe
...
...
@@ -72,11 +72,11 @@ class MultiScaleDataset(Dataset):
for
resize
in
resize_op
:
if
resize
in
op
:
if
self
.
has_crop_flag
:
logger
.
error
(
logger
.
warning
(
"Multi scale dataset will crop image according to the multi scale resolution"
)
self
.
transform_ops
[
i
][
resize
]
=
{
'size'
:
(
img_
height
,
img_width
)
'size'
:
(
img_
width
,
img_height
)
}
has_crop
=
True
self
.
has_crop_flag
=
0
...
...
ppcls/data/dataloader/multi_scale_sampler.py
浏览文件 @
f8150efe
...
...
@@ -64,11 +64,11 @@ class MultiScaleSampler(Sampler):
base_elements
=
base_im_w
*
base_im_h
*
base_batch_size
for
(
h
,
w
)
in
zip
(
height_dims
,
width_dims
):
batch_size
=
int
(
max
(
1
,
(
base_elements
/
(
h
*
w
))))
img_batch_pairs
.
append
((
h
,
w
,
batch_size
))
img_batch_pairs
.
append
((
w
,
h
,
batch_size
))
self
.
img_batch_pairs
=
img_batch_pairs
self
.
shuffle
=
True
else
:
self
.
img_batch_pairs
=
[(
base_im_
h
,
base_im_w
,
base_batch_size
)]
self
.
img_batch_pairs
=
[(
base_im_
w
,
base_im_h
,
base_batch_size
)]
self
.
img_indices
=
img_indices
self
.
n_samples_per_replica
=
num_samples_per_replica
...
...
@@ -81,7 +81,7 @@ class MultiScaleSampler(Sampler):
indices_rank_i
=
self
.
img_indices
[
self
.
rank
:
len
(
self
.
img_indices
):
self
.
num_replicas
]
while
self
.
current
<
self
.
n_samples_per_replica
:
curr_
h
,
curr_w
,
curr_bsz
=
random
.
choice
(
self
.
img_batch_pairs
)
curr_
w
,
curr_h
,
curr_bsz
=
random
.
choice
(
self
.
img_batch_pairs
)
end_index
=
min
(
self
.
current
+
curr_bsz
,
self
.
n_samples_per_replica
)
...
...
@@ -93,7 +93,7 @@ class MultiScaleSampler(Sampler):
self
.
current
+=
curr_bsz
if
len
(
batch_ids
)
>
0
:
batch
=
[
curr_
h
,
curr_w
,
len
(
batch_ids
)]
batch
=
[
curr_
w
,
curr_h
,
len
(
batch_ids
)]
self
.
batch_list
.
append
(
batch
)
self
.
length
=
len
(
self
.
batch_list
)
...
...
@@ -113,7 +113,7 @@ class MultiScaleSampler(Sampler):
start_index
=
0
for
batch_tuple
in
self
.
batch_list
:
curr_
h
,
curr_w
,
curr_bsz
=
batch_tuple
curr_
w
,
curr_h
,
curr_bsz
=
batch_tuple
end_index
=
min
(
start_index
+
curr_bsz
,
self
.
n_samples_per_replica
)
batch_ids
=
indices_rank_i
[
start_index
:
end_index
]
n_batch_samples
=
len
(
batch_ids
)
...
...
@@ -122,7 +122,7 @@ class MultiScaleSampler(Sampler):
start_index
+=
curr_bsz
if
len
(
batch_ids
)
>
0
:
batch
=
[(
curr_
h
,
curr_w
,
b_id
)
for
b_id
in
batch_ids
]
batch
=
[(
curr_
w
,
curr_h
,
b_id
)
for
b_id
in
batch_ids
]
yield
batch
def
set_epoch
(
self
,
epoch
:
int
):
...
...
ppcls/data/preprocess/ops/operators.py
浏览文件 @
f8150efe
...
...
@@ -50,22 +50,17 @@ class UnifiedResize(object):
}
def
_pil_resize
(
src
,
size
,
resample
):
# to be accordance with opencv, the input size is (h,w)
pil_img
=
Image
.
fromarray
(
src
)
pil_img
=
pil_img
.
resize
(
size
,
resample
)
return
np
.
asarray
(
pil_img
)
def
_cv2_resize
(
src
,
size
,
interpolation
):
cv_img
=
cv2
.
resize
(
src
,
size
[::
-
1
],
interpolation
)
return
cv_img
if
backend
.
lower
()
==
"cv2"
:
if
isinstance
(
interpolation
,
str
):
interpolation
=
_cv2_interp_from_str
[
interpolation
.
lower
()]
# compatible with opencv < version 4.4.0
elif
interpolation
is
None
:
interpolation
=
cv2
.
INTER_LINEAR
self
.
resize_func
=
partial
(
_cv2_
resize
,
interpolation
=
interpolation
)
self
.
resize_func
=
partial
(
cv2
.
resize
,
interpolation
=
interpolation
)
elif
backend
.
lower
()
==
"pil"
:
if
isinstance
(
interpolation
,
str
):
interpolation
=
_pil_interp_from_str
[
interpolation
.
lower
()]
...
...
@@ -128,8 +123,8 @@ class ResizeImage(object):
self
.
h
=
None
elif
size
is
not
None
:
self
.
resize_short
=
None
self
.
h
=
size
if
type
(
size
)
is
int
else
size
[
0
]
self
.
w
=
size
if
type
(
size
)
is
int
else
size
[
1
]
self
.
w
=
size
if
type
(
size
)
is
int
else
size
[
0
]
self
.
h
=
size
if
type
(
size
)
is
int
else
size
[
1
]
else
:
raise
OperatorParamError
(
"invalid params for ReisizeImage for '
\
'both 'size' and 'resize_short' are None"
)
...
...
@@ -146,7 +141,7 @@ class ResizeImage(object):
else
:
w
=
self
.
w
h
=
self
.
h
return
self
.
_resize_func
(
img
,
(
h
,
w
))
return
self
.
_resize_func
(
img
,
(
w
,
h
))
class
CropImage
(
object
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录