Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
11a5b1b3
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看板
提交
11a5b1b3
编写于
1月 15, 2020
作者:
S
shippingwang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix name scope
上级
30351c6c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
32 deletion
+21
-32
dygraph/tsm/eval.py
dygraph/tsm/eval.py
+19
-30
dygraph/tsm/train.py
dygraph/tsm/train.py
+2
-2
未找到文件。
dygraph/tsm/eval.py
浏览文件 @
11a5b1b3
...
...
@@ -22,15 +22,9 @@ import numpy as np
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph.base
import
to_variable
from
utils.train_utils
import
train_with_pyreader
#import models.TSM.TSM_ResNet as TSM_ResNet
#from models import TSM as TSM
from
tsm_res_model
import
TSM_ResNet
#import TSM
from
utils.config_utils
import
*
from
reader
import
get_reader
from
metrics
import
get_metrics
from
utils.utility
import
check_cuda
from
model
import
TSM_ResNet
from
config_utils
import
*
from
reader
import
KineticsReader
logging
.
root
.
handlers
=
[]
FORMAT
=
'[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s'
...
...
@@ -39,16 +33,13 @@ logger = logging.getLogger(__name__)
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
"Paddle Video t
rain
script"
)
parser
=
argparse
.
ArgumentParser
(
"Paddle Video t
est
script"
)
parser
.
add_argument
(
'--model_name'
,
type
=
str
,
default
=
'AttentionCluster'
,
help
=
'name of model to train.'
)
'--model_name'
,
type
=
str
,
default
=
'TSM'
,
help
=
'name of model to train.'
)
parser
.
add_argument
(
'--config'
,
type
=
str
,
default
=
'
configs/attention_cluster.txt
'
,
default
=
'
tsm.yaml
'
,
help
=
'path to config file of model'
)
parser
.
add_argument
(
'--batch_size'
,
...
...
@@ -61,10 +52,7 @@ def parse_args():
default
=
True
,
help
=
'default use gpu.'
)
parser
.
add_argument
(
'--weights'
,
type
=
str
,
default
=
"./final"
,
help
=
"weight path"
)
'--weights'
,
type
=
str
,
default
=
"./final"
,
help
=
"weight path"
)
parser
.
add_argument
(
'--log_interval'
,
type
=
int
,
...
...
@@ -83,15 +71,13 @@ def test(args):
place
=
fluid
.
CUDAPlace
(
0
)
with
fluid
.
dygraph
.
guard
(
place
):
video_model
=
TSM_ResNet
(
'TSM'
,
layers
=
test_config
.
MODEL
.
num_layers
,
class_dim
=
test_config
.
MODEL
.
num_classes
,
seg_num
=
test_config
.
MODEL
.
seg_num
)
video_model
=
TSM_ResNet
(
"TSM"
,
test_config
)
model_dict
,
_
=
fluid
.
load_dygraph
(
args
.
weights
)
video_model
.
set_dict
(
model_dict
)
test_reader
=
get_reader
(
args
.
model_name
.
upper
(),
'test'
,
test_config
)
test_reader
=
KineticsReader
(
name
=
"tsm"
,
mode
=
'test'
,
cfg
=
test_config
)
test_reader
=
test_reader
.
create_reader
()
video_model
.
eval
()
total_loss
=
0.0
...
...
@@ -102,12 +88,13 @@ def test(args):
for
batch_id
,
data
in
enumerate
(
test_reader
()):
x_data
=
np
.
array
([
item
[
0
]
for
item
in
data
])
y_data
=
np
.
array
([
item
[
1
]
for
item
in
data
]).
reshape
([
-
1
,
1
])
imgs
=
to_variable
(
x_data
)
labels
=
to_variable
(
y_data
)
labels
.
stop_gradient
=
True
outputs
=
video_model
(
imgs
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
outputs
,
label
=
labels
,
ignore_index
=-
1
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
outputs
,
label
=
labels
,
ignore_index
=-
1
)
avg_loss
=
fluid
.
layers
.
mean
(
loss
)
...
...
@@ -117,13 +104,15 @@ def test(args):
total_acc1
+=
acc_top1
.
numpy
()
total_acc5
+=
acc_top5
.
numpy
()
total_sample
+=
1
print
(
'TEST iter {}, loss = {}, acc1 {}, acc5 {}'
.
format
(
batch_id
,
avg_loss
.
numpy
(),
acc_top1
.
numpy
(),
acc_top5
.
numpy
()))
print
(
'Finish loss {}, acc1 {}, acc5 {}'
.
format
(
total_loss
/
total_sample
,
total_acc1
/
total_sample
,
total_acc5
/
total_sample
))
print
(
'TEST iter {}, loss = {}, acc1 {}, acc5 {}'
.
format
(
batch_id
,
avg_loss
.
numpy
(),
acc_top1
.
numpy
(),
acc_top5
.
numpy
()))
print
(
'Finish loss {}, acc1 {}, acc5 {}'
.
format
(
total_loss
/
total_sample
,
total_acc1
/
total_sample
,
total_acc5
/
total_sample
))
if
__name__
==
"__main__"
:
args
=
parse_args
()
# check whether the installed paddle is compiled with GPU
check_cuda
(
args
.
use_gpu
)
logger
.
info
(
args
)
test
(
args
)
dygraph/tsm/train.py
浏览文件 @
11a5b1b3
...
...
@@ -39,7 +39,7 @@ def parse_args():
parser
.
add_argument
(
'--config'
,
type
=
str
,
default
=
'
configs/attention_cluster.txt
'
,
default
=
'
tsm.yaml
'
,
help
=
'path to config file of model'
)
parser
.
add_argument
(
'--batch_size'
,
...
...
@@ -167,7 +167,7 @@ def train(args):
if
use_data_parallel
:
strategy
=
fluid
.
dygraph
.
parallel
.
prepare_context
()
video_model
=
TSM_ResNet
(
""
,
train_config
)
video_model
=
TSM_ResNet
(
"
TSM
"
,
train_config
)
optimizer
=
create_optimizer
(
train_config
.
TRAIN
)
if
use_data_parallel
:
video_model
=
fluid
.
dygraph
.
parallel
.
DataParallel
(
video_model
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录