论文阅读笔记(4-2)---吴恩达DNN算法分析和仿真实现

article/2025/10/20 8:11:01

算法开发

该深度卷积神经网络以原始心电图数据(以200Hz或每秒200个样本为样本)作为输入,并且每256个样本(或每1.28秒)生成一个预测,我们称之为输出间隔。网络仅以原始心电图样本为输入,网络架构有34层:为了使这种网络的优化变得可处理,采用类似残差网络的架构进行快捷连接。该网络由16个残差块组成,每个块有两个卷积层。卷积层的过滤宽度为16和 32 ∗ 2 K 32*2^K 322K过滤器,其中K是超参,从0开始,每四个残差块增加一个。每个备用残差块对其输入进行子采样2次。在每个卷积层之前,应用批量归一化和Relui激活,采用预激活块设计。由于这种预激活块结构,网络的第一层和最后一层是特殊的。另外还在卷积层之间和非线性之后应用Dropout,概率为0.2。最终完全连接的softmax层输出12类心率时长的概率。网络是从头训练的,随机初始化权重。使用Adam optimizer,默认参数为β1= 0.9,β2= 0.999,minibatch大小为128。学习率初始化为1×10-3,并且当连续两个epoch的训练损失没有改观时其降低10倍。通过grid search和手动调整的组合来选择网络架构和优化算法的超参数。对于该体系结构,主要搜索的超参数与为卷积层的数量,卷积滤波器的大小和数量,以及残差连接的使用。实验中发现,一旦模型的深度超过八层,残差连接就很有用。论文还尝试了RNN,包括LSTM和BiRNN,但发现准确性没有提高,运行时间却大幅增加;因此,因此文章抛弃了这类模型。

仿真实现

源代码

在这里插入图片描述

原来的网络结构是用pytorch实现的,而且结构理解比较困难,这里尝试用keras实现。

config.json

{"conv_subsample_lengths": [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],"conv_filter_length": 16,"conv_num_filters_start": 32,"conv_init": "he_normal","conv_activation": "relu","conv_dropout": 0.2,"conv_num_skip": 2,"conv_increase_channels_at": 4,"learning_rate": 0.001,"batch_size": 32,}

network


def model_build(params):def zeropad(x):y = K.zeros_like(x)return K.concatenate([x, y], axis=2)def zeropad_output_shape(input_shape):shape = list(input_shape)assert len(shape) == 3shape[2] *= 2return tuple(shape)def type_1(input_data, n_filters, filter_size, max_pool_size,index):x = Conv1D(n_filters, filter_size, strides=1, padding='same', name='type_1' + '_' + 'conv_1'+str(index), kernel_initializer=params["conv_init"])(input_data)x = BatchNormalization(name='type_1'+ '_' + 'BN_1'+str(index))(x)x = Activation('relu', name='type_1'+ '_' + 'relu_1'+str(index))(x)x = Dropout(rate=0.1)(x)x = Conv1D(n_filters, filter_size, strides=1, padding='same', name='type_1'+ '_' + 'conv_2'+str(index),kernel_initializer=params["conv_init"])(x)shortcut = MaxPooling1D(pool_size=max_pool_size,name='short'+ '_' + 'max_pooling_'+str(index))(input_data)x = add([x, shortcut], name='type_1' + '_' + 'add'+str(index))return xdef type_2(input_data, n_filters, filter_size, max_pool_size,index):x = BatchNormalization(name='type_2'+ '_' + 'BN_1'+str(index))(input_data)x = Activation('relu', name='type_2'+ '_' + 'relu_1'+str(index))(x)x = Conv1D(n_filters, filter_size, strides=max_pool_size, padding='same', name='type_2'+ '_' + 'conv_1'+str(index),kernel_initializer=params["conv_init"])(x)x = BatchNormalization(name='type_2'+ '_' + 'BN_2'+str(index))(x)x = Activation('relu', name='type_2'+ '_' + 'relu_2'+str(index))(x)x = Dropout(rate=0.1)(x)x = Conv1D(n_filters, filter_size, strides=1, padding='same', name='type_2'+ '_' + 'conv_2'+str(index),kernel_initializer=params["conv_init"])(x)shortcut = MaxPooling1D(pool_size=max_pool_size,padding='same',name='short'+ '_' + 'max_pooling_'+str(index))(input_data)if index in (5,9,13):shortcut = Lambda(zeropad, output_shape=zeropad_output_shape)(shortcut)x = add([x, shortcut], name='type_2' + str(index) + '_' + 'add')return xinput_ecg = Input(shape=(5000, 12), name='input')x = Conv1D(filters=32, kernel_size=16, strides=1, padding='same', kernel_initializer=params["conv_init"], name='conv_1')(input_ecg)x = BatchNormalization(name='BN_1')(x)x = Activation('relu', name='relu_1')(x)x = type_1(x, n_filters=params["conv_num_filters_start"], filter_size=params["conv_filter_length"], max_pool_size=1,index=1)   x = type_2(x, n_filters=params["conv_num_filters_start"], filter_size=params["conv_filter_length"], max_pool_size=2,index=2)x = type_2(x, n_filters=params["conv_num_filters_start"], filter_size=params["conv_filter_length"], max_pool_size=1,index=3)x = type_2(x, n_filters=params["conv_num_filters_start"], filter_size=params["conv_filter_length"], max_pool_size=2,index=4)x = type_2(x, n_filters=params["conv_num_filters_start"]*2, filter_size=params["conv_filter_length"], max_pool_size=1,index=5)x = type_2(x, n_filters=params["conv_num_filters_start"]*2, filter_size=params["conv_filter_length"], max_pool_size=2,index=6)x = type_2(x, n_filters=params["conv_num_filters_start"]*2, filter_size=params["conv_filter_length"]//2, max_pool_size=1,index=7)x = type_2(x, n_filters=params["conv_num_filters_start"]*2, filter_size=params["conv_filter_length"]//2, max_pool_size=2,index=8)x = type_2(x, n_filters=params["conv_num_filters_start"]*4, filter_size=params["conv_filter_length"]//2, max_pool_size=1,index=9)x = type_2(x, n_filters=params["conv_num_filters_start"]*4, filter_size=params["conv_filter_length"]//2, max_pool_size=2,index=10)x = type_2(x, n_filters=params["conv_num_filters_start"]*4, filter_size=params["conv_filter_length"]//2, max_pool_size=1,index=11)x = type_2(x, n_filters=params["conv_num_filters_start"]*4, filter_size=params["conv_filter_length"]//2, max_pool_size=2,index=12)x = type_2(x, n_filters=params["conv_num_filters_start"]*8, filter_size=params["conv_filter_length"]//2, max_pool_size=1,index=13)x = type_2(x, n_filters=params["conv_num_filters_start"]*8, filter_size=params["conv_filter_length"]//2, max_pool_size=2,index=14)x = type_2(x, n_filters=params["conv_num_filters_start"]*8, filter_size=params["conv_filter_length"]//2, max_pool_size=1,index=15)x = type_2(x, n_filters=params["conv_num_filters_start"]*8, filter_size=params["conv_filter_length"]//2, max_pool_size=2,index=16)x = BatchNormalization(name='BN_2')(x)x = Activation('relu', name='relu_2')(x)  #x = TimeDistributed(Dense(5, activation='softmax', name='output'))(x) x = GlobalAveragePooling1D(name='average_pooling')(x)#x = MaxPooling1D(name='max_pooling')(x)#x = Concatenate(axis=1)([x1, x2])#x = Flatten(name='flatten')(x)#全连接层#x = Dense(64,kernel_regularizer=l2(0.01), name='FC1')(x)#隐藏层#x = Activation('relu', name='Dense_relu_1')(x)#x = Dropout(rate=0.2)(x)x = Dense(12, activation='softmax', name='output')(x)model = Model(inputs=input_ecg, outputs=x)return model

http://chatgpt.dhexx.cn/article/LtMKmRip.shtml

相关文章

LightGBM的基本原理以及使用

LightGBM的基本原理以及使用 LightGBM的基本原理 LightGBM是一款常用的GBDT工具包,由微软亚研院开发,速度比XGBoost快,精度稍低 。他的设计理念是:1.单个机器在不牺牲速度的情况下,尽可能使用上更多的数据。2.多机并…

从心电信号分类过渡到心音信号分类

首先刚接手这种关于信号的分类问题,以下可能会有不对的地方,接下去通过学习会对不正确的地方进行更正或者补充。 心电信号分类参考文献:Cardiologist-LevelArrhythmiaDetectionwithConvolutionalNeuralNetworks目标:对传感器采集…

LightGBM调参

GBDT模型的另一个进化版本:LightGBM。LigthGBM是boosting集合模型中的新进成员,由微软提供,它和XGBoost一样是对GBDT的高效实现,原理上它和GBDT及XGBoost类似,都采用损失函数的负梯度作为当前决策树的残差近似值&#…

XGBoost调参步骤及常见问题

XGBoost xgboost中的基学习器除了可以是CART(gbtree)也可以是线性分类器(gblinear) xgboost在目标函数中显示的加上了正则化项,基学习为CART时,正则化项与树的叶子节点的数量T和叶子节点的值有关。 正则项…

LightGBM原理介绍

简介 是GBDT模型的一个进化版本,其主要思想是利用弱分类器(决策树)迭代训练以得到最优模型,该模型具有训练效果好、不易过拟合等优点(备注:容易出现过拟合的风险,需要限制树的最大深度来防止过…

lightbgm参数_参数调优LightGBM-商品分类-代码

1.直接调用LightGBM内嵌的cv寻找最佳的参数n_estimators(弱分类器数目) Otto商品分类数据 导入必要模型import lightgbm as lgbm import pandas as pd import numpy as np from sklearn.model_selection import GridSearchCV from sklearn.model_selection import StratifiedKF…

Xgboost回归四种调参方法及Python简单实现

前言 Xgboost对特征工程和数据处理比较友好,相比之下调参成为用好Xgboost重要的一环,本文分别从参数、调参方法、Python实现的维度进行梳理,作为调参思路的记录。 本文将关注以下几个问题: 1.Xgboost哪些参数需要调参&#xff…

Python机器学习10——梯度提升

本系列所有的代码和数据都可以从陈强老师的个人主页上下载:Python数据程序 参考书目:陈强.机器学习及Python应用. 北京:高等教育出版社, 2021. 本系列基本不讲数学原理,只从代码角度去让读者们利用最简洁的Python代码实现机器学…

【机器学习】集成学习代码练习

课程完整代码:https://github.com/fengdu78/WZU-machine-learning-course 代码修改并注释:黄海广,haiguang2000wzu.edu.cn import warnings warnings.filterwarnings("ignore") import pandas as pd from sklearn.model_selection …

Keras 1.0 与 2.0 中 Convolution1D 的区别(其实是tf1.0 2.0 区别)

1.0 Convolution1D: 一维卷积层 nb_filter: 卷积核的个数 filter_length: 每个卷积核的长度 init: 权重初始化函数名称 weights: 权重初始化 border_mode: valid, same or full 如果是‘valid ’ 进行有效的卷积,对边界数据不处理,‘same表示保留…

数据挖掘入门_Task04

线性回归模型 线性回归(Linear Regression)是利用称为线性回归方程的最小平方函数对一个或多个自变量和因变量之间关系进行建模的一种回归分析。 可以直接使用sklearn建立线性模型: from sklearn.linear_model import LinearRegression model LinearRegression(n…

task4 建模调参

1 读取数据 import pandas as pd import numpy as np import warnings warnings.filterwarnings(ignore)note: 将整型变量的类型尽量压缩,逐步判断并转化为int8,int16,int32,int64 def reduce_mem_usage(df):""" iterate through all the columns …

深度学习与神经网络(七)——卷积神经网络之池化pooling 上采样upsample与降采样downsample(下采样)(subsample)(nn.MaxPool2d)

池化层pooling与采样 upsample与downsample upsample(interpolating)是上采样,是图片的放大 unpool是上采样的一种 downsample(subsample)是下采样,是图片的缩小 在卷积神经网络中使用的采样方式就是pooling,有点类似下采样,但不太…

有放回随机抽样:重要参数subsample

原理透析 确认了有多少棵树之后,我们来思考一个问题:建立了众多的树,怎么就能够保证模型整体的效果变强呢?集成的目的是为了模型在样本上能表现出更好的效果,所以对于所有的提升集成算法,每构建一个评估器&…

Subsample子采样(CloudCompare软件)

之前一直以为CC软件里面没有子采样这个功能,不过找了找之后发现还是有的,感觉这些小的功能挺有意思的,所以也就记录一下。 文章目录 一、Random采样二、space采样三、octree采样四、小结 一、Random采样 有时候我总是喜欢使用一些小的样本来…

Android Content Providers(三)——Contacts Provider

接着上篇Android Content Providers(二)——Contacts Provider继续,接下来要说明的是顶层的Contacts,Contacts是聚合联系人表,在之前讨论的RawContacts是原始联系人表,在Android通讯录的架构中,…

Android contacts 的详解

一、包结构分析 相关联的的projects 1、Contacts相关 联系人分为了Contacts和ContactsCommon,与sim卡联系人相关的是在Telephony中,数据库是在ContactsProvider,apk要push到/system/priv-app/Contacts下 2、Contacts的包结构 3、ContactsComm…

由ContactsProvider的升级引发的OTA首次开机卡白米问题分析

上午的宁静被一个OTA卡白米问题打破,接下来不断有人反馈不同机型都复现了OTA后卡白米,10.9号OTA升级到10.10号的版本,全机型问题,线刷没有问题,好吧,接下来就根据这些信息开始初步分析log吧! 初…

Android Content Providers(二)——Contacts Provider

Contacts Provider是Android中一个强大并且灵活的组件,负责管理系统通讯录的数据,对外提供访问接口来对系统通讯录进行访问和操作。 以下是Contacts Provider的组织结构图: 可以看出Android的系统通讯录是三层架构,通过URI进行访…

API Guides Contacts Provider (二)

Data From Sync Adapters 用户直接输入联系人的数据到设备中,但是也可以通过sync adapters从服务器上获取联系人的数据。sync adapter 会自动同步设备和服务器上的数据。sync adapter运行在后台,由系统来控制。系统调用ContentResolver去管理数据。 在A…