1.介绍

本文整合了部分深度残差收缩网络以及残差神经网络现有的2D及1D版本资源,并给出TensorFlow&Keras环境下的1D ResNet和DRSN程序和使用示例。

2.资源整合

深度残差收缩网络:
-介绍:http://t.csdn.cn/DvnBL
-(pytorch,2D)https://cloud.tencent.com/developer/article/1813376
-(pytorch,2D)https://zhuanlan.zhihu.com/p/337346575
-(pytorch,2D)https://blog.csdn.net/weixin_47174159/article/details/115409058
-(Tensorflow2.0&Keras,2D)https://blog.csdn.net/qq_36758914/article/details/109452735
-(pytorch,1D)https://github.com/liguge/Deep-Residual-Shrinkage-Networks-for-intelligent-fault-diagnosis-DRSN-
-(官方,TFLearn-1D、TensorFlow&Keras-2D、TFLearn-2D)https://github.com/zhao62/Deep-Residual-Shrinkage-Networks

残差神经网络

-(pytorch,1D)https://github.com/StChenHaoGitHub/1D-deeplearning-model-LeNet-AlexNet-ZFNet-VGG-GoogLeNet-ResNet-DenseNet
-(TensorFlow,1D)https://github.com/ralasun/tensorflow-resnet-1d/blob/master/Resnet.ipynb
-(Keras,2D)https://keras.io/api/applications/resnet/#resnet50v2-function

3.ResNet-1D

修改内容:参考DRSN风格,以keras.applications.ResNet50V21为基础,将2D操作更改为1D操作。

代码片段:复制以下内容或前往github下载https://github.com/M73ACat/ResNet-1D-DRSN-1D
示例结构图,参考2

图 文献2中的模型结构图
from keras.layers import (Activation, Add, BatchNormalization, Conv1D, Dense,GlobalAveragePooling1D, Input)
from keras.models import Model
from keras.optimizers import Nadamdef res_block(x, filters, block_nums, kernel_size=3, stride=1):"""A residual block.Arguments:x: input tensor.filters: integer, filters of the bottleneck layer.block_nums: integer, numbers of block. kernel_size: default 3, kernel size of the bottleneck layer.stride: default 1, stride of the first layer.Returns:Output tensor for the residual block."""for _ in range(block_nums):preact = BatchNormalization(epsilon=1.001e-5)(x)preact = Activation('relu')(preact)shortcut = Conv1D(4 * filters, 1, strides=stride,padding='same')(preact)x = Conv1D(filters, 1, strides=1, use_bias=False)(preact)x = BatchNormalization(epsilon=1.001e-5)(x)x = Activation('relu')(x)x = Conv1D(filters,kernel_size,strides=stride,use_bias=False,padding='same')(x)x = BatchNormalization(epsilon=1.001e-5)(x)x = Activation('relu')(x)x = Conv1D(4 * filters, 1)(x)x = Add()([shortcut, x])return x

使用示例(建立图1所示ResNet模型):

inputs = 2048
outputs = 8x_input  = Input(shape=(inputs,1))
x = Conv1D(4,3,2,padding='same')(x_input)x = res_block(x,filters=4,block_nums=1,stride=2)
x = res_block(x,filters=4,block_nums=3,stride=1)x = res_block(x,filters=8,block_nums=1,stride=2)
x = res_block(x,filters=8,block_nums=3,stride=1)x = res_block(x,filters=16,block_nums=1,stride=2)
x = res_block(x,filters=16,block_nums=3,stride=1)x = BatchNormalization()(x)
x = Activation('relu')(x)
x = GlobalAveragePooling1D()(x)x = Dense(outputs,activation='softmax')(x)model = Model(inputs=x_input,outputs=x)
optimizers = Nadam(lr=1e-5)
model.compile(optimizer = optimizers, loss= 'categorical_crossentropy',metrics=['accuracy'])
model.summary()

4.DRSN-1D

修改内容:以DRSN Keras2D3为基础,将2D操作更改为1D操作。

代码片段:复制以下内容或前往github下载https://github.com/M73ACat/ResNet-1D-DRSN-1D

import keras
from keras import backend as K
from keras.layers import (Activation, AveragePooling1D, BatchNormalization,Conv1D, Dense, GlobalAveragePooling1D, Input)
from keras.layers.core import Lambda
from keras.models import Model
from keras.optimizers import Nadam
from keras.regularizers import l2def abs_backend(inputs):return K.abs(inputs)def expand_dim_backend(inputs):return K.expand_dims(inputs,1)def sign_backend(inputs):return K.sign(inputs)def pad_backend(inputs, in_channels, out_channels):pad_dim = (out_channels - in_channels)//2inputs = K.expand_dims(inputs)inputs = K.spatial_2d_padding(inputs,padding=((0,0),(pad_dim,pad_dim)))return K.squeeze(inputs,-1)def residual_shrinkage_block(incoming, nb_blocks, out_channels, downsample=False,downsample_strides=2):"""A residual_shrinkage_block.Arguments:incoming: input tensor.nb_blocks: integer, numbers of block. out_channels: integer, filters of the conv1d layer.downsample: default False, downsample or not.downsample_strides: default 2, stride of the first layer.Returns:Output tensor for the residual block."""residual = incomingin_channels = incoming.get_shape().as_list()[-1]for _ in range(nb_blocks):identity = residualif not downsample:downsample_strides = 1residual = BatchNormalization()(residual)residual = Activation('relu')(residual)residual = Conv1D(out_channels, 3, strides=downsample_strides, padding='same', kernel_initializer='he_normal', kernel_regularizer=l2(1e-4))(residual)residual = BatchNormalization()(residual)residual = Activation('relu')(residual)residual = Conv1D(out_channels, 3, padding='same', kernel_initializer='he_normal', kernel_regularizer=l2(1e-4))(residual)# Calculate global meansresidual_abs = Lambda(abs_backend)(residual)abs_mean = GlobalAveragePooling1D()(residual_abs)# Calculate scaling coefficientsscales = Dense(out_channels, activation=None, kernel_initializer='he_normal', kernel_regularizer=l2(1e-4))(abs_mean)scales = BatchNormalization()(scales)scales = Activation('relu')(scales)scales = Dense(out_channels, activation='sigmoid', kernel_regularizer=l2(1e-4))(scales)scales = Lambda(expand_dim_backend)(scales)# Calculate thresholdsthres = keras.layers.multiply([abs_mean, scales])# Soft thresholdingsub = keras.layers.subtract([residual_abs, thres])zeros = keras.layers.subtract([sub, sub])n_sub = keras.layers.maximum([sub, zeros])residual = keras.layers.multiply([Lambda(sign_backend)(residual), n_sub])# Downsampling using the pooL-size of (1, 1)if downsample_strides > 1:identity = AveragePooling1D(pool_size=1, strides=2)(identity)# Zero_padding or Conv1D to match channelsif in_channels != out_channels:""" padding """identity = Lambda(pad_backend, arguments={'in_channels':in_channels,'out_channels':out_channels})(identity)""" Conv1D """# identity = Conv1D(out_channels,1,strides=1,padding='same')(identity)residual = keras.layers.add([residual, identity])return residual

使用示例(建立图1所示DRSN模型):

inputs = 2048
outputs = 8x_input = Input(shape=(inputs,1))
x = Conv1D(4,3,2,padding='same')(x_input)
x = residual_shrinkage_block(x, 1, 4, downsample=True)
x = residual_shrinkage_block(x, 3, 4, downsample=False)x = residual_shrinkage_block(x, 1, 8, downsample=True)
x = residual_shrinkage_block(x, 3, 8, downsample=False)x = residual_shrinkage_block(x, 1, 16, downsample=True)
x = residual_shrinkage_block(x, 3, 16, downsample=False)x = BatchNormalization()(x)
x = Activation('relu')(x)
x = GlobalAveragePooling1D()(x)x = Dense(outputs,activation='softmax')(x)model = Model(inputs=x_input,outputs=x)
optimizers = Nadam(lr=1e-5)
model.compile(optimizer = optimizers, loss= 'categorical_crossentropy',metrics=['accuracy'])
model.summary()

参考文献


  1. https://keras.io/api/applications/resnet/#resnet50v2-function ↩︎

  2. ZHAO M., ZHONG S., FU X., et al. Deep Residual Shrinkage Networks for Fault Diagnosis[J]. IEEE Transactions on Industrial Informatics, 2020, 16(7):4681-4690. ↩︎

  3. https://github.com/zhao62/Deep-Residual-Shrinkage-Networks/blob/master/DRSN_Keras.py ↩︎

keras 一维残差神经网络(1D-ResNet)和一维深度残差收缩网络(1D-DRSN)相关推荐

  1. 基于FPGA的一维卷积神经网络CNN的实现(三)训练网络搭建及参数导出(附代码)

    训练网络搭建 环境:Pytorch,Pycham,Matlab. 说明:该网络反向传播是通过软件方式生成,FPGA内部不进行反向传播计算. 该节通过Python获取训练数据集,并通过Pytorch框架 ...

  2. 理解残差神经网络(Resnet)

    理解残差神经网络(Resnet) 目的 DNN在超过一定深度后,就会产生退化(degradation),在训练集和测试集的准确率都变低.一味地加深深度反而有不利的影响.很难找到一个合适的深度.如果可以 ...

  3. keras构建卷积神经网络_通过此简单教程学习在网络上构建卷积神经网络

    keras构建卷积神经网络 by John David Chibuk 约翰·大卫·奇布克(John David Chibuk) 通过此简单教程学习在网络上构建卷积神经网络 (Learn to buil ...

  4. 残差神经网络(ResNet)理解

    关键词:退化现象 (Degradation).快捷连接(Shortcut connection) 退化现象:随着网络层不断的加深,模型的准确率先是不断的提高,达到最大值(准确率饱和),然后随着网络深度 ...

  5. 对残差神经网络,resnet的理解

    参考资料 背景:遇到了挑战,随着网络深度的增加,模型的预测结果并没有编号.按道理,如果深度为20的网络已经达到不错的效果的话,深度增加到30层,后10层什么都不做,也能达到和20层一样的效果才对.但是 ...

  6. CNN 常用的几个模型 LeNet5 AlexNet VGGNet Google Inception Net 微软ResNet残差神经网络

    LeNet5 LeNet-5:是Yann LeCun在1998年设计的用于手写数字识别的卷积神经网络,当年美国大多数银行就是用它来识别支票上面的手写数字的,它是早期卷积神经网络中最有代表性的实验系统之 ...

  7. 基于FPGA的一维卷积神经网络CNN的实现(二)资源分配

    资源分配 环境:Vivado2019.2. Part:xcku040-ffva1156-2-i,内嵌DSP个数 1920个,BRAM 600个也就是21.1Mb. 说明:通过识别加高斯白噪声的正弦波. ...

  8. 基于FPGA的一维卷积神经网络CNN的实现(一)框架

    理论建立与效果展示 环境:Vivado2019.2. Part:xcku040-ffva1156-2-i,内嵌DSP个数 1920个,BRAM 600个也就是21.1Mb. 说明:通过识别加高斯白噪声 ...

  9. 残差神经网络Resnet(MNIST数据集tensorflow实现)

    简述: 残差神经网络(ResNet)主要是用于搭建深度的网络结构模型 (一)优势: 与传统的神经网络相比残差神经网络具有更好的深度网络构建能力,能避免因为网络层次过深而造成的梯度弥散和梯度爆炸. (二 ...

  10. 【深度学习之ResNet】——深度残差网络—ResNet总结

    目录 论文名称:Deep Residual Learning for Image Recognition 摘要: 1.引言 2.为什么会提出ResNet残差网络呢? 3.深度残差网络结构学习(Deep ...

最新文章

  1. 谷歌发布深度学习新算法,适用于真实机器人的技能学习
  2. BZOJ 1821: [JSOI2010]Group 部落划分 Group【MST】
  3. autofac 作用域_控制作用域和生命周期
  4. PYTHON——TCPUDP:Socket初识
  5. python 文件指针及文件覆盖
  6. ES读写为何速度那么快(史上最全面总结)
  7. python 1+2+3+4+5+6+7+8+9累加求和_求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!+...+N! N阶阶乘求和算法 JAVA C Python...
  8. 解决ajax无法给js全局变量赋值的问题
  9. 【codevs5709】01背包
  10. Java中List的使用
  11. 超详细Hexo+Github博客搭建小白教程
  12. 简单的避免idea自动导入 *
  13. [工具] Seer 代码预览器
  14. 搭建RoacketChat(v4.5.1)聊天服务。有生之年,我也能使用上自己搭建的聊天服务器
  15. 【下载】快速通过Python笔试?学大家一样先把LeetCode答案私藏了
  16. 平行坐标图:高维数据可视化必备图形
  17. 伪C++开发连连看(补充)
  18. 静态网站生成器(开源项目)
  19. (02) Apache Felix 入门 - 02
  20. 【避坑指“难”】react-dnd引入后,.mjs文件解析错误

热门文章

  1. 75个iOS开发工具
  2. Unity HDRP材质和着色器
  3. 实现评论商品详情的评论功能
  4. android添加横幅广告,android-如何获取适用于adMob的测试广告横幅...
  5. 硅谷大牛、阿里达摩院专家,增长标杆企业都来了,这届UBDC厉害了!
  6. 毕业设计论文-基于android平台的手机订餐系统设计,毕业论文基于android的手机订餐系统的设计与实现.doc...
  7. 从鳄鱼哥尼流绘本思考,数据分析师是怎样炼成的?(一)
  8. 一个好的技术Leader,首先要分清谁是“野狗”,谁是“明星”!聊一聊,九宫格人才盘点法...
  9. 无套路免费修改简历,并推荐一个实用的简历模板
  10. C++之23种经典设计模式(一)