Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
62184126
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看板
提交
62184126
编写于
4月 15, 2020
作者:
L
LielinJiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/PaddlePaddle/hapi
into style-transfer
上级
01cc52ee
308447ba
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
57 addition
and
23 deletion
+57
-23
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/callbacks.py
hapi/callbacks.py
+1
-1
hapi/vision/models/__init__.py
hapi/vision/models/__init__.py
+3
-3
hapi/vision/models/bmn_model.py
hapi/vision/models/bmn_model.py
+38
-4
未找到文件。
examples/bmn/eval.py
浏览文件 @
62184126
...
@@ -19,7 +19,7 @@ import logging
...
@@ -19,7 +19,7 @@ import logging
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
hapi.model
import
set_device
,
Input
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
bmn_metric
import
BmnMetric
from
reader
import
BmnDataset
from
reader
import
BmnDataset
from
config_utils
import
*
from
config_utils
import
*
...
@@ -53,7 +53,7 @@ def parse_args():
...
@@ -53,7 +53,7 @@ def parse_args():
parser
.
add_argument
(
parser
.
add_argument
(
'--weights'
,
'--weights'
,
type
=
str
,
type
=
str
,
default
=
"checkpoint/final"
,
default
=
None
,
help
=
'weight path, None to automatically download weights provided by Paddle.'
help
=
'weight path, None to automatically download weights provided by Paddle.'
)
)
parser
.
add_argument
(
parser
.
add_argument
(
...
@@ -97,7 +97,7 @@ def test_bmn(args):
...
@@ -97,7 +97,7 @@ def test_bmn(args):
eval_dataset
=
BmnDataset
(
eval_cfg
,
'test'
)
eval_dataset
=
BmnDataset
(
eval_cfg
,
'test'
)
#model
#model
model
=
BMN
(
config
,
args
.
dynamic
)
model
=
bmn
(
config
,
pretrained
=
args
.
weights
is
None
)
model
.
prepare
(
model
.
prepare
(
loss_function
=
BmnLoss
(
config
),
loss_function
=
BmnLoss
(
config
),
metrics
=
BmnMetric
(
metrics
=
BmnMetric
(
...
@@ -107,11 +107,11 @@ def test_bmn(args):
...
@@ -107,11 +107,11 @@ def test_bmn(args):
device
=
device
)
device
=
device
)
#load checkpoint
#load checkpoint
if
args
.
weights
:
if
args
.
weights
is
not
None
:
assert
os
.
path
.
exists
(
args
.
weights
+
'.pdparams'
),
\
assert
os
.
path
.
exists
(
args
.
weights
+
'.pdparams'
),
\
"Given weight dir {} not exist."
.
format
(
args
.
weights
)
"Given weight dir {} not exist."
.
format
(
args
.
weights
)
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
model
.
load
(
args
.
weights
)
model
.
load
(
args
.
weights
)
model
.
evaluate
(
model
.
evaluate
(
eval_data
=
eval_dataset
,
eval_data
=
eval_dataset
,
...
...
examples/bmn/predict.py
浏览文件 @
62184126
...
@@ -19,7 +19,7 @@ import logging
...
@@ -19,7 +19,7 @@ import logging
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
hapi.model
import
set_device
,
Input
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
bmn_metric
import
BmnMetric
from
reader
import
BmnDataset
from
reader
import
BmnDataset
from
config_utils
import
*
from
config_utils
import
*
...
@@ -50,7 +50,7 @@ def parse_args():
...
@@ -50,7 +50,7 @@ def parse_args():
parser
.
add_argument
(
parser
.
add_argument
(
'--weights'
,
'--weights'
,
type
=
str
,
type
=
str
,
default
=
"checkpoint/final"
,
default
=
None
,
help
=
'weight path, None to automatically download weights provided by Paddle.'
help
=
'weight path, None to automatically download weights provided by Paddle.'
)
)
parser
.
add_argument
(
parser
.
add_argument
(
...
@@ -92,7 +92,7 @@ def infer_bmn(args):
...
@@ -92,7 +92,7 @@ def infer_bmn(args):
#data
#data
infer_dataset
=
BmnDataset
(
infer_cfg
,
'infer'
)
infer_dataset
=
BmnDataset
(
infer_cfg
,
'infer'
)
model
=
BMN
(
config
,
args
.
dynamic
)
model
=
bmn
(
config
,
pretrained
=
args
.
weights
is
None
)
model
.
prepare
(
model
.
prepare
(
metrics
=
BmnMetric
(
metrics
=
BmnMetric
(
config
,
mode
=
'infer'
),
config
,
mode
=
'infer'
),
...
@@ -101,12 +101,12 @@ def infer_bmn(args):
...
@@ -101,12 +101,12 @@ def infer_bmn(args):
device
=
device
)
device
=
device
)
# load checkpoint
# load checkpoint
if
args
.
weights
:
if
args
.
weights
is
not
None
:
assert
os
.
path
.
exists
(
assert
os
.
path
.
exists
(
args
.
weights
+
args
.
weights
+
".pdparams"
),
"Given weight dir {} not exist."
.
format
(
args
.
weights
)
".pdparams"
),
"Given weight dir {} not exist."
.
format
(
args
.
weights
)
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
logger
.
info
(
'load test weights from {}'
.
format
(
args
.
weights
))
model
.
load
(
args
.
weights
)
model
.
load
(
args
.
weights
)
# here use model.eval instead of model.test, as post process is required in our case
# here use model.eval instead of model.test, as post process is required in our case
model
.
evaluate
(
model
.
evaluate
(
...
...
examples/bmn/reader.py
浏览文件 @
62184126
...
@@ -21,7 +21,7 @@ import sys
...
@@ -21,7 +21,7 @@ import sys
sys
.
path
.
append
(
'../'
)
sys
.
path
.
append
(
'../'
)
from
distributed
import
DistributedBatchSampler
from
hapi.
distributed
import
DistributedBatchSampler
from
paddle.io
import
Dataset
,
DataLoader
from
paddle.io
import
Dataset
,
DataLoader
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
examples/bmn/train.py
浏览文件 @
62184126
...
@@ -19,7 +19,7 @@ import sys
...
@@ -19,7 +19,7 @@ import sys
import
os
import
os
from
hapi.model
import
set_device
,
Input
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
reader
import
BmnDataset
from
config_utils
import
*
from
config_utils
import
*
...
@@ -136,7 +136,7 @@ def train_bmn(args):
...
@@ -136,7 +136,7 @@ def train_bmn(args):
val_dataset
=
BmnDataset
(
val_cfg
,
'valid'
)
val_dataset
=
BmnDataset
(
val_cfg
,
'valid'
)
# model
# model
model
=
BMN
(
config
,
args
.
dynamic
)
model
=
bmn
(
config
,
pretrained
=
False
)
optim
=
optimizer
(
config
,
parameter_list
=
model
.
parameters
())
optim
=
optimizer
(
config
,
parameter_list
=
model
.
parameters
())
model
.
prepare
(
model
.
prepare
(
optimizer
=
optim
,
optimizer
=
optim
,
...
...
hapi/callbacks.py
浏览文件 @
62184126
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
import
six
import
six
import
copy
import
copy
from
progressbar
import
ProgressBar
from
.
progressbar
import
ProgressBar
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
...
...
hapi/vision/models/__init__.py
浏览文件 @
62184126
...
@@ -19,7 +19,7 @@ from . import mobilenetv2
...
@@ -19,7 +19,7 @@ from . import mobilenetv2
from
.
import
darknet
from
.
import
darknet
from
.
import
yolov3
from
.
import
yolov3
from
.
import
tsm
from
.
import
tsm
from
.
import
bmn
from
.
import
bmn
_model
from
.resnet
import
*
from
.resnet
import
*
from
.mobilenetv1
import
*
from
.mobilenetv1
import
*
...
@@ -28,7 +28,7 @@ from .vgg import *
...
@@ -28,7 +28,7 @@ from .vgg import *
from
.darknet
import
*
from
.darknet
import
*
from
.yolov3
import
*
from
.yolov3
import
*
from
.tsm
import
*
from
.tsm
import
*
from
.bmn
import
*
from
.bmn
_model
import
*
__all__
=
resnet
.
__all__
\
__all__
=
resnet
.
__all__
\
+
vgg
.
__all__
\
+
vgg
.
__all__
\
...
@@ -37,4 +37,4 @@ __all__ = resnet.__all__ \
...
@@ -37,4 +37,4 @@ __all__ = resnet.__all__ \
+
darknet
.
__all__
\
+
darknet
.
__all__
\
+
yolov3
.
__all__
\
+
yolov3
.
__all__
\
+
tsm
.
__all__
\
+
tsm
.
__all__
\
+
bmn
.
__all__
+
bmn
_model
.
__all__
hapi/vision/models/bmn.py
→
hapi/vision/models/bmn
_model
.py
浏览文件 @
62184126
...
@@ -14,15 +14,22 @@
...
@@ -14,15 +14,22 @@
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid
import
ParamAttr
from
paddle.fluid
import
ParamAttr
from
paddle.fluid.framework
import
in_dygraph_mode
import
numpy
as
np
import
numpy
as
np
import
math
import
math
from
hapi.model
import
Model
,
Loss
from
hapi.model
import
Model
,
Loss
from
hapi.download
import
get_weights_path
__all__
=
[
"BMN"
,
"BmnLoss"
]
__all__
=
[
"BMN"
,
"BmnLoss"
,
"bmn"
]
DATATYPE
=
'float32'
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
,
def
_get_interp1d_bin_mask
(
seg_xmin
,
seg_xmax
,
tscale
,
num_sample
,
num_sample_perbin
):
num_sample_perbin
):
...
@@ -120,7 +127,13 @@ class Conv1D(fluid.dygraph.Layer):
...
@@ -120,7 +127,13 @@ class Conv1D(fluid.dygraph.Layer):
class
BMN
(
Model
):
class
BMN
(
Model
):
def
__init__
(
self
,
cfg
,
is_dygraph
=
True
):
"""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
"""
def
__init__
(
self
,
cfg
):
super
(
BMN
,
self
).
__init__
()
super
(
BMN
,
self
).
__init__
()
#init config
#init config
...
@@ -129,7 +142,6 @@ class BMN(Model):
...
@@ -129,7 +142,6 @@ class BMN(Model):
self
.
prop_boundary_ratio
=
cfg
.
MODEL
.
prop_boundary_ratio
self
.
prop_boundary_ratio
=
cfg
.
MODEL
.
prop_boundary_ratio
self
.
num_sample
=
cfg
.
MODEL
.
num_sample
self
.
num_sample
=
cfg
.
MODEL
.
num_sample
self
.
num_sample_perbin
=
cfg
.
MODEL
.
num_sample_perbin
self
.
num_sample_perbin
=
cfg
.
MODEL
.
num_sample_perbin
self
.
is_dygraph
=
is_dygraph
self
.
hidden_dim_1d
=
256
self
.
hidden_dim_1d
=
256
self
.
hidden_dim_2d
=
128
self
.
hidden_dim_2d
=
128
...
@@ -184,7 +196,7 @@ class BMN(Model):
...
@@ -184,7 +196,7 @@ class BMN(Model):
sample_mask_array
=
get_interp1d_mask
(
sample_mask_array
=
get_interp1d_mask
(
self
.
tscale
,
self
.
dscale
,
self
.
prop_boundary_ratio
,
self
.
tscale
,
self
.
dscale
,
self
.
prop_boundary_ratio
,
self
.
num_sample
,
self
.
num_sample_perbin
)
self
.
num_sample
,
self
.
num_sample_perbin
)
if
self
.
is_dygraph
:
if
in_dygraph_mode
():
self
.
sample_mask
=
fluid
.
dygraph
.
base
.
to_variable
(
self
.
sample_mask
=
fluid
.
dygraph
.
base
.
to_variable
(
sample_mask_array
)
sample_mask_array
)
else
:
# static
else
:
# static
...
@@ -277,6 +289,11 @@ class BMN(Model):
...
@@ -277,6 +289,11 @@ class BMN(Model):
class
BmnLoss
(
Loss
):
class
BmnLoss
(
Loss
):
"""Loss for BMN model
Args:
cfg (AttrDict): configs for BMN model
"""
def
__init__
(
self
,
cfg
):
def
__init__
(
self
,
cfg
):
super
(
BmnLoss
,
self
).
__init__
()
super
(
BmnLoss
,
self
).
__init__
()
self
.
cfg
=
cfg
self
.
cfg
=
cfg
...
@@ -418,3 +435,20 @@ class BmnLoss(Loss):
...
@@ -418,3 +435,20 @@ class BmnLoss(Loss):
loss
=
tem_loss
+
10
*
pem_reg_loss
+
pem_cls_loss
loss
=
tem_loss
+
10
*
pem_reg_loss
+
pem_cls_loss
return
loss
return
loss
def
bmn
(
cfg
,
pretrained
=
True
):
"""BMN model
Args:
cfg (AttrDict): configs for BMN model
pretrained (bool): If True, returns a model with pre-trained model
on COCO, default True
"""
model
=
BMN
(
cfg
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录