Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
Tensorflow Deep Learning
提交
ca843cc5
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 搜索 >>
提交
ca843cc5
编写于
8月 21, 2022
作者:
别团等shy哥发育
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ECA-Net通道注意力机制复现
ECA-ResNet50花朵识别
上级
ac636c7a
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
48 addition
and
7 deletion
+48
-7
.gitignore
.gitignore
+1
-0
循环神经网络/Attention/图像中的注意力机制/ECANet.py
循环神经网络/Attention/图像中的注意力机制/ECANet.py
+9
-7
经典网络/ECANet/ECA-ResNet50花朵识别.ipynb
经典网络/ECANet/ECA-ResNet50花朵识别.ipynb
+0
-0
经典网络/ECANet/ECANet-block.py
经典网络/ECANet/ECANet-block.py
+38
-0
经典网络/ECANet/img/ECANet-block.png
经典网络/ECANet/img/ECANet-block.png
+0
-0
未找到文件。
.gitignore
浏览文件 @
ca843cc5
...
...
@@ -36,3 +36,4 @@
/经典网络/ShuffleNet/checkpoint/
/经典网络/ShuffleNet/checkpoint_v2/
/经典网络/ResNext/checkpoint/
/经典网络/ECANet/checkpoint/
循环神经网络/Attention/图像中的注意力机制/ECANet.py
浏览文件 @
ca843cc5
import
math
import
tensorflow
as
tf
from
keras
import
backend
as
K
from
keras.layers
import
(
Activation
,
Add
,
Concatenate
,
Conv1D
,
Conv2D
,
Dense
,
GlobalAveragePooling2D
,
GlobalMaxPooling2D
,
Lambda
,
BatchNormalization
,
Reshape
,
multiply
,
Input
)
...
...
@@ -10,16 +9,18 @@ from keras.models import Model
ECA模块的思想是非常简单的,它去除了原来SE模块中的全连接层,
直接在全局平均池化之后的特征上通过一个1D卷积进行学习。
'''
def
eca_block
(
input_feature
,
b
=
1
,
gamma
=
2
,
name
=
""
):
channel
=
input_feature
.
_keras_shape
[
-
1
]
def
ECA_Block
(
input_feature
,
b
=
1
,
gamma
=
2
,
name
=
""
):
channel
=
input_feature
.
shape
[
-
1
]
# 根据公式计算自适应卷积核大小
kernel_size
=
int
(
abs
((
math
.
log
(
channel
,
2
)
+
b
)
/
gamma
))
# 如果是kernel_size是偶数,就使用,否则变成偶数
kernel_size
=
kernel_size
if
kernel_size
%
2
else
kernel_size
+
1
# [c]
avg_pool
=
GlobalAveragePooling2D
()(
input_feature
)
x
=
GlobalAveragePooling2D
()(
input_feature
)
# [c,1]
x
=
Reshape
((
-
1
,
1
))(
avg_pool
)
x
=
Reshape
((
-
1
,
1
))(
x
)
#
x
=
Conv1D
(
1
,
kernel_size
=
kernel_size
,
padding
=
"same"
,
name
=
"eca_layer_"
+
str
(
name
),
use_bias
=
False
,
)(
x
)
x
=
Conv1D
(
1
,
kernel_size
=
kernel_size
,
padding
=
"same"
,
use_bias
=
False
,
name
=
"eca_layer_"
+
str
(
name
)
)(
x
)
x
=
Activation
(
'sigmoid'
)(
x
)
# [c,1]=>[1,1,c]
x
=
Reshape
((
1
,
1
,
-
1
))(
x
)
...
...
@@ -29,6 +30,6 @@ def eca_block(input_feature, b=1, gamma=2, name=""):
if
__name__
==
'__main__'
:
inputs
=
Input
([
26
,
26
,
512
])
x
=
eca_b
lock
(
inputs
)
x
=
ECA_B
lock
(
inputs
)
model
=
Model
(
inputs
,
x
)
model
.
summary
()
\ No newline at end of file
经典网络/ECANet/ECA-ResNet50花朵识别.ipynb
0 → 100644
浏览文件 @
ca843cc5
此差异已折叠。
点击以展开。
经典网络/ECANet/ECANet-block.py
0 → 100644
浏览文件 @
ca843cc5
import
tensorflow
as
tf
import
math
from
tensorflow.keras.layers
import
GlobalAveragePooling2D
,
Conv1D
,
Reshape
,
Activation
,
multiply
from
tensorflow.keras.layers
import
Input
from
tensorflow.keras.models
import
Model
from
plot_model
import
plot_model
'''
ECA模块的思想是非常简单的,它去除了原来SE模块中的全连接层,
直接在全局平均池化之后的特征上通过一个1D卷积进行学习。
'''
def
eca_block
(
input_feature
,
b
=
1
,
gamma
=
2
,
name
=
""
):
channel
=
input_feature
.
shape
[
-
1
]
# 根据公式计算自适应卷积核大小
kernel_size
=
int
(
abs
((
math
.
log
(
channel
,
2
)
+
b
)
/
gamma
))
# 如果是kernel_size是偶数,就使用,否则变成偶数
kernel_size
=
kernel_size
if
kernel_size
%
2
else
kernel_size
+
1
# [c]
x
=
GlobalAveragePooling2D
()(
input_feature
)
# [c,1]
x
=
Reshape
((
-
1
,
1
))(
x
)
#
x
=
Conv1D
(
1
,
kernel_size
=
kernel_size
,
padding
=
"same"
,
use_bias
=
False
,
name
=
"eca_layer_"
+
str
(
name
))(
x
)
x
=
Activation
(
'sigmoid'
)(
x
)
# [c,1]=>[1,1,c]
x
=
Reshape
((
1
,
1
,
-
1
))(
x
)
output
=
multiply
([
input_feature
,
x
])
return
output
if
__name__
==
'__main__'
:
inputs
=
Input
([
26
,
25
,
512
])
x
=
eca_block
(
inputs
)
model
=
Model
(
inputs
,
x
)
model
.
summary
()
plot_model
(
model
,
to_file
=
'img/ECANet-block.png'
)
\ No newline at end of file
经典网络/ECANet/img/ECANet-block.png
0 → 100644
浏览文件 @
ca843cc5
29.8 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录