Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
67fb7c0d
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
67fb7c0d
编写于
1月 31, 2019
作者:
S
SunGaofeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove redundant code in kinetics_reader in decode_mp4 and decode_pickle
上级
c39c6e22
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
29 deletion
+28
-29
fluid/PaddleCV/video/datareader/kinetics_reader.py
fluid/PaddleCV/video/datareader/kinetics_reader.py
+28
-29
未找到文件。
fluid/PaddleCV/video/datareader/kinetics_reader.py
浏览文件 @
67fb7c0d
...
...
@@ -135,33 +135,24 @@ def _reader_creator(pickle_list,
return
paddle
.
reader
.
xmap_readers
(
mapper
,
reader
,
num_threads
,
buf_size
)
def
decode_mp4
(
sample
,
mode
,
seg_num
,
seglen
,
short_size
,
target_size
,
img_
mean
,
img_
std
):
def
decode_mp4
(
sample
,
mode
,
seg_num
,
seglen
,
short_size
,
target_size
,
img_mean
,
img_std
):
sample
=
sample
[
0
].
split
(
' '
)
mp4_path
=
sample
[
0
]
# when infer, we store vid as label
label
=
int
(
sample
[
1
])
imgs
=
mp4_loader
(
mp4_path
,
seg_num
,
seglen
,
mode
)
imgs
=
group_scale
(
imgs
,
short_size
)
if
mode
==
'train'
:
imgs
=
group_random_crop
(
imgs
,
target_size
)
imgs
=
group_random_flip
(
imgs
)
else
:
imgs
=
group_center_crop
(
imgs
,
target_size
)
np_imgs
=
(
np
.
array
(
imgs
[
0
]).
astype
(
'float32'
).
transpose
(
(
2
,
0
,
1
))).
reshape
(
1
,
3
,
target_size
,
target_size
)
/
255
for
i
in
range
(
len
(
imgs
)
-
1
):
img
=
(
np
.
array
(
imgs
[
i
+
1
]).
astype
(
'float32'
).
transpose
(
(
2
,
0
,
1
))).
reshape
(
1
,
3
,
target_size
,
target_size
)
/
255
np_imgs
=
np
.
concatenate
((
np_imgs
,
img
))
imgs
=
np_imgs
imgs
-=
img_mean
imgs
/=
img_std
imgs
=
np
.
reshape
(
imgs
,
(
seg_num
,
seglen
*
3
,
target_size
,
target_size
))
try
:
imgs
=
mp4_loader
(
mp4_path
,
seg_num
,
seglen
,
mode
)
if
len
(
imgs
)
<
1
:
logger
.
error
(
'{} frame length {} less than 1.'
.
format
(
mp4_path
,
len
(
imgs
)))
return
None
,
None
except
:
logger
.
error
(
'Error when loading {}'
.
format
(
mp4_path
))
return
None
,
None
return
imgs
,
label
return
imgs_transform
(
imgs
,
label
,
mode
,
seg_num
,
seglen
,
\
short_size
,
target_size
,
img_mean
,
img_std
)
def
decode_pickle
(
sample
,
mode
,
seg_num
,
seglen
,
short_size
,
target_size
,
...
...
@@ -175,14 +166,25 @@ def decode_pickle(sample, mode, seg_num, seglen, short_size, target_size,
vid
,
label
,
frames
=
data_loaded
if
len
(
frames
)
<
1
:
logger
.
info
(
'{} frame length {} less than 1.'
.
format
(
pickle_path
,
len
(
frames
)))
r
ais
e
logger
.
error
(
'{} frame length {} less than 1.'
.
format
(
pickle_path
,
len
(
frames
)))
r
eturn
None
,
Non
e
except
:
logger
.
info
(
'Error when loading {}'
.
format
(
pickle_path
))
return
None
,
None
if
mode
==
'train'
or
mode
==
'valid'
or
mode
==
'test'
:
ret_label
=
label
elif
mode
==
'infer'
:
ret_label
=
vid
imgs
=
video_loader
(
frames
,
seg_num
,
seglen
,
mode
)
return
imgs_transform
(
imgs
,
ret_label
,
mode
,
seg_num
,
seglen
,
\
short_size
,
target_size
,
img_mean
,
img_std
)
def
imgs_transform
(
imgs
,
label
,
mode
,
seg_num
,
seglen
,
short_size
,
target_size
,
img_mean
,
img_std
):
imgs
=
group_scale
(
imgs
,
short_size
)
if
mode
==
'train'
:
...
...
@@ -202,10 +204,7 @@ def decode_pickle(sample, mode, seg_num, seglen, short_size, target_size,
imgs
/=
img_std
imgs
=
np
.
reshape
(
imgs
,
(
seg_num
,
seglen
*
3
,
target_size
,
target_size
))
if
mode
==
'train'
or
mode
==
'valid'
or
mode
==
'test'
:
return
imgs
,
label
elif
mode
==
'infer'
:
return
imgs
,
vid
return
imgs
,
label
def
group_random_crop
(
img_group
,
target_size
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录