Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
09f433d1
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看板
提交
09f433d1
编写于
4月 03, 2018
作者:
E
Eric Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated squeezenet to meet python formatter
上级
64ebfae1
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
46 addition
and
29 deletion
+46
-29
image_classification/squeezenet.py
image_classification/squeezenet.py
+46
-29
未找到文件。
image_classification/squeezenet.py
浏览文件 @
09f433d1
import
paddle.v2
as
paddle
__all__
=
[
'squeezenet'
]
...
...
@@ -8,53 +7,63 @@ def fire_module(x, chs, squeeze=16, expand=64):
squeezer
=
paddle
.
layer
.
img_conv
(
input
=
x
,
num_channels
=
chs
,
filter_size
=
(
1
,
1
),
filter_size
=
(
1
,
1
),
num_filters
=
squeeze
,
stride
=
1
,
padding
=
(
0
,
0
),
padding
=
(
0
,
0
),
act
=
paddle
.
activation
.
Relu
(),
bias_attr
=
False
)
uno_expander
=
paddle
.
layer
.
img_conv
(
input
=
squeezer
,
filter_size
=
(
1
,
1
),
filter_size
=
(
1
,
1
),
num_filters
=
squeeze
,
stride
=
1
,
padding
=
(
0
,
0
),
padding
=
(
0
,
0
),
act
=
paddle
.
activation
.
Relu
(),
bias_attr
=
False
)
tri_expander
=
paddle
.
layer
.
img_conv
(
input
=
squeezer
,
filter_size
=
(
3
,
3
),
filter_size
=
(
3
,
3
),
num_filters
=
squeeze
,
stride
=
1
,
padding
=
(
1
,
1
),
padding
=
(
1
,
1
),
act
=
paddle
.
activation
.
Relu
(),
bias_attr
=
False
)
return
paddle
.
layer
.
concat
(
input
=
[
uno_expander
,
tri_expander
])
def
squeezenet
(
x
,
class_dim
,
include_top
=
True
):
conv1
=
paddle
.
layer
.
img_conv
(
input
=
x
,
num_channels
=
3
,
filter_size
=
(
3
,
3
),
filter_size
=
(
3
,
3
),
num_filters
=
64
,
stride
=
(
2
,
2
),
padding
=
(
0
,
0
),
stride
=
(
2
,
2
),
padding
=
(
0
,
0
),
act
=
paddle
.
activation
.
Relu
())
pool1
=
paddle
.
layer
.
img_pool
(
input
=
conv1
,
pool_size
=
3
,
stride
=
2
,
pool_type
=
paddle
.
pooling
.
Max
())
pool1
=
paddle
.
layer
.
img_pool
(
input
=
conv1
,
pool_size
=
3
,
stride
=
2
,
pool_type
=
paddle
.
pooling
.
Max
())
f1
=
fire_module
(
pool1
,
64
,
squeeze
=
16
,
expand
=
64
)
f2
=
fire_module
(
f1
,
32
,
squeeze
=
16
,
expand
=
64
)
pool2
=
paddle
.
layer
.
img_pool
(
input
=
f2
,
num_channels
=
32
,
pool_size
=
3
,
stride
=
2
,
pool_type
=
paddle
.
pooling
.
Max
())
pool2
=
paddle
.
layer
.
img_pool
(
input
=
f2
,
num_channels
=
32
,
pool_size
=
3
,
stride
=
2
,
pool_type
=
paddle
.
pooling
.
Max
())
f3
=
fire_module
(
pool2
,
32
,
squeeze
=
32
,
expand
=
128
)
f4
=
fire_module
(
f3
,
64
,
squeeze
=
32
,
expand
=
128
)
pool3
=
paddle
.
layer
.
img_pool
(
input
=
f4
,
num_channels
=
64
,
pool_size
=
3
,
stride
=
2
,
pool_type
=
paddle
.
pooling
.
Max
())
pool3
=
paddle
.
layer
.
img_pool
(
input
=
f4
,
num_channels
=
64
,
pool_size
=
3
,
stride
=
2
,
pool_type
=
paddle
.
pooling
.
Max
())
f5
=
fire_module
(
pool3
,
64
,
squeeze
=
48
,
expand
=
192
)
f6
=
fire_module
(
f5
,
96
,
squeeze
=
48
,
expand
=
192
)
...
...
@@ -66,17 +75,21 @@ def squeezenet(x, class_dim, include_top=True):
finalconv
=
paddle
.
layer
.
img_conv
(
input
=
drop
,
num_channels
=
128
,
filter_size
=
(
1
,
1
),
filter_size
=
(
1
,
1
),
num_filters
=
class_dim
,
stride
=
1
,
padding
=
(
0
,
0
),
padding
=
(
0
,
0
),
act
=
paddle
.
activation
.
Relu
(),
bias_attr
=
False
)
### TODO: I'm trying to implement a global average pooling layer here.
### When I was using this layer, I manually set the pool_size to match the
### input dimensions. I saw that PaddleFluid has global pooling and wasn't
### sure what normal Paddle's equivalent is.
gavg
=
paddle
.
layer
.
img_pool
(
input
=
finalconv
,
pool_size
=
8
,
stride
=
1
,
pool_type
=
paddle
.
pooling
.
Avg
())
gavg
=
paddle
.
layer
.
img_pool
(
input
=
finalconv
,
pool_size
=
8
,
stride
=
1
,
pool_type
=
paddle
.
pooling
.
Avg
())
out
=
paddle
.
layer
.
fc
(
input
=
finalconv
,
size
=
class_dim
,
act
=
paddle
.
activation
.
Softmax
())
...
...
@@ -85,9 +98,13 @@ def squeezenet(x, class_dim, include_top=True):
### When I was using this layer, I manually set the pool_size to match the
### input dimensions. I saw that PaddleFluid has global pooling and wasn't
### sure what normal Paddle's equivalent is.
gavg
=
paddle
.
layer
.
img_pool
(
input
=
f8
,
num_channels
=
128
,
pool_size
=
8
,
stride
=
1
,
pool_type
=
paddle
.
pooling
.
Avg
())
gavg
=
paddle
.
layer
.
img_pool
(
input
=
f8
,
num_channels
=
128
,
pool_size
=
8
,
stride
=
1
,
pool_type
=
paddle
.
pooling
.
Avg
())
out
=
paddle
.
layer
.
fc
(
input
=
f8
,
size
=
class_dim
,
act
=
paddle
.
activation
.
Softmax
())
return
out
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录