Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_40195168达庆意
keras
提交
14ff5175
K
keras
项目概览
weixin_40195168达庆意
/
keras
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
keras
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
14ff5175
编写于
5月 18, 2018
作者:
T
Taehoon Lee
提交者:
GitHub
5月 18, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix NASNet (#10209)
* Fix NASNet * Update weight files
上级
b8ac7e07
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
37 deletion
+36
-37
keras/applications/nasnet.py
keras/applications/nasnet.py
+36
-37
未找到文件。
keras/applications/nasnet.py
浏览文件 @
14ff5175
...
...
@@ -60,10 +60,10 @@ from ..applications.inception_v3 import preprocess_input
from
..applications.imagenet_utils
import
decode_predictions
from
..
import
backend
as
K
NASNET_MOBILE_WEIGHT_PATH
=
'https://github.com/
fchollet/deep-learning-models/releases/download/v0.8
/NASNet-mobile.h5'
NASNET_MOBILE_WEIGHT_PATH_NO_TOP
=
'https://github.com/
fchollet/deep-learning-models/releases/download/v0.8
/NASNet-mobile-no-top.h5'
NASNET_LARGE_WEIGHT_PATH
=
'https://github.com/
fchollet/deep-learning-models/releases/download/v0.8
/NASNet-large.h5'
NASNET_LARGE_WEIGHT_PATH_NO_TOP
=
'https://github.com/
fchollet/deep-learning-models/releases/download/v0.8
/NASNet-large-no-top.h5'
NASNET_MOBILE_WEIGHT_PATH
=
'https://github.com/
titu1994/Keras-NASNet/releases/download/v1.2
/NASNet-mobile.h5'
NASNET_MOBILE_WEIGHT_PATH_NO_TOP
=
'https://github.com/
titu1994/Keras-NASNet/releases/download/v1.2
/NASNet-mobile-no-top.h5'
NASNET_LARGE_WEIGHT_PATH
=
'https://github.com/
titu1994/Keras-NASNet/releases/download/v1.2
/NASNet-large.h5'
NASNET_LARGE_WEIGHT_PATH_NO_TOP
=
'https://github.com/
titu1994/Keras-NASNet/releases/download/v1.2
/NASNet-large-no-top.h5'
def
NASNet
(
input_shape
=
None
,
...
...
@@ -102,7 +102,7 @@ def NASNet(input_shape=None,
- P is the number of penultimate filters
stem_block_filters: Number of filters in the initial stem block
skip_reduction: Whether to skip the reduction step at the tail
end of the network.
Set to `False` for CIFAR models.
end of the network.
filter_multiplier: Controls the width of the network.
- If `filter_multiplier` < 1.0, proportionally decreases the number
of filters in each layer.
...
...
@@ -210,24 +210,18 @@ def NASNet(input_shape=None,
channel_dim
=
1
if
K
.
image_data_format
()
==
'channels_first'
else
-
1
filters
=
penultimate_filters
//
24
if
not
skip_reduction
:
x
=
Conv2D
(
stem_block_filters
,
(
3
,
3
),
strides
=
(
2
,
2
),
padding
=
'valid'
,
use_bias
=
False
,
name
=
'stem_conv1'
,
kernel_initializer
=
'he_normal'
)(
img_input
)
else
:
x
=
Conv2D
(
stem_block_filters
,
(
3
,
3
),
strides
=
(
1
,
1
),
padding
=
'same'
,
use_bias
=
False
,
name
=
'stem_conv1'
,
kernel_initializer
=
'he_normal'
)(
img_input
)
x
=
Conv2D
(
stem_block_filters
,
(
3
,
3
),
strides
=
(
2
,
2
),
padding
=
'valid'
,
use_bias
=
False
,
name
=
'stem_conv1'
,
kernel_initializer
=
'he_normal'
)(
img_input
)
x
=
BatchNormalization
(
axis
=
channel_dim
,
momentum
=
0.9997
,
epsilon
=
1e-3
,
name
=
'stem_bn1'
)(
x
)
p
=
None
if
not
skip_reduction
:
# imagenet / mobile mode
x
,
p
=
_reduction_a_cell
(
x
,
p
,
filters
//
(
filter_multiplier
**
2
),
block_id
=
'stem_1'
)
x
,
p
=
_reduction_a_cell
(
x
,
p
,
filters
//
filter_multiplier
,
block_id
=
'stem_2'
)
x
,
p
=
_reduction_a_cell
(
x
,
p
,
filters
//
(
filter_multiplier
**
2
),
block_id
=
'stem_1'
)
x
,
p
=
_reduction_a_cell
(
x
,
p
,
filters
//
filter_multiplier
,
block_id
=
'stem_2'
)
for
i
in
range
(
num_blocks
):
x
,
p
=
_normal_a_cell
(
x
,
p
,
filters
,
block_id
=
'%d'
%
(
i
))
...
...
@@ -274,27 +268,32 @@ def NASNet(input_shape=None,
if
weights
==
'imagenet'
:
if
default_size
==
224
:
# mobile version
if
include_top
:
weight_path
=
NASNET_MOBILE_WEIGHT_PATH
model_name
=
'nasnet_mobile.h5'
weights_path
=
get_file
(
'nasnet_mobile.h5'
,
NASNET_MOBILE_WEIGHT_PATH
,
cache_subdir
=
'models'
,
file_hash
=
'020fb642bf7360b370c678b08e0adf61'
)
else
:
weight_path
=
NASNET_MOBILE_WEIGHT_PATH_NO_TOP
model_name
=
'nasnet_mobile_no_top.h5'
weights_file
=
get_file
(
model_name
,
weight_path
,
cache_subdir
=
'models'
)
model
.
load_weights
(
weights_file
)
weights_path
=
get_file
(
'nasnet_mobile_no_top.h5'
,
NASNET_MOBILE_WEIGHT_PATH_NO_TOP
,
cache_subdir
=
'models'
,
file_hash
=
'1ed92395b5b598bdda52abe5c0dbfd63'
)
model
.
load_weights
(
weights_path
)
elif
default_size
==
331
:
# large version
if
include_top
:
weight_path
=
NASNET_LARGE_WEIGHT_PATH
model_name
=
'nasnet_large.h5'
weights_path
=
get_file
(
'nasnet_large.h5'
,
NASNET_LARGE_WEIGHT_PATH
,
cache_subdir
=
'models'
,
file_hash
=
'11577c9a518f0070763c2b964a382f17'
)
else
:
weight
_path
=
NASNET_LARGE_WEIGHT_PATH_NO_TOP
model_name
=
'nasnet_large_no_top.h5'
weights_file
=
get_file
(
model_name
,
weight_path
,
cache_subdir
=
'models
'
)
model
.
load_weights
(
weights_
file
)
weight
s_path
=
get_file
(
'nasnet_large_no_top.h5'
,
NASNET_LARGE_WEIGHT_PATH_NO_TOP
,
cache_subdir
=
'models'
,
file_hash
=
'd81d89dc07e6e56530c4e77faddd61b5
'
)
model
.
load_weights
(
weights_
path
)
else
:
raise
ValueError
(
'ImageNet weights can only be loaded with NASNetLarge'
...
...
@@ -364,7 +363,7 @@ def NASNetLarge(input_shape=None,
penultimate_filters
=
4032
,
num_blocks
=
6
,
stem_block_filters
=
96
,
skip_reduction
=
Fals
e
,
skip_reduction
=
Tru
e
,
filter_multiplier
=
2
,
include_top
=
include_top
,
weights
=
weights
,
...
...
@@ -630,7 +629,7 @@ def _reduction_a_cell(ip, p, filters, block_id=None):
x1_1
=
_separable_conv_block
(
h
,
filters
,
(
5
,
5
),
strides
=
(
2
,
2
),
block_id
=
'reduction_left1_%s'
%
block_id
)
x1_2
=
_separable_conv_block
(
p
,
filters
,
(
7
,
7
),
strides
=
(
2
,
2
),
block_id
=
'reduction_1_%s'
%
block_id
)
block_id
=
'reduction_
right
1_%s'
%
block_id
)
x1
=
add
([
x1_1
,
x1_2
],
name
=
'reduction_add_1_%s'
%
block_id
)
with
K
.
name_scope
(
'block_2'
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录