Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
17dbe2b1
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
17dbe2b1
编写于
9月 14, 2020
作者:
K
Kaipeng Deng
提交者:
GitHub
9月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #93 from heavengate/update_tsm
update TSM use new APIS
上级
931564e5
2d72ad22
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
26 deletion
+22
-26
tsm/infer.py
tsm/infer.py
+5
-7
tsm/main.py
tsm/main.py
+7
-15
tsm/modeling.py
tsm/modeling.py
+10
-4
未找到文件。
tsm/infer.py
浏览文件 @
17dbe2b1
...
...
@@ -19,8 +19,8 @@ import os
import
argparse
import
numpy
as
np
from
paddle.incubate.hapi.model
import
Input
,
set_devic
e
from
paddle.
incubate.hapi.
vision.transforms
import
Compose
import
paddl
e
from
paddle.vision.transforms
import
Compose
from
check
import
check_gpu
,
check_version
from
modeling
import
tsm_resnet50
...
...
@@ -33,8 +33,8 @@ logger = logging.getLogger(__name__)
def
main
():
device
=
set_device
(
FLAGS
.
device
)
fluid
.
enable_dygraph
(
device
)
if
FLAGS
.
dynamic
else
None
device
=
paddle
.
set_device
(
FLAGS
.
device
)
paddle
.
disable_static
(
device
)
if
FLAGS
.
dynamic
else
None
transform
=
Compose
([
GroupScale
(),
GroupCenterCrop
(),
NormalizeImage
()])
dataset
=
KineticsDataset
(
...
...
@@ -47,9 +47,7 @@ def main():
model
=
tsm_resnet50
(
num_classes
=
len
(
labels
),
pretrained
=
FLAGS
.
weights
is
None
)
inputs
=
[
Input
([
None
,
8
,
3
,
224
,
224
],
'float32'
,
name
=
'image'
)]
model
.
prepare
(
inputs
=
inputs
,
device
=
FLAGS
.
device
)
model
.
prepare
()
if
FLAGS
.
weights
is
not
None
:
model
.
load
(
FLAGS
.
weights
,
reset_optimizer
=
True
)
...
...
tsm/main.py
浏览文件 @
17dbe2b1
...
...
@@ -19,13 +19,11 @@ import os
import
argparse
import
numpy
as
np
import
paddle
from
paddle
import
fluid
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.incubate.hapi.model
import
Model
,
Input
,
set_device
from
paddle.incubate.hapi.loss
import
CrossEntropy
from
paddle.incubate.hapi.metrics
import
Accuracy
from
paddle.incubate.hapi.vision.transforms
import
Compose
from
paddle.vision.transforms
import
Compose
from
modeling
import
tsm_resnet50
from
check
import
check_gpu
,
check_version
...
...
@@ -50,8 +48,8 @@ def make_optimizer(step_per_epoch, parameter_list=None):
def
main
():
device
=
set_device
(
FLAGS
.
device
)
fluid
.
enable_dygraph
(
device
)
if
FLAGS
.
dynamic
else
None
device
=
paddle
.
set_device
(
FLAGS
.
device
)
paddle
.
disable_static
(
device
)
if
FLAGS
.
dynamic
else
None
train_transform
=
Compose
([
GroupScale
(),
GroupMultiScaleCrop
(),
GroupRandomCrop
(),
...
...
@@ -79,16 +77,10 @@ def main():
/
ParallelEnv
().
nranks
)
optim
=
make_optimizer
(
step_per_epoch
,
model
.
parameters
())
inputs
=
[
Input
([
None
,
8
,
3
,
224
,
224
],
'float32'
,
name
=
'image'
)]
labels
=
[
Input
([
None
,
1
],
'int64'
,
name
=
'label'
)]
model
.
prepare
(
optim
,
CrossEntropy
(),
metrics
=
Accuracy
(
topk
=
(
1
,
5
)),
inputs
=
inputs
,
labels
=
labels
,
device
=
FLAGS
.
device
)
optimizer
=
optim
,
loss
=
paddle
.
nn
.
CrossEntropyLoss
(),
metrics
=
paddle
.
metric
.
Accuracy
(
topk
=
(
1
,
5
)))
if
FLAGS
.
eval_only
:
if
FLAGS
.
weights
is
not
None
:
...
...
tsm/modeling.py
浏览文件 @
17dbe2b1
...
...
@@ -13,12 +13,13 @@
#limitations under the License.
import
math
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
BatchNorm
,
Linear
from
paddle.
incubate.hapi.model
import
Model
from
paddle.
incubate.hapi
.download
import
get_weights_path_from_url
from
paddle.
static
import
InputSpec
from
paddle.
utils
.download
import
get_weights_path_from_url
__all__
=
[
"TSM_ResNet"
,
"tsm_resnet50"
]
...
...
@@ -112,7 +113,7 @@ class BottleneckBlock(fluid.dygraph.Layer):
return
y
class
TSM_ResNet
(
Model
):
class
TSM_ResNet
(
fluid
.
dygraph
.
Layer
):
"""
TSM network with ResNet as backbone
...
...
@@ -193,7 +194,10 @@ class TSM_ResNet(Model):
def
_tsm_resnet
(
num_layers
,
seg_num
=
8
,
num_classes
=
400
,
pretrained
=
True
):
model
=
TSM_ResNet
(
num_layers
,
seg_num
,
num_classes
)
inputs
=
[
InputSpec
([
None
,
8
,
3
,
224
,
224
],
'float32'
,
name
=
'image'
)]
labels
=
[
InputSpec
([
None
,
1
],
'int64'
,
name
=
'label'
)]
net
=
TSM_ResNet
(
num_layers
,
seg_num
,
num_classes
)
model
=
paddle
.
Model
(
net
,
inputs
,
labels
)
if
pretrained
:
assert
num_layers
in
pretrain_infos
.
keys
(),
\
"TSM-ResNet{} do not have pretrained weights now, "
\
...
...
@@ -201,6 +205,8 @@ def _tsm_resnet(num_layers, seg_num=8, num_classes=400, pretrained=True):
weight_path
=
get_weights_path_from_url
(
*
(
pretrain_infos
[
num_layers
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
# weight_dict, _ = fluid.load_dygraph(weight_path)
# model.set_dict(weight_dict)
model
.
load
(
weight_path
)
return
model
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录