Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
133458b1
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看板
提交
133458b1
编写于
1月 30, 2019
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use load_params
上级
fc0e6988
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
18 addition
and
24 deletion
+18
-24
fluid/PaddleCV/video/.gitignore
fluid/PaddleCV/video/.gitignore
+5
-0
fluid/PaddleCV/video/models/model.py
fluid/PaddleCV/video/models/model.py
+9
-14
fluid/PaddleCV/video/models/stnet/stnet.py
fluid/PaddleCV/video/models/stnet/stnet.py
+2
-9
fluid/PaddleCV/video/test.py
fluid/PaddleCV/video/test.py
+1
-0
fluid/PaddleCV/video/train.py
fluid/PaddleCV/video/train.py
+1
-1
未找到文件。
fluid/PaddleCV/video/.gitignore
0 → 100644
浏览文件 @
133458b1
data
checkpoints
output*
*.py
*.swp
fluid/PaddleCV/video/models/model.py
浏览文件 @
133458b1
...
...
@@ -13,6 +13,7 @@
#limitations under the License.
import
os
import
logging
try
:
from
configparser
import
ConfigParser
except
:
...
...
@@ -25,6 +26,8 @@ from .utils import download, AttrDict
WEIGHT_DIR
=
os
.
path
.
expanduser
(
"~/.paddle/weights"
)
logger
=
logging
.
getLogger
(
__name__
)
class
NotImplementError
(
Exception
):
"Error: model function not implement"
...
...
@@ -163,15 +166,14 @@ class ModelBase(object):
"get model weight default path and download url"
raise
NotImplementError
(
self
,
self
.
weights_info
)
def
get_weights
(
self
,
logger
=
None
):
def
get_weights
(
self
):
"get model weight file path, download weight from Paddle if not exist"
path
,
url
=
self
.
weights_info
()
path
=
os
.
path
.
join
(
WEIGHT_DIR
,
path
)
if
os
.
path
.
exists
(
path
):
return
path
if
logger
:
logger
.
info
(
"Download weights of {} from {}"
.
format
(
self
.
name
,
url
))
logger
.
info
(
"Download weights of {} from {}"
.
format
(
self
.
name
,
url
))
download
(
url
,
path
)
return
path
...
...
@@ -186,7 +188,7 @@ class ModelBase(object):
"get pretrain base model directory"
return
(
None
,
None
)
def
get_pretrain_weights
(
self
,
logger
=
None
):
def
get_pretrain_weights
(
self
):
"get model weight file path, download weight from Paddle if not exist"
path
,
url
=
self
.
pretrain_info
()
if
not
path
:
...
...
@@ -196,22 +198,15 @@ class ModelBase(object):
if
os
.
path
.
exists
(
path
):
return
path
if
logger
:
logger
.
info
(
"Download pretrain weights of {} from {}"
.
format
(
logger
.
info
(
"Download pretrain weights of {} from {}"
.
format
(
self
.
name
,
url
))
utils
.
download
(
url
,
path
)
return
path
def
load_pretrain
ed_params
(
self
,
exe
,
pretrained_base
,
prog
,
place
):
def
load_pretrain
_params
(
self
,
exe
,
pretrain
,
prog
):
def
if_exist
(
var
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
pretrained_base
,
var
.
name
))
inference_program
=
prog
.
clone
(
for_test
=
True
)
fluid
.
io
.
load_vars
(
exe
,
pretrained_base
,
predicate
=
if_exist
,
main_program
=
inference_program
)
fluid
.
io
.
load_params
(
exe
,
pretrain
,
main_program
=
prog
)
def
get_config_from_sec
(
self
,
sec
,
item
,
default
=
None
):
cfg_item
=
self
.
_config
.
get_config_from_sec
(
sec
.
upper
(),
...
...
fluid/PaddleCV/video/models/stnet/stnet.py
浏览文件 @
133458b1
...
...
@@ -153,15 +153,8 @@ class STNET(ModelBase):
def
create_metrics_args
(
self
):
return
{}
def
load_pretrained_params
(
self
,
exe
,
pretrain_base
,
prog
,
place
):
def
is_parameter
(
var
):
if
isinstance
(
var
,
fluid
.
framework
.
Parameter
):
return
isinstance
(
var
,
fluid
.
framework
.
Parameter
)
and
(
not
(
"fc_0"
in
var
.
name
))
\
and
(
not
(
"batch_norm"
in
var
.
name
))
and
(
not
(
"xception"
in
var
.
name
))
and
(
not
(
"conv3d"
in
var
.
name
))
inference_program
=
prog
.
clone
(
for_test
=
True
)
vars
=
filter
(
is_parameter
,
inference_program
.
list_vars
())
fluid
.
io
.
load_vars
(
exe
,
pretrain_base
,
vars
=
vars
)
def
load_pretrain_params
(
self
,
exe
,
pretrain
,
prog
):
fluid
.
io
.
load_params
(
exe
,
pretrain
,
main_program
=
prog
)
param_tensor
=
fluid
.
global_scope
().
find_var
(
"conv1_weights"
).
get_tensor
()
...
...
fluid/PaddleCV/video/test.py
浏览文件 @
133458b1
...
...
@@ -21,6 +21,7 @@ import numpy as np
import
paddle.fluid
as
fluid
import
models
logging
.
root
.
handlers
=
[]
FORMAT
=
'[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
FORMAT
,
stream
=
sys
.
stdout
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
fluid/PaddleCV/video/train.py
浏览文件 @
133458b1
...
...
@@ -152,7 +152,7 @@ def train(train_model, valid_model, args):
"Given pretrain weight dir {} not exist."
.
format
(
args
.
pretrain
)
pretrain
=
args
.
pretrain
or
train_model
.
get_pretrain_weights
()
if
pretrain
:
train_model
.
load_pretrain
ed_params
(
exe
,
pretrain
,
train_prog
,
place
)
train_model
.
load_pretrain
_params
(
exe
,
pretrain
,
train_prog
)
if
args
.
no_parallel
:
train_exe
=
exe
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录