Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
Tensorflow Deep Learning
提交
967fa064
T
Tensorflow Deep Learning
项目概览
别团等shy哥发育
/
Tensorflow Deep Learning
9 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Tensorflow Deep Learning
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
967fa064
编写于
9月 08, 2022
作者:
别团等shy哥发育
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
NasNet架构复现--CVPR2018
上级
1d99602c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
22 deletion
+57
-22
经典网络/NasNet--CVPR2018/NasNet--手动搭建.py
经典网络/NasNet--CVPR2018/NasNet--手动搭建.py
+50
-22
经典网络/NasNet--CVPR2018/NasNet--迁移学习.py
经典网络/NasNet--CVPR2018/NasNet--迁移学习.py
+7
-0
未找到文件。
经典网络/NasNet--CVPR2018/NasNet.py
→
经典网络/NasNet--CVPR2018/NasNet
--手动搭建
.py
浏览文件 @
967fa064
...
...
@@ -2,7 +2,7 @@ import tensorflow as tf
from
tensorflow.keras
import
layers
from
tensorflow.keras.models
import
Model
from
tensorflow.keras
import
backend
from
plot_model
import
plot_model
def
correct_pad
(
inputs
,
kernel_size
):
"""返回一个元组,用于带有下采样的2D卷积的零填充.
...
...
@@ -33,7 +33,9 @@ def _adjust_block(p, # 需要修改的输入张量
block_id
=
None
):
channel_dim
=
1
if
backend
.
image_data_format
()
==
'channels_first'
else
-
1
img_dim
=
2
if
backend
.
image_data_format
()
==
'channels_first'
else
-
2
ip_shape
=
backend
.
int_shape
(
ip
)
if
p
is
not
None
:
p_shape
=
backend
.
int_shape
(
p
)
...
...
@@ -88,6 +90,7 @@ def _separable_conv_block(ip, # 输入张量
kernel_size
=
(
3
,
3
),
# 可分离卷积的内核大小
strides
=
(
1
,
1
),
# 用于下采样的跨步卷积
block_id
=
None
):
# channel_dim = 1 if backend.image_data_format() == 'channels_first' else -1
with
backend
.
name_scope
(
'separable_conv_block_%s'
%
block_id
):
x
=
layers
.
Activation
(
'relu'
)(
ip
)
if
strides
==
(
2
,
2
):
...
...
@@ -119,8 +122,8 @@ def _separable_conv_block(ip, # 输入张量
# Adds a Reduction cell for NASNet-A(原论文图4)
def
_reduction_a_cell
(
ip
,
# 输入张量
p
,
# 输入张量
def
_reduction_a_cell
(
ip
,
# 输入张量
x
p
,
# 输入张量
p
filters
,
# 输出filters的数量
block_id
=
None
):
channel_dim
=
1
if
backend
.
image_data_format
()
==
'channels_first'
else
-
1
...
...
@@ -204,6 +207,7 @@ def _normal_a_cell(ip, # 输入张量x
h
=
layers
.
Activation
(
'relu'
)(
ip
)
h
=
layers
.
Conv2D
(
filters
=
filters
,
kernel_size
=
(
1
,
1
),
strides
=
(
1
,
1
),
padding
=
'same'
,
use_bias
=
False
,
kernel_initializer
=
'he_normal'
,
...
...
@@ -232,12 +236,13 @@ def _normal_a_cell(ip, # 输入张量x
x4_1
=
layers
.
AveragePooling2D
(
pool_size
=
(
3
,
3
),
strides
=
(
1
,
1
),
padding
=
'same'
,
name
=
'normal
-
left4_%s'
%
block_id
)(
p
)
name
=
'normal
_
left4_%s'
%
block_id
)(
p
)
x4_2
=
layers
.
AveragePooling2D
(
pool_size
=
(
3
,
3
),
strides
=
(
1
,
1
),
padding
=
'same'
,
name
=
'normal_right4_%s'
%
block_id
)(
p
)
x4
=
layers
.
add
([
x4_1
,
x4_2
],
name
=
'normal_add_4_%s'
%
block_id
)
with
backend
.
name_scope
(
'block_5'
):
x5
=
_separable_conv_block
(
h
,
filters
,
block_id
=
'normal_left5_%s'
%
block_id
)
x5
=
layers
.
add
([
x5
,
h
],
name
=
'normal_add_5_%s'
%
block_id
)
...
...
@@ -262,7 +267,7 @@ def NASNet(input_shape=None, # 输入shape
if
default_size
is
None
:
default_size
=
331
img_input
=
layers
.
Input
(
shape
=
input_shape
)
inputs
=
img_input
inputs
=
img_input
filters
=
penultimate_filters
//
24
...
...
@@ -293,27 +298,28 @@ def NASNet(input_shape=None, # 输入shape
p
,
filters
*
filter_multiplier
**
2
,
block_id
=
'reduce_%d'
%
(
2
*
num_blocks
))
p
=
p0
if
not
skip_reduction
else
p
p
=
p0
if
not
skip_reduction
else
p
for
i
in
range
(
num_blocks
):
x
,
p
=
_normal_a_cell
(
x
,
p
,
filters
*
filter_multiplier
**
2
,
block_id
=
'%d'
%
(
2
*
num_blocks
+
i
+
1
))
x
=
layers
.
Activation
(
'relu'
)(
x
)
x
,
p
=
_normal_a_cell
(
x
,
p
,
filters
*
filter_multiplier
**
2
,
block_id
=
'%d'
%
(
2
*
num_blocks
+
i
+
1
))
x
=
layers
.
Activation
(
'relu'
)(
x
)
if
include_top
:
x
=
layers
.
GlobalAveragePooling2D
()(
x
)
x
=
layers
.
Dense
(
classes
,
activation
=
classifier_activation
,
name
=
'predictions'
)(
x
)
x
=
layers
.
GlobalAveragePooling2D
()(
x
)
x
=
layers
.
Dense
(
classes
,
activation
=
classifier_activation
,
name
=
'predictions'
)(
x
)
else
:
if
pooling
==
'avg'
:
x
=
layers
.
GlobalAveragePooling2D
()(
x
)
elif
pooling
==
'max'
:
x
=
layers
.
GlobalMaxPooling2D
()(
x
)
model
=
Model
(
inputs
,
x
,
name
=
'NASNet'
)
if
pooling
==
'avg'
:
x
=
layers
.
GlobalAveragePooling2D
()(
x
)
elif
pooling
==
'max'
:
x
=
layers
.
GlobalMaxPooling2D
()(
x
)
model
=
Model
(
inputs
,
x
,
name
=
'NASNet'
)
return
model
def
NASNetMobile
(
input_shape
=
None
,
include_top
=
True
,
weights
=
'imagenet'
,
...
...
@@ -332,6 +338,29 @@ def NASNetMobile(input_shape=None,
pooling
=
pooling
,
classes
=
classes
,
default_size
=
224
)
def
NASNetLarge
(
input_shape
=
None
,
include_top
=
True
,
weights
=
'imagenet'
,
input_tensor
=
None
,
pooling
=
None
,
classes
=
1000
,
classifier_activation
=
'softmax'
):
return
NASNet
(
input_shape
,
penultimate_filters
=
4032
,
num_blocks
=
6
,
stem_block_filters
=
96
,
skip_reduction
=
True
,
filter_multiplier
=
2
,
include_top
=
include_top
,
weights
=
weights
,
input_tensor
=
input_tensor
,
pooling
=
pooling
,
classes
=
classes
,
default_size
=
331
,
classifier_activation
=
classifier_activation
)
if
__name__
==
'__main__'
:
model
=
NASNetMobile
(
input_shape
=
(
224
,
224
,
3
),
classes
=
1000
)
model
.
summary
()
\ No newline at end of file
model
=
NASNetMobile
(
input_shape
=
(
224
,
224
,
3
),
classes
=
1000
)
# model=NASNetLarge(input_shape=(224,224,3),classes=1000)
model
.
summary
()
# plot_model(model,to_file='img/NASNetMobile.pdf')
经典网络/NasNet--CVPR2018/NasNet--迁移学习.py
0 → 100644
浏览文件 @
967fa064
from
tensorflow.keras.applications
import
NASNetMobile
model
=
NASNetMobile
(
include_top
=
True
,
input_shape
=
(
224
,
224
,
3
),
classes
=
1000
)
model
.
summary
()
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录