Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
4643cad7
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看板
提交
4643cad7
编写于
4月 14, 2020
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update BMN
上级
d8541eac
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
55 addition
and
19 deletion
+55
-19
examples/bmn/eval.py
examples/bmn/eval.py
+6
-6
examples/bmn/predict.py
examples/bmn/predict.py
+6
-6
examples/bmn/reader.py
examples/bmn/reader.py
+1
-1
examples/bmn/train.py
examples/bmn/train.py
+2
-2
hapi/vision/models/__init__.py
hapi/vision/models/__init__.py
+3
-3
hapi/vision/models/bmn_model.py
hapi/vision/models/bmn_model.py
+37
-1
未找到文件。
examples/bmn/eval.py
浏览文件 @
4643cad7
...
...
@@ -19,7 +19,7 @@ import logging
import
paddle.fluid
as
fluid
from
hapi.model
import
set_device
,
Input
from
hapi.vision.models
import
BMN
,
BmnLoss
from
hapi.vision.models
import
bmn
,
BmnLoss
from
bmn_metric
import
BmnMetric
from
reader
import
BmnDataset
from
config_utils
import
*
...
...
@@ -53,7 +53,7 @@ def parse_args():
parser
.
add_argument
(
'--weights'
,
type
=
str
,
default
=
"checkpoint/final"
,
default
=
None
,
help
=
'weight path, None to automatically download weights provided by Paddle.'
)
parser
.
add_argument
(
...
...
@@ -97,7 +97,7 @@ def test_bmn(args):
eval_dataset
=
BmnDataset
(
eval_cfg
,
'test'
)
#model
model
=
BMN
(
config
,
args
.
dynamic
)
model
=
bmn
(
config
,
args
.
dynamic
,
pretrained
=
args
.
weights
is
None
)
model
.
prepare
(
loss_function
=
BmnLoss
(
config
),
metrics
=
BmnMetric
(
...
...
@@ -107,11 +107,11 @@ def test_bmn(args):
device
=
device
)
#load checkpoint
if
args
.
weights
:
if
args
.
weights
is
not
None
:
assert
os
.
path
.
exists
(
args
.
weights
+
'.pdparams'
),
\
"Given weight dir {} not exist."
.
format
(
args
.
weights
)
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
model
.
load
(
args
.
weights
)
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
model
.
load
(
args
.
weights
)
model
.
evaluate
(
eval_data
=
eval_dataset
,
...
...
examples/bmn/predict.py
浏览文件 @
4643cad7
...
...
@@ -19,7 +19,7 @@ import logging
import
paddle.fluid
as
fluid
from
hapi.model
import
set_device
,
Input
from
hapi.vision.models
import
BMN
,
BmnLoss
from
hapi.vision.models
import
bmn
,
BmnLoss
from
bmn_metric
import
BmnMetric
from
reader
import
BmnDataset
from
config_utils
import
*
...
...
@@ -50,7 +50,7 @@ def parse_args():
parser
.
add_argument
(
'--weights'
,
type
=
str
,
default
=
"checkpoint/final"
,
default
=
None
,
help
=
'weight path, None to automatically download weights provided by Paddle.'
)
parser
.
add_argument
(
...
...
@@ -92,7 +92,7 @@ def infer_bmn(args):
#data
infer_dataset
=
BmnDataset
(
infer_cfg
,
'infer'
)
model
=
BMN
(
config
,
args
.
dynamic
)
model
=
bmn
(
config
,
args
.
dynamic
,
pretrained
=
args
.
weights
is
None
)
model
.
prepare
(
metrics
=
BmnMetric
(
config
,
mode
=
'infer'
),
...
...
@@ -101,12 +101,12 @@ def infer_bmn(args):
device
=
device
)
# load checkpoint
if
args
.
weights
:
if
args
.
weights
is
not
None
:
assert
os
.
path
.
exists
(
args
.
weights
+
".pdparams"
),
"Given weight dir {} not exist."
.
format
(
args
.
weights
)
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
model
.
load
(
args
.
weights
)
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
model
.
load
(
args
.
weights
)
# here use model.eval instead of model.test, as post process is required in our case
model
.
evaluate
(
...
...
examples/bmn/reader.py
浏览文件 @
4643cad7
...
...
@@ -21,7 +21,7 @@ import sys
sys
.
path
.
append
(
'../'
)
from
distributed
import
DistributedBatchSampler
from
hapi.
distributed
import
DistributedBatchSampler
from
paddle.io
import
Dataset
,
DataLoader
logger
=
logging
.
getLogger
(
__name__
)
...
...
examples/bmn/train.py
浏览文件 @
4643cad7
...
...
@@ -19,7 +19,7 @@ import sys
import
os
from
hapi.model
import
set_device
,
Input
from
hapi.vision.models
import
BMN
,
BmnLoss
from
hapi.vision.models
import
bmn
,
BmnLoss
from
reader
import
BmnDataset
from
config_utils
import
*
...
...
@@ -136,7 +136,7 @@ def train_bmn(args):
val_dataset
=
BmnDataset
(
val_cfg
,
'valid'
)
# model
model
=
BMN
(
config
,
args
.
dynamic
)
model
=
bmn
(
config
,
args
.
dynamic
,
pretrained
=
False
)
optim
=
optimizer
(
config
,
parameter_list
=
model
.
parameters
())
model
.
prepare
(
optimizer
=
optim
,
...
...
hapi/vision/models/__init__.py
浏览文件 @
4643cad7
...
...
@@ -19,7 +19,7 @@ from . import mobilenetv2
from
.
import
darknet
from
.
import
yolov3
from
.
import
tsm
from
.
import
bmn
from
.
import
bmn
_model
from
.resnet
import
*
from
.mobilenetv1
import
*
...
...
@@ -28,7 +28,7 @@ from .vgg import *
from
.darknet
import
*
from
.yolov3
import
*
from
.tsm
import
*
from
.bmn
import
*
from
.bmn
_model
import
*
__all__
=
resnet
.
__all__
\
+
vgg
.
__all__
\
...
...
@@ -37,4 +37,4 @@ __all__ = resnet.__all__ \
+
darknet
.
__all__
\
+
yolov3
.
__all__
\
+
tsm
.
__all__
\
+
bmn
.
__all__
+
bmn
_model
.
__all__
hapi/vision/models/bmn.py
→
hapi/vision/models/bmn
_model
.py
浏览文件 @
4643cad7
...
...
@@ -18,11 +18,17 @@ import numpy as np
import
math
from
hapi.model
import
Model
,
Loss
from
hapi.download
import
get_weights_path
__all__
=
[
"BMN"
,
"BmnLoss"
]
__all__
=
[
"BMN"
,
"BmnLoss"
,
"bmn"
]
DATATYPE
=
'float32'
pretrain_infos
=
{
'bmn'
:
(
'https://paddlemodels.bj.bcebos.com/hapi/bmn.pdparams'
,
'9286c821acc4cad46d6613b931ba468c'
)
}
def
_get_interp1d_bin_mask
(
seg_xmin
,
seg_xmax
,
tscale
,
num_sample
,
num_sample_perbin
):
...
...
@@ -120,6 +126,13 @@ class Conv1D(fluid.dygraph.Layer):
class
BMN
(
Model
):
"""BMN model from
`"BMN: Boundary-Matching Network for Temporal Action Proposal Generation" <https://arxiv.org/abs/1907.09702>`_
Args:
cfg (AttrDict): configs for BMN model
is_dygraph (bool): whether in dygraph mode, default True.
"""
def
__init__
(
self
,
cfg
,
is_dygraph
=
True
):
super
(
BMN
,
self
).
__init__
()
...
...
@@ -277,6 +290,11 @@ class BMN(Model):
class
BmnLoss
(
Loss
):
"""Loss for BMN model
Args:
cfg (AttrDict): configs for BMN model
"""
def
__init__
(
self
,
cfg
):
super
(
BmnLoss
,
self
).
__init__
()
self
.
cfg
=
cfg
...
...
@@ -418,3 +436,21 @@ class BmnLoss(Loss):
loss
=
tem_loss
+
10
*
pem_reg_loss
+
pem_cls_loss
return
loss
def
bmn
(
cfg
,
is_dygraph
=
True
,
pretrained
=
True
):
"""BMN model
Args:
cfg (AttrDict): configs for BMN model
is_dygraph (bool): whether in dygraph mode, default True.
pretrained (bool): If True, returns a model with pre-trained model
on COCO, default True
"""
model
=
BMN
(
cfg
,
is_dygraph
=
is_dygraph
)
if
pretrained
:
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
'bmn'
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
[:
-
9
])
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录