Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
4509ef1d
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4509ef1d
编写于
6月 04, 2020
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add AlexNet
上级
a073367a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
216 addition
and
21 deletion
+216
-21
paddlex/__init__.py
paddlex/__init__.py
+1
-1
paddlex/cls.py
paddlex/cls.py
+1
-0
paddlex/cv/models/__init__.py
paddlex/cv/models/__init__.py
+1
-0
paddlex/cv/models/base.py
paddlex/cv/models/base.py
+9
-13
paddlex/cv/models/classifier.py
paddlex/cv/models/classifier.py
+9
-0
paddlex/cv/models/load_model.py
paddlex/cv/models/load_model.py
+10
-2
paddlex/cv/models/utils/pretrain_weights.py
paddlex/cv/models/utils/pretrain_weights.py
+8
-4
paddlex/cv/nets/__init__.py
paddlex/cv/nets/__init__.py
+6
-0
paddlex/cv/nets/alexnet.py
paddlex/cv/nets/alexnet.py
+170
-0
setup.py
setup.py
+1
-1
未找到文件。
paddlex/__init__.py
浏览文件 @
4509ef1d
...
...
@@ -53,4 +53,4 @@ log_level = 2
from
.
import
interpret
__version__
=
'1.0.
5
'
__version__
=
'1.0.
6
'
paddlex/cls.py
浏览文件 @
4509ef1d
...
...
@@ -37,5 +37,6 @@ DenseNet161 = cv.models.DenseNet161
DenseNet201
=
cv
.
models
.
DenseNet201
ShuffleNetV2
=
cv
.
models
.
ShuffleNetV2
HRNet_W18
=
cv
.
models
.
HRNet_W18
AlexNet
=
cv
.
models
.
AlexNet
transforms
=
cv
.
transforms
.
cls_transforms
paddlex/cv/models/__init__.py
浏览文件 @
4509ef1d
...
...
@@ -35,6 +35,7 @@ from .classifier import DenseNet161
from
.classifier
import
DenseNet201
from
.classifier
import
ShuffleNetV2
from
.classifier
import
HRNet_W18
from
.classifier
import
AlexNet
from
.base
import
BaseAPI
from
.yolo_v3
import
YOLOv3
from
.faster_rcnn
import
FasterRCNN
...
...
paddlex/cv/models/base.py
浏览文件 @
4509ef1d
...
...
@@ -221,8 +221,8 @@ class BaseAPI:
logging
.
info
(
"Load pretrain weights from {}."
.
format
(
pretrain_weights
),
use_color
=
True
)
paddlex
.
utils
.
utils
.
load_pretrain_weights
(
self
.
exe
,
self
.
train_prog
,
pretrain_weights
,
fuse_bn
)
paddlex
.
utils
.
utils
.
load_pretrain_weights
(
self
.
exe
,
self
.
train_prog
,
pretrain_weights
,
fuse_bn
)
# 进行裁剪
if
sensitivities_file
is
not
None
:
import
paddleslim
...
...
@@ -262,6 +262,7 @@ class BaseAPI:
info
[
'_Attributes'
][
'num_classes'
]
=
self
.
num_classes
info
[
'_Attributes'
][
'labels'
]
=
self
.
labels
info
[
'_Attributes'
][
'fixed_input_shape'
]
=
self
.
fixed_input_shape
try
:
primary_metric_key
=
list
(
self
.
eval_metrics
.
keys
())[
0
]
primary_metric_value
=
float
(
self
.
eval_metrics
[
primary_metric_key
])
...
...
@@ -325,9 +326,7 @@ class BaseAPI:
logging
.
info
(
"Model saved in {}."
.
format
(
save_dir
))
def
export_inference_model
(
self
,
save_dir
):
test_input_names
=
[
var
.
name
for
var
in
list
(
self
.
test_inputs
.
values
())
]
test_input_names
=
[
var
.
name
for
var
in
list
(
self
.
test_inputs
.
values
())]
test_outputs
=
list
(
self
.
test_outputs
.
values
())
if
self
.
__class__
.
__name__
==
'MaskRCNN'
:
from
paddlex.utils.save
import
save_mask_inference_model
...
...
@@ -364,8 +363,7 @@ class BaseAPI:
# 模型保存成功的标志
open
(
osp
.
join
(
save_dir
,
'.success'
),
'w'
).
close
()
logging
.
info
(
"Model for inference deploy saved in {}."
.
format
(
save_dir
))
logging
.
info
(
"Model for inference deploy saved in {}."
.
format
(
save_dir
))
def
train_loop
(
self
,
num_epochs
,
...
...
@@ -489,13 +487,11 @@ class BaseAPI:
eta
=
((
num_epochs
-
i
)
*
total_num_steps
-
step
-
1
)
*
avg_step_time
if
time_eval_one_epoch
is
not
None
:
eval_eta
=
(
total_eval_times
-
i
//
save_interval_epochs
)
*
time_eval_one_epoch
eval_eta
=
(
total_eval_times
-
i
//
save_interval_epochs
)
*
time_eval_one_epoch
else
:
eval_eta
=
(
total_eval_times
-
i
//
save_interval_epochs
)
*
total_num_steps_eval
*
avg_step_time
eval_eta
=
(
total_eval_times
-
i
//
save_interval_epochs
)
*
total_num_steps_eval
*
avg_step_time
eta_str
=
seconds_to_hms
(
eta
+
eval_eta
)
logging
.
info
(
...
...
paddlex/cv/models/classifier.py
浏览文件 @
4509ef1d
...
...
@@ -48,6 +48,8 @@ class BaseClassifier(BaseAPI):
self
.
fixed_input_shape
=
None
def
build_net
(
self
,
mode
=
'train'
):
if
self
.
__class__
.
__name__
==
"AlexNet"
:
assert
self
.
fixed_input_shape
is
not
None
,
"In AlexNet, input_shape should be defined, e.g. model = paddlex.cls.AlexNet(num_classes=1000, input_shape=[224, 224])"
if
self
.
fixed_input_shape
is
not
None
:
input_shape
=
[
None
,
3
,
self
.
fixed_input_shape
[
1
],
self
.
fixed_input_shape
[
0
]
...
...
@@ -427,3 +429,10 @@ class HRNet_W18(BaseClassifier):
def
__init__
(
self
,
num_classes
=
1000
):
super
(
HRNet_W18
,
self
).
__init__
(
model_name
=
'HRNet_W18'
,
num_classes
=
num_classes
)
class
AlexNet
(
BaseClassifier
):
def
__init__
(
self
,
num_classes
=
1000
,
input_shape
=
None
):
super
(
AlexNet
,
self
).
__init__
(
model_name
=
'AlexNet'
,
num_classes
=
num_classes
)
self
.
fixed_input_shape
=
input_shape
paddlex/cv/models/load_model.py
浏览文件 @
4509ef1d
...
...
@@ -41,7 +41,15 @@ def load_model(model_dir, fixed_input_shape=None):
if
'model_name'
in
info
[
'_init_params'
]:
del
info
[
'_init_params'
][
'model_name'
]
model
=
getattr
(
paddlex
.
cv
.
models
,
info
[
'Model'
])(
**
info
[
'_init_params'
])
model
.
fixed_input_shape
=
fixed_input_shape
if
'_Attributes'
in
info
:
if
'fixed_input_shape'
in
info
[
'_Attributes'
]:
fixed_input_shape
=
info
[
'_Attributes'
][
'fixed_input_shape'
]
logging
.
info
(
"Model already has fixed_input_shape with {}"
.
format
(
fixed_input_shape
))
model
.
fixed_input_shape
=
fixed_input_shape
if
status
==
"Normal"
or
\
status
==
"Prune"
or
status
==
"fluid.save"
:
startup_prog
=
fluid
.
Program
()
...
...
@@ -88,8 +96,8 @@ def load_model(model_dir, fixed_input_shape=None):
model
.
model_type
,
info
[
'Transforms'
],
info
[
'BatchTransforms'
])
model
.
eval_transforms
=
copy
.
deepcopy
(
model
.
test_transforms
)
else
:
model
.
test_transforms
=
build_transforms
(
model
.
model_type
,
info
[
'Transforms'
],
to_rgb
)
model
.
test_transforms
=
build_transforms
(
model
.
model_type
,
info
[
'Transforms'
],
to_rgb
)
model
.
eval_transforms
=
copy
.
deepcopy
(
model
.
test_transforms
)
if
'_Attributes'
in
info
:
...
...
paddlex/cv/models/utils/pretrain_weights.py
浏览文件 @
4509ef1d
...
...
@@ -70,6 +70,8 @@ image_pretrain = {
'https://paddle-imagenet-models-name.bj.bcebos.com/HRNet_W60_C_pretrained.tar'
,
'HRNet_W64'
:
'https://paddle-imagenet-models-name.bj.bcebos.com/HRNet_W64_C_pretrained.tar'
,
'AlexNet'
:
'http://paddle-imagenet-models-name.bj.bcebos.com/AlexNet_pretrained.tar'
}
coco_pretrain
=
{
...
...
@@ -99,10 +101,12 @@ def get_pretrain_weights(flag, model_type, backbone, save_dir):
backbone
=
'DetResNet50'
assert
backbone
in
image_pretrain
,
"There is not ImageNet pretrain weights for {}, you may try COCO."
.
format
(
backbone
)
# url = image_pretrain[backbone]
# fname = osp.split(url)[-1].split('.')[0]
# paddlex.utils.download_and_decompress(url, path=new_save_dir)
# return osp.join(new_save_dir, fname)
if
backbone
==
'AlexNet'
:
url
=
image_pretrain
[
backbone
]
fname
=
osp
.
split
(
url
)[
-
1
].
split
(
'.'
)[
0
]
paddlex
.
utils
.
download_and_decompress
(
url
,
path
=
new_save_dir
)
return
osp
.
join
(
new_save_dir
,
fname
)
try
:
hub
.
download
(
backbone
,
save_path
=
new_save_dir
)
except
Exception
as
e
:
...
...
paddlex/cv/nets/__init__.py
浏览文件 @
4509ef1d
...
...
@@ -24,6 +24,7 @@ from .xception import Xception
from
.densenet
import
DenseNet
from
.shufflenet_v2
import
ShuffleNetV2
from
.hrnet
import
HRNet
from
.alexnet
import
AlexNet
def
resnet18
(
input
,
num_classes
=
1000
):
...
...
@@ -153,3 +154,8 @@ def shufflenetv2(input, num_classes=1000):
def
hrnet_w18
(
input
,
num_classes
=
1000
):
model
=
HRNet
(
width
=
18
,
num_classes
=
num_classes
)
return
model
(
input
)
def
alexnet
(
input
,
num_classes
=
1000
):
model
=
AlexNet
(
num_classes
=
num_classes
)
return
model
(
input
)
paddlex/cv/nets/alexnet.py
0 → 100644
浏览文件 @
4509ef1d
#copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
math
import
paddle
import
paddle.fluid
as
fluid
class
AlexNet
():
def
__init__
(
self
,
num_classes
=
1000
):
assert
num_classes
is
not
None
,
"In AlextNet, num_classes cannot be None"
self
.
num_classes
=
num_classes
def
__call__
(
self
,
input
):
stdv
=
1.0
/
math
.
sqrt
(
input
.
shape
[
1
]
*
11
*
11
)
layer_name
=
[
"conv1"
,
"conv2"
,
"conv3"
,
"conv4"
,
"conv5"
,
"fc6"
,
"fc7"
,
"fc8"
]
conv1
=
fluid
.
layers
.
conv2d
(
input
=
input
,
num_filters
=
64
,
filter_size
=
11
,
stride
=
4
,
padding
=
2
,
groups
=
1
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
0
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
0
]
+
"_weights"
))
pool1
=
fluid
.
layers
.
pool2d
(
input
=
conv1
,
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
0
,
pool_type
=
'max'
)
stdv
=
1.0
/
math
.
sqrt
(
pool1
.
shape
[
1
]
*
5
*
5
)
conv2
=
fluid
.
layers
.
conv2d
(
input
=
pool1
,
num_filters
=
192
,
filter_size
=
5
,
stride
=
1
,
padding
=
2
,
groups
=
1
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
1
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
1
]
+
"_weights"
))
pool2
=
fluid
.
layers
.
pool2d
(
input
=
conv2
,
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
0
,
pool_type
=
'max'
)
stdv
=
1.0
/
math
.
sqrt
(
pool2
.
shape
[
1
]
*
3
*
3
)
conv3
=
fluid
.
layers
.
conv2d
(
input
=
pool2
,
num_filters
=
384
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
groups
=
1
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
2
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
2
]
+
"_weights"
))
stdv
=
1.0
/
math
.
sqrt
(
conv3
.
shape
[
1
]
*
3
*
3
)
conv4
=
fluid
.
layers
.
conv2d
(
input
=
conv3
,
num_filters
=
256
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
groups
=
1
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
3
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
3
]
+
"_weights"
))
stdv
=
1.0
/
math
.
sqrt
(
conv4
.
shape
[
1
]
*
3
*
3
)
conv5
=
fluid
.
layers
.
conv2d
(
input
=
conv4
,
num_filters
=
256
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
groups
=
1
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
4
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
4
]
+
"_weights"
))
pool5
=
fluid
.
layers
.
pool2d
(
input
=
conv5
,
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
0
,
pool_type
=
'max'
)
drop6
=
fluid
.
layers
.
dropout
(
x
=
pool5
,
dropout_prob
=
0.5
)
stdv
=
1.0
/
math
.
sqrt
(
drop6
.
shape
[
1
]
*
drop6
.
shape
[
2
]
*
drop6
.
shape
[
3
]
*
1.0
)
fc6
=
fluid
.
layers
.
fc
(
input
=
drop6
,
size
=
4096
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
5
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
5
]
+
"_weights"
))
drop7
=
fluid
.
layers
.
dropout
(
x
=
fc6
,
dropout_prob
=
0.5
)
stdv
=
1.0
/
math
.
sqrt
(
drop7
.
shape
[
1
]
*
1.0
)
fc7
=
fluid
.
layers
.
fc
(
input
=
drop7
,
size
=
4096
,
act
=
'relu'
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
6
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
6
]
+
"_weights"
))
stdv
=
1.0
/
math
.
sqrt
(
fc7
.
shape
[
1
]
*
1.0
)
out
=
fluid
.
layers
.
fc
(
input
=
fc7
,
size
=
self
.
num_classes
,
bias_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
7
]
+
"_offset"
),
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
),
name
=
layer_name
[
7
]
+
"_weights"
))
return
out
setup.py
浏览文件 @
4509ef1d
...
...
@@ -19,7 +19,7 @@ long_description = "PaddleX. A end-to-end deeplearning model development toolkit
setuptools
.
setup
(
name
=
"paddlex"
,
version
=
'1.0.
5
'
,
version
=
'1.0.
6a1
'
,
author
=
"paddlex"
,
author_email
=
"paddlex@baidu.com"
,
description
=
long_description
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录