Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
e26905fe
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看板
提交
e26905fe
编写于
4月 24, 2020
作者:
L
LielinJiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move Loss to loss.py
上级
2458c1fb
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
77 addition
and
60 deletion
+77
-60
examples/bert/bert_classifier.py
examples/bert/bert_classifier.py
+2
-1
examples/bert_leveldb/bert_classifier.py
examples/bert_leveldb/bert_classifier.py
+2
-1
examples/bmn/modeling.py
examples/bmn/modeling.py
+4
-3
examples/cyclegan/cyclegan.py
examples/cyclegan/cyclegan.py
+2
-1
examples/image_classification/main.py
examples/image_classification/main.py
+2
-1
examples/ocr/seq2seq_attn.py
examples/ocr/seq2seq_attn.py
+2
-1
examples/sequence_tagging/train.py
examples/sequence_tagging/train.py
+27
-22
examples/tsm/main.py
examples/tsm/main.py
+24
-24
examples/tsm/modeling.py
examples/tsm/modeling.py
+8
-3
examples/yolov3/modeling.py
examples/yolov3/modeling.py
+4
-3
未找到文件。
examples/bert/bert_classifier.py
浏览文件 @
e26905fe
...
@@ -18,7 +18,8 @@ from hapi.metrics import Accuracy
...
@@ -18,7 +18,8 @@ from hapi.metrics import Accuracy
from
hapi.configure
import
Config
from
hapi.configure
import
Config
from
hapi.text.bert
import
BertEncoder
from
hapi.text.bert
import
BertEncoder
from
paddle.fluid.dygraph
import
Linear
,
Layer
from
paddle.fluid.dygraph
import
Linear
,
Layer
from
hapi.model
import
set_device
,
Model
,
SoftmaxWithCrossEntropy
,
Input
from
hapi.model
import
set_device
,
Model
,
Input
from
hapi.loss
import
SoftmaxWithCrossEntropy
import
hapi.text.tokenizer.tokenization
as
tokenization
import
hapi.text.tokenizer.tokenization
as
tokenization
from
hapi.text.bert
import
Optimizer
,
BertConfig
,
BertDataLoader
,
BertInputExample
from
hapi.text.bert
import
Optimizer
,
BertConfig
,
BertDataLoader
,
BertInputExample
...
...
examples/bert_leveldb/bert_classifier.py
浏览文件 @
e26905fe
...
@@ -18,7 +18,8 @@ from hapi.metrics import Accuracy
...
@@ -18,7 +18,8 @@ from hapi.metrics import Accuracy
from
hapi.configure
import
Config
from
hapi.configure
import
Config
from
hapi.text.bert
import
BertEncoder
from
hapi.text.bert
import
BertEncoder
from
paddle.fluid.dygraph
import
Linear
,
Layer
from
paddle.fluid.dygraph
import
Linear
,
Layer
from
hapi.model
import
set_device
,
Model
,
SoftmaxWithCrossEntropy
,
Input
from
hapi.model
import
set_device
,
Model
,
Input
from
hapi.loss
import
SoftmaxWithCrossEntropy
import
hapi.text.tokenizer.tokenization
as
tokenization
import
hapi.text.tokenizer.tokenization
as
tokenization
from
hapi.text.bert
import
Optimizer
,
BertConfig
,
BertDataLoader
,
BertInputExample
from
hapi.text.bert
import
Optimizer
,
BertConfig
,
BertDataLoader
,
BertInputExample
...
...
examples/bmn/modeling.py
浏览文件 @
e26905fe
...
@@ -17,8 +17,9 @@ from paddle.fluid import ParamAttr
...
@@ -17,8 +17,9 @@ from paddle.fluid import ParamAttr
import
numpy
as
np
import
numpy
as
np
import
math
import
math
from
hapi.model
import
Model
,
Loss
from
hapi.model
import
Model
from
hapi.download
import
get_weights_path
from
hapi.loss
import
Loss
from
hapi.download
import
get_weights_path_from_url
__all__
=
[
"BMN"
,
"BmnLoss"
,
"bmn"
]
__all__
=
[
"BMN"
,
"BmnLoss"
,
"bmn"
]
...
@@ -459,7 +460,7 @@ def bmn(tscale,
...
@@ -459,7 +460,7 @@ def bmn(tscale,
model
=
BMN
(
tscale
,
dscale
,
prop_boundary_ratio
,
num_sample
,
model
=
BMN
(
tscale
,
dscale
,
prop_boundary_ratio
,
num_sample
,
num_sample_perbin
)
num_sample_perbin
)
if
pretrained
:
if
pretrained
:
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
'bmn'
]))
weight_path
=
get_weights_path
_from_url
(
*
(
pretrain_infos
[
'bmn'
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
)
model
.
load
(
weight_path
)
...
...
examples/cyclegan/cyclegan.py
浏览文件 @
e26905fe
...
@@ -19,7 +19,8 @@ from __future__ import print_function
...
@@ -19,7 +19,8 @@ from __future__ import print_function
import
numpy
as
np
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
hapi.model
import
Model
,
Loss
from
hapi.model
import
Model
from
hapi.loss
import
Loss
from
layers
import
ConvBN
,
DeConvBN
from
layers
import
ConvBN
,
DeConvBN
...
...
examples/image_classification/main.py
浏览文件 @
e26905fe
...
@@ -27,7 +27,8 @@ import paddle.fluid as fluid
...
@@ -27,7 +27,8 @@ import paddle.fluid as fluid
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.io
import
BatchSampler
,
DataLoader
from
paddle.io
import
BatchSampler
,
DataLoader
from
hapi.model
import
CrossEntropy
,
Input
,
set_device
from
hapi.model
import
Input
,
set_device
from
hapi.loss
import
CrossEntropy
from
hapi.distributed
import
DistributedBatchSampler
from
hapi.distributed
import
DistributedBatchSampler
from
hapi.metrics
import
Accuracy
from
hapi.metrics
import
Accuracy
import
hapi.vision.models
as
models
import
hapi.vision.models
as
models
...
...
examples/ocr/seq2seq_attn.py
浏览文件 @
e26905fe
...
@@ -20,7 +20,8 @@ import paddle.fluid.layers as layers
...
@@ -20,7 +20,8 @@ import paddle.fluid.layers as layers
from
paddle.fluid.layers
import
BeamSearchDecoder
from
paddle.fluid.layers
import
BeamSearchDecoder
from
hapi.text
import
RNNCell
,
RNN
,
DynamicDecode
from
hapi.text
import
RNNCell
,
RNN
,
DynamicDecode
from
hapi.model
import
Model
,
Loss
from
hapi.model
import
Model
from
hapi.loss
import
Loss
class
ConvBNPool
(
fluid
.
dygraph
.
Layer
):
class
ConvBNPool
(
fluid
.
dygraph
.
Layer
):
...
...
examples/sequence_tagging/train.py
浏览文件 @
e26905fe
...
@@ -28,14 +28,14 @@ import numpy as np
...
@@ -28,14 +28,14 @@ import numpy as np
work_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
work_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
sys
.
path
.
append
(
os
.
path
.
join
(
work_dir
,
"../"
))
sys
.
path
.
append
(
os
.
path
.
join
(
work_dir
,
"../"
))
from
hapi.metrics
import
Metric
from
hapi.metrics
import
Metric
from
hapi.model
import
Model
,
Input
,
Loss
,
set_device
from
hapi.model
import
Model
,
Input
,
set_device
from
hapi.loss
import
Loss
from
hapi.text.text
import
SequenceTagging
from
hapi.text.text
import
SequenceTagging
from
utils.check
import
check_gpu
,
check_version
from
utils.check
import
check_gpu
,
check_version
from
utils.configure
import
PDConfig
from
utils.configure
import
PDConfig
from
reader
import
LacDataset
,
create_lexnet_data_generator
,
create_dataloader
from
reader
import
LacDataset
,
create_lexnet_data_generator
,
create_dataloader
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid.optimizer
import
AdamOptimizer
from
paddle.fluid.optimizer
import
AdamOptimizer
...
@@ -65,19 +65,19 @@ class SeqTagging(Model):
...
@@ -65,19 +65,19 @@ class SeqTagging(Model):
self
.
bigru_num
=
args
.
bigru_num
self
.
bigru_num
=
args
.
bigru_num
self
.
batch_size
=
args
.
batch_size
self
.
batch_size
=
args
.
batch_size
self
.
init_bound
=
0.1
self
.
init_bound
=
0.1
self
.
length
=
length
self
.
length
=
length
self
.
sequence_tagging
=
SequenceTagging
(
self
.
sequence_tagging
=
SequenceTagging
(
vocab_size
=
self
.
vocab_size
,
vocab_size
=
self
.
vocab_size
,
num_labels
=
self
.
num_labels
,
num_labels
=
self
.
num_labels
,
batch_size
=
self
.
batch_size
,
batch_size
=
self
.
batch_size
,
word_emb_dim
=
self
.
word_emb_dim
,
word_emb_dim
=
self
.
word_emb_dim
,
grnn_hidden_dim
=
self
.
grnn_hidden_dim
,
grnn_hidden_dim
=
self
.
grnn_hidden_dim
,
emb_learning_rate
=
self
.
emb_lr
,
emb_learning_rate
=
self
.
emb_lr
,
crf_learning_rate
=
self
.
crf_lr
,
crf_learning_rate
=
self
.
crf_lr
,
bigru_num
=
self
.
bigru_num
,
bigru_num
=
self
.
bigru_num
,
init_bound
=
self
.
init_bound
,
init_bound
=
self
.
init_bound
,
length
=
self
.
length
)
length
=
self
.
length
)
def
forward
(
self
,
*
inputs
):
def
forward
(
self
,
*
inputs
):
"""
"""
...
@@ -85,10 +85,10 @@ class SeqTagging(Model):
...
@@ -85,10 +85,10 @@ class SeqTagging(Model):
"""
"""
word
=
inputs
[
0
]
word
=
inputs
[
0
]
lengths
=
inputs
[
1
]
lengths
=
inputs
[
1
]
if
self
.
mode_type
==
"train"
or
self
.
mode_type
==
"test"
:
if
self
.
mode_type
==
"train"
or
self
.
mode_type
==
"test"
:
target
=
inputs
[
2
]
target
=
inputs
[
2
]
outputs
=
self
.
sequence_tagging
(
word
,
lengths
,
target
)
outputs
=
self
.
sequence_tagging
(
word
,
lengths
,
target
)
else
:
else
:
outputs
=
self
.
sequence_tagging
(
word
,
lengths
)
outputs
=
self
.
sequence_tagging
(
word
,
lengths
)
return
outputs
return
outputs
...
@@ -156,7 +156,7 @@ class ChunkEval(Metric):
...
@@ -156,7 +156,7 @@ class ChunkEval(Metric):
int
(
math
.
ceil
((
num_labels
-
1
)
/
2.0
)),
"IOB"
)
int
(
math
.
ceil
((
num_labels
-
1
)
/
2.0
)),
"IOB"
)
self
.
reset
()
self
.
reset
()
def
add_metric_op
(
self
,
*
args
):
def
add_metric_op
(
self
,
*
args
):
crf_decode
=
args
[
0
]
crf_decode
=
args
[
0
]
lengths
=
args
[
2
]
lengths
=
args
[
2
]
label
=
args
[
3
]
label
=
args
[
3
]
...
@@ -207,13 +207,18 @@ def main(args):
...
@@ -207,13 +207,18 @@ def main(args):
place
=
set_device
(
args
.
device
)
place
=
set_device
(
args
.
device
)
fluid
.
enable_dygraph
(
place
)
if
args
.
dynamic
else
None
fluid
.
enable_dygraph
(
place
)
if
args
.
dynamic
else
None
inputs
=
[
Input
([
None
,
None
],
'int64'
,
name
=
'words'
),
inputs
=
[
Input
([
None
],
'int64'
,
name
=
'length'
),
Input
(
Input
([
None
,
None
],
'int64'
,
name
=
'target'
)]
[
None
,
None
],
'int64'
,
name
=
'words'
),
Input
(
[
None
],
'int64'
,
name
=
'length'
),
Input
(
[
None
,
None
],
'int64'
,
name
=
'target'
)
]
labels
=
[
Input
([
None
,
None
],
'int64'
,
name
=
'labels'
)]
labels
=
[
Input
([
None
,
None
],
'int64'
,
name
=
'labels'
)]
feed_list
=
None
if
args
.
dynamic
else
[
x
.
forward
()
for
x
in
inputs
+
labels
]
feed_list
=
None
if
args
.
dynamic
else
[
x
.
forward
()
for
x
in
inputs
+
labels
]
dataset
=
LacDataset
(
args
)
dataset
=
LacDataset
(
args
)
train_path
=
args
.
train_file
train_path
=
args
.
train_file
test_path
=
args
.
test_file
test_path
=
args
.
test_file
...
@@ -263,7 +268,7 @@ if __name__ == '__main__':
...
@@ -263,7 +268,7 @@ if __name__ == '__main__':
args
=
PDConfig
(
yaml_file
=
"sequence_tagging.yaml"
)
args
=
PDConfig
(
yaml_file
=
"sequence_tagging.yaml"
)
args
.
build
()
args
.
build
()
args
.
Print
()
args
.
Print
()
use_gpu
=
True
if
args
.
device
==
"gpu"
else
False
use_gpu
=
True
if
args
.
device
==
"gpu"
else
False
check_gpu
(
use_gpu
)
check_gpu
(
use_gpu
)
check_version
()
check_version
()
...
...
examples/tsm/main.py
浏览文件 @
e26905fe
...
@@ -22,7 +22,8 @@ import numpy as np
...
@@ -22,7 +22,8 @@ import numpy as np
from
paddle
import
fluid
from
paddle
import
fluid
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
hapi.model
import
Model
,
CrossEntropy
,
Input
,
set_device
from
hapi.model
import
Model
,
Input
,
set_device
from
hapi.loss
import
CrossEntropy
from
hapi.metrics
import
Accuracy
from
hapi.metrics
import
Accuracy
from
modeling
import
tsm_resnet50
from
modeling
import
tsm_resnet50
...
@@ -33,11 +34,10 @@ from transforms import *
...
@@ -33,11 +34,10 @@ from transforms import *
def
make_optimizer
(
step_per_epoch
,
parameter_list
=
None
):
def
make_optimizer
(
step_per_epoch
,
parameter_list
=
None
):
boundaries
=
[
e
*
step_per_epoch
for
e
in
[
40
,
60
]]
boundaries
=
[
e
*
step_per_epoch
for
e
in
[
40
,
60
]]
values
=
[
FLAGS
.
lr
*
(
0.1
**
i
)
for
i
in
range
(
len
(
boundaries
)
+
1
)]
values
=
[
FLAGS
.
lr
*
(
0.1
**
i
)
for
i
in
range
(
len
(
boundaries
)
+
1
)]
learning_rate
=
fluid
.
layers
.
piecewise_decay
(
learning_rate
=
fluid
.
layers
.
piecewise_decay
(
boundaries
=
boundaries
,
boundaries
=
boundaries
,
values
=
values
)
values
=
values
)
optimizer
=
fluid
.
optimizer
.
Momentum
(
optimizer
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
learning_rate
,
learning_rate
=
learning_rate
,
regularization
=
fluid
.
regularizer
.
L2Decay
(
1e-4
),
regularization
=
fluid
.
regularizer
.
L2Decay
(
1e-4
),
...
@@ -51,29 +51,27 @@ def main():
...
@@ -51,29 +51,27 @@ def main():
device
=
set_device
(
FLAGS
.
device
)
device
=
set_device
(
FLAGS
.
device
)
fluid
.
enable_dygraph
(
device
)
if
FLAGS
.
dynamic
else
None
fluid
.
enable_dygraph
(
device
)
if
FLAGS
.
dynamic
else
None
train_transform
=
Compose
([
GroupScale
(),
train_transform
=
Compose
([
GroupMultiScaleCrop
(),
GroupScale
(),
GroupMultiScaleCrop
(),
GroupRandomCrop
(),
GroupRandomCrop
(),
GroupRandomFlip
(),
NormalizeImage
()
GroupRandomFlip
(),
])
NormalizeImage
()])
train_dataset
=
KineticsDataset
(
train_dataset
=
KineticsDataset
(
file_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'train_10.list'
),
file_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'train_10.list'
),
pickle_dir
=
os
.
path
.
join
(
FLAGS
.
data
,
'train_10'
),
pickle_dir
=
os
.
path
.
join
(
FLAGS
.
data
,
'train_10'
),
label_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'label_list'
),
label_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'label_list'
),
transform
=
train_transform
)
transform
=
train_transform
)
val_transform
=
Compose
([
GroupScale
(),
val_transform
=
Compose
(
GroupCenterCrop
(),
[
GroupScale
(),
GroupCenterCrop
(),
NormalizeImage
()])
NormalizeImage
()])
val_dataset
=
KineticsDataset
(
val_dataset
=
KineticsDataset
(
file_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'val_10.list'
),
file_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'val_10.list'
),
pickle_dir
=
os
.
path
.
join
(
FLAGS
.
data
,
'val_10'
),
pickle_dir
=
os
.
path
.
join
(
FLAGS
.
data
,
'val_10'
),
label_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'label_list'
),
label_list
=
os
.
path
.
join
(
FLAGS
.
data
,
'label_list'
),
mode
=
'val'
,
mode
=
'val'
,
transform
=
val_transform
)
transform
=
val_transform
)
pretrained
=
FLAGS
.
eval_only
and
FLAGS
.
weights
is
None
pretrained
=
FLAGS
.
eval_only
and
FLAGS
.
weights
is
None
model
=
tsm_resnet50
(
num_classes
=
train_dataset
.
num_classes
,
model
=
tsm_resnet50
(
pretrained
=
pretrained
)
num_classes
=
train_dataset
.
num_classes
,
pretrained
=
pretrained
)
step_per_epoch
=
int
(
len
(
train_dataset
)
/
FLAGS
.
batch_size
\
step_per_epoch
=
int
(
len
(
train_dataset
)
/
FLAGS
.
batch_size
\
/
ParallelEnv
().
nranks
)
/
ParallelEnv
().
nranks
)
...
@@ -116,7 +114,9 @@ def main():
...
@@ -116,7 +114,9 @@ def main():
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
"CNN training on TSM"
)
parser
=
argparse
.
ArgumentParser
(
"CNN training on TSM"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--data"
,
type
=
str
,
default
=
'dataset/kinetics'
,
"--data"
,
type
=
str
,
default
=
'dataset/kinetics'
,
help
=
"path to dataset root directory"
)
help
=
"path to dataset root directory"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--device"
,
type
=
str
,
default
=
'gpu'
,
help
=
"device to use, gpu or cpu"
)
"--device"
,
type
=
str
,
default
=
'gpu'
,
help
=
"device to use, gpu or cpu"
)
...
...
examples/tsm/modeling.py
浏览文件 @
e26905fe
...
@@ -18,7 +18,7 @@ from paddle.fluid.layer_helper import LayerHelper
...
@@ -18,7 +18,7 @@ from paddle.fluid.layer_helper import LayerHelper
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
BatchNorm
,
Linear
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
BatchNorm
,
Linear
from
hapi.model
import
Model
from
hapi.model
import
Model
from
hapi.download
import
get_weights_path
from
hapi.download
import
get_weights_path
_from_url
__all__
=
[
"TSM_ResNet"
,
"tsm_resnet50"
]
__all__
=
[
"TSM_ResNet"
,
"tsm_resnet50"
]
...
@@ -122,6 +122,7 @@ class TSM_ResNet(Model):
...
@@ -122,6 +122,7 @@ class TSM_ResNet(Model):
seg_num (int): segment number of each video sample. Default 8.
seg_num (int): segment number of each video sample. Default 8.
num_classes (int): video class number. Default 400.
num_classes (int): video class number. Default 400.
"""
"""
def
__init__
(
self
,
num_layers
=
50
,
seg_num
=
8
,
num_classes
=
400
):
def
__init__
(
self
,
num_layers
=
50
,
seg_num
=
8
,
num_classes
=
400
):
super
(
TSM_ResNet
,
self
).
__init__
()
super
(
TSM_ResNet
,
self
).
__init__
()
...
@@ -136,7 +137,11 @@ class TSM_ResNet(Model):
...
@@ -136,7 +137,11 @@ class TSM_ResNet(Model):
num_filters
=
[
64
,
128
,
256
,
512
]
num_filters
=
[
64
,
128
,
256
,
512
]
self
.
conv
=
ConvBNLayer
(
self
.
conv
=
ConvBNLayer
(
num_channels
=
3
,
num_filters
=
64
,
filter_size
=
7
,
stride
=
2
,
act
=
'relu'
)
num_channels
=
3
,
num_filters
=
64
,
filter_size
=
7
,
stride
=
2
,
act
=
'relu'
)
self
.
pool2d_max
=
Pool2D
(
self
.
pool2d_max
=
Pool2D
(
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
pool_type
=
'max'
)
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
pool_type
=
'max'
)
...
@@ -193,7 +198,7 @@ def _tsm_resnet(num_layers, seg_num=8, num_classes=400, pretrained=True):
...
@@ -193,7 +198,7 @@ def _tsm_resnet(num_layers, seg_num=8, num_classes=400, pretrained=True):
assert
num_layers
in
pretrain_infos
.
keys
(),
\
assert
num_layers
in
pretrain_infos
.
keys
(),
\
"TSM-ResNet{} do not have pretrained weights now, "
\
"TSM-ResNet{} do not have pretrained weights now, "
\
"pretrained should be set as False"
.
format
(
num_layers
)
"pretrained should be set as False"
.
format
(
num_layers
)
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
num_layers
]))
weight_path
=
get_weights_path
_from_url
(
*
(
pretrain_infos
[
num_layers
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
)
model
.
load
(
weight_path
)
...
...
examples/yolov3/modeling.py
浏览文件 @
e26905fe
...
@@ -20,8 +20,9 @@ from paddle.fluid.dygraph.nn import Conv2D, BatchNorm
...
@@ -20,8 +20,9 @@ from paddle.fluid.dygraph.nn import Conv2D, BatchNorm
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.regularizer
import
L2Decay
from
paddle.fluid.regularizer
import
L2Decay
from
hapi.model
import
Model
,
Loss
from
hapi.model
import
Model
from
hapi.download
import
get_weights_path
from
hapi.loss
import
Loss
from
hapi.download
import
get_weights_path_from_url
from
hapi.vision.models
import
darknet53
from
hapi.vision.models
import
darknet53
__all__
=
[
'YoloLoss'
,
'YOLOv3'
,
'yolov3_darknet53'
]
__all__
=
[
'YoloLoss'
,
'YOLOv3'
,
'yolov3_darknet53'
]
...
@@ -315,7 +316,7 @@ def _yolov3_darknet(num_layers=53,
...
@@ -315,7 +316,7 @@ def _yolov3_darknet(num_layers=53,
assert
num_layers
in
pretrain_infos
.
keys
(),
\
assert
num_layers
in
pretrain_infos
.
keys
(),
\
"YOLOv3-DarkNet{} do not have pretrained weights now, "
\
"YOLOv3-DarkNet{} do not have pretrained weights now, "
\
"pretrained should be set as False"
.
format
(
num_layers
)
"pretrained should be set as False"
.
format
(
num_layers
)
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
num_layers
]))
weight_path
=
get_weights_path
_from_url
(
*
(
pretrain_infos
[
num_layers
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
)
model
.
load
(
weight_path
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录