Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
9f9817d3
M
models
项目概览
PaddlePaddle
/
models
大约 2 年 前同步成功
通知
232
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看板
未验证
提交
9f9817d3
编写于
9月 30, 2018
作者:
Q
Qiyang Min
提交者:
GitHub
9月 30, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1331 from CrossLee1/develop
support python3 in video classification
上级
f0050fd5
362dc1b3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
21 addition
and
18 deletion
+21
-18
fluid/video_classification/reader.py
fluid/video_classification/reader.py
+17
-15
fluid/video_classification/resnet.py
fluid/video_classification/resnet.py
+1
-1
fluid/video_classification/train.py
fluid/video_classification/train.py
+1
-1
fluid/video_classification/utility.py
fluid/video_classification/utility.py
+2
-1
未找到文件。
fluid/video_classification/reader.py
浏览文件 @
9f9817d3
import
os
import
os
import
sys
import
math
import
math
import
random
import
random
import
functools
import
functools
import
cPickle
try
:
from
cStringIO
import
StringIO
import
cPickle
as
pickle
from
cStringIO
import
StringIO
except
ImportError
:
import
pickle
from
io
import
BytesIO
import
numpy
as
np
import
numpy
as
np
import
paddle
import
paddle
from
PIL
import
Image
,
ImageEnhance
from
PIL
import
Image
,
ImageEnhance
random
.
seed
(
0
)
random
.
seed
(
0
)
DATA_DIM
=
224
THREAD
=
8
THREAD
=
8
BUF_SIZE
=
1024
BUF_SIZE
=
1024
...
@@ -22,17 +25,13 @@ INFER_LIST = 'data/test.list'
...
@@ -22,17 +25,13 @@ INFER_LIST = 'data/test.list'
img_mean
=
np
.
array
([
0.485
,
0.456
,
0.406
]).
reshape
((
3
,
1
,
1
))
img_mean
=
np
.
array
([
0.485
,
0.456
,
0.406
]).
reshape
((
3
,
1
,
1
))
img_std
=
np
.
array
([
0.229
,
0.224
,
0.225
]).
reshape
((
3
,
1
,
1
))
img_std
=
np
.
array
([
0.229
,
0.224
,
0.225
]).
reshape
((
3
,
1
,
1
))
python_ver
=
sys
.
version_info
def
imageloader
(
buf
):
def
imageloader
(
buf
):
if
isinstance
(
buf
,
str
):
if
isinstance
(
buf
,
str
):
tempbuff
=
StringIO
()
tempbuff
.
write
(
buf
)
tempbuff
.
seek
(
0
)
img
=
Image
.
open
(
tempbuff
)
elif
isinstance
(
buf
,
collections
.
Sequence
):
img
=
Image
.
open
(
StringIO
(
buf
[
-
1
]))
else
:
img
=
Image
.
open
(
StringIO
(
buf
))
img
=
Image
.
open
(
StringIO
(
buf
))
else
:
img
=
Image
.
open
(
BytesIO
(
buf
))
return
img
.
convert
(
'RGB'
)
return
img
.
convert
(
'RGB'
)
...
@@ -98,7 +97,7 @@ def group_center_crop(img_group, target_size):
...
@@ -98,7 +97,7 @@ def group_center_crop(img_group, target_size):
def
video_loader
(
frames
,
nsample
,
mode
):
def
video_loader
(
frames
,
nsample
,
mode
):
videolen
=
len
(
frames
)
videolen
=
len
(
frames
)
average_dur
=
videolen
/
nsample
average_dur
=
videolen
/
/
nsample
imgs
=
[]
imgs
=
[]
for
i
in
range
(
nsample
):
for
i
in
range
(
nsample
):
...
@@ -111,12 +110,12 @@ def video_loader(frames, nsample, mode):
...
@@ -111,12 +110,12 @@ def video_loader(frames, nsample, mode):
idx
=
i
idx
=
i
else
:
else
:
if
average_dur
>=
1
:
if
average_dur
>=
1
:
idx
=
(
average_dur
-
1
)
/
2
idx
=
(
average_dur
-
1
)
/
/
2
idx
+=
i
*
average_dur
idx
+=
i
*
average_dur
else
:
else
:
idx
=
i
idx
=
i
imgbuf
=
frames
[
i
dx
%
videolen
]
imgbuf
=
frames
[
i
nt
(
idx
%
videolen
)
]
img
=
imageloader
(
imgbuf
)
img
=
imageloader
(
imgbuf
)
imgs
.
append
(
img
)
imgs
.
append
(
img
)
...
@@ -125,7 +124,10 @@ def video_loader(frames, nsample, mode):
...
@@ -125,7 +124,10 @@ def video_loader(frames, nsample, mode):
def
decode_pickle
(
sample
,
mode
,
seg_num
,
short_size
,
target_size
):
def
decode_pickle
(
sample
,
mode
,
seg_num
,
short_size
,
target_size
):
pickle_path
=
sample
[
0
]
pickle_path
=
sample
[
0
]
data_loaded
=
cPickle
.
load
(
open
(
pickle_path
))
if
python_ver
<
(
3
,
0
):
data_loaded
=
pickle
.
load
(
open
(
pickle_path
,
'rb'
))
else
:
data_loaded
=
pickle
.
load
(
open
(
pickle_path
,
'rb'
),
encoding
=
'bytes'
)
vid
,
label
,
frames
=
data_loaded
vid
,
label
,
frames
=
data_loaded
imgs
=
video_loader
(
frames
,
seg_num
,
mode
)
imgs
=
video_loader
(
frames
,
seg_num
,
mode
)
...
...
fluid/video_classification/resnet.py
浏览文件 @
9f9817d3
...
@@ -22,7 +22,7 @@ class TSN_ResNet():
...
@@ -22,7 +22,7 @@ class TSN_ResNet():
num_filters
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
filter_size
,
filter_size
=
filter_size
,
stride
=
stride
,
stride
=
stride
,
padding
=
(
filter_size
-
1
)
/
2
,
padding
=
(
filter_size
-
1
)
/
/
2
,
groups
=
groups
,
groups
=
groups
,
act
=
None
,
act
=
None
,
bias_attr
=
False
)
bias_attr
=
False
)
...
...
fluid/video_classification/train.py
浏览文件 @
9f9817d3
...
@@ -91,7 +91,7 @@ def train(args):
...
@@ -91,7 +91,7 @@ def train(args):
fluid
.
io
.
load_vars
(
exe
,
pretrained_model
,
vars
=
vars
)
fluid
.
io
.
load_vars
(
exe
,
pretrained_model
,
vars
=
vars
)
# reader
# reader
train_reader
=
paddle
.
batch
(
reader
.
train
(
seg_num
),
batch_size
=
batch_size
)
train_reader
=
paddle
.
batch
(
reader
.
train
(
seg_num
),
batch_size
=
batch_size
,
drop_last
=
True
)
# test in single GPU
# test in single GPU
test_reader
=
paddle
.
batch
(
reader
.
test
(
seg_num
),
batch_size
=
batch_size
/
16
)
test_reader
=
paddle
.
batch
(
reader
.
test
(
seg_num
),
batch_size
=
batch_size
/
16
)
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
[
image
,
label
])
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
[
image
,
label
])
...
...
fluid/video_classification/utility.py
浏览文件 @
9f9817d3
...
@@ -17,6 +17,7 @@ from __future__ import division
...
@@ -17,6 +17,7 @@ from __future__ import division
from
__future__
import
print_function
from
__future__
import
print_function
import
distutils.util
import
distutils.util
import
numpy
as
np
import
numpy
as
np
import
six
from
paddle.fluid
import
core
from
paddle.fluid
import
core
...
@@ -36,7 +37,7 @@ def print_arguments(args):
...
@@ -36,7 +37,7 @@ def print_arguments(args):
:type args: argparse.Namespace
:type args: argparse.Namespace
"""
"""
print
(
"----------- Configuration Arguments -----------"
)
print
(
"----------- Configuration Arguments -----------"
)
for
arg
,
value
in
sorted
(
vars
(
args
).
iteritems
(
)):
for
arg
,
value
in
sorted
(
six
.
iteritems
(
vars
(
args
)
)):
print
(
"%s: %s"
%
(
arg
,
value
))
print
(
"%s: %s"
%
(
arg
,
value
))
print
(
"------------------------------------------------"
)
print
(
"------------------------------------------------"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录