Tensorflow实战学习(三十)【实现AlexNet】

TensorFlow的实战(详细代码) TensorFlow中的计算可表示为一个有向图(计算图),其中每个运算操作为一个节点,每个节点可有任意多个输入和输出;在计算图的边中流动(flow)的数据被称为张量(tensor),tensor在计算图中flow,故命名为TensorFlow;Session是用户使用TensorFlow的交互式接口,可通过Session的Extend方法添加新的节点和边;反复执行计算图时一般的tensor不会被持续保留,Variable中的数据tensor会被保存。自编码器,即可以使用自身的高阶特征编码自己。 阅读详情

ILSVRC(ImageNet Large Scale Visual Recognition Challenge)分类比赛。AlexNet 2012年冠军(top-5错误率16.4%,额外数据15.3%,8层神经网络)。VGGNet 2014年亚军(top-5错误率7.3%,19层神经网络)。Google Inception 2014年冠军(top-5错误率6.7%,22层神经网络)。ResNet 2015年冠军(top-5错误率3.57%,152层神经网络)。人眼错误率5.1%。卷积神经网络基本解决ImageNet数据集图片分类问题。

ImageNet,2007年斯坦福大学李飞飞教授创办,收集大量带标注信息图片数据供计算机视觉模型训练。1500万张标注高清图片,22000类,100万张标注图片主要物体定位边框。眼睛生物照相机,每200ms拍一张,3岁已经上亿张。ImageNet下载互联网10亿张图片,亚马逊土耳其机器人平台众包标注过程,167个国家5万名工作者筛选标注。每年ILSVRC比赛数据120万张图片,1000类标注。top-5、top-1分类错误率模型性能评测指标。

2012年,Hinton学生Alex Krizhevsky提出LeNet更深更宽版深度神经网络模型AlexNet。首次在CNN用ReLU、Dropout、LRN等Trick。GPU运算加速。开源GPU训红卷积神经网络CUDA代码。6亿3000万连接,6000万参数,65万神经元,5个卷积层,3个卷积层后连最大池化层,3个全连接层。top-5错误率16.4%。第二名26.2%。神经网络低谷期后第一次发声,确立深度学习(深度卷积网络)计算机视觉统治地位,推动深度学习语音识别、自然语言处理、强化学习领域拓展。

成功使用ReLU CNN激活函数,验证较深网络效果超过Sigmoid,解决梯度弥散问题。训练用Dropout随机忽略部分神经元,避免模型过拟合。CNN用重叠最大池化,避免平均池化模糊化效果,步长比池化核尺寸小,池化层输出重叠覆盖,提升特征丰富性。LRN层,创建局部神经元活动竞争机制,响应较大值变更大,抑制其他反馈较小神经元,增强模型泛化能力。CUDA加速深度卷积网络训练,并行计算大量矩阵,GPU通信方便,互相访问显存,只在网络某些层进行,控制通信性能损耗。数据增强,随机从256x256原始图像截取224x224区域,水平翻转镜像,增加(256-224)^2x2=2048倍数据量,减轻过拟合,提升泛化能力,预测取图片四角加中间5个位置,左右翻转,10张图片,10次预测结果求均值,图像RGB数据PCA处理,主成分标准差0.1高斯扰动,增加噪声,错误率下降1%。

8个参数训练层(不包括池化层、LRN层),前5卷积层,后3全连接层。最后一层1000类输出Softmax层分类。LRN层在第1、2卷积层后,最大池化层在LRN层、最后卷积层后。ReLU激活函数在每个参数层后。

AlexNet超参数:
params AlexNext FLOPs
4M FC1000 4M
16M FC4096/ReLU 4M
37M FC4096/ReLU 37M
Max Pool 3x3s2
442K Conv 3x3s1,256/ReLU 74M
1.3M Conv 3x3s1,384/ReLU 112M
884K Conv 3x3s1,384/ReLU 149M
Max Pool 3x3s2
Local Response Norm
307K Conv 5x5s1,256/ReLU 223M
Max Pool 3x3s2
Local Response Norm
35K Conv 11x11s4,96/ReLU 105M

输入图片尺寸224x224,第一卷积层卷积核尺寸11x11,步长4,96个卷积核。LRN层。3x3 最大池化层,步长2。后续卷积核5x5或3x3,步长2。通过较小参数提取有效特征。

导入系统库datetime、math、time,载入TensorFlow。

batch_size 32,num_batches 100,共测试100个batch数据。

定义网络结构显示函数print_actications,卷积层或池化层输出tensor尺寸。接受tensor输入,显示名称(t.op.name)、tensor尺寸(t.get_shape.as_list())。

网络结构。定义inference函数,接受images输入,返回最后一层pool5(第5个池化层)及parameters(模型参数)。多个卷积层、池化层。

第一卷积层conv1,TensorFlow name_scope,with tf.name_scope(‘conv1’) as scope,scope内生成Variable自动命名为conv1/xxx,区分不同卷积层组件。定义第一卷积层,tf.truncated_normal截断正态分布函数(标准差0.1),初始化卷积核参数kernel。卷积核尺寸11x11,颜色通道3,卷积核64。tf.nn.conv2d卷积images,strides步长4x4(图片每4x4区域只取样一次,横向间隔4,纵向间隔4,取样卷积核尺寸11x11),padding模式SAME。卷积层biases全初始化0。tf.nn.bias_add,conv、biases加。用激活函数tf.nn.relu结果非线性。print_activations 打印最后输出tensor conv1结构。可训练参数kernel、biases添加parameters。

第一卷积层后添加LRN层、最大池化层。tf.nn.lrn LRN处理前面输出tensor conv1,depth_radius 4,bias 1,alpha 0.001/9,beta 0.75。其他经典卷积神经网络放充LRN。LRN让前馈、反馈速度下降到1/3。tf.nn.max_pool 最大池化处理前面输出lrn1,尺寸 3x3,3x3像素块降为1x1像素,取样步长2x2,padding模式VALID,取样不超过边框,不填充边界外点(SAME)。打印输出结果pool1结构。

第二卷积层,卷积核尺寸5x5,输入通道数 64(上一层输出通道数,上一层卷积核数量),卷积核192,步长1,扫描全图像素。

处理第二卷积层输出conv2,先LRN处理,再最大池化。

第三卷积层,卷积核尺寸3x3,输入通道数 192,卷积核 384,步长1。

第四卷积层,卷积核尺寸3x3,输入通道数 384,卷积核 256,步长1。

第五卷积层,卷积核尺寸3x3,输入通道数 256,卷积核 256,步长1。

最大池化层,返回池化层输出pool5。卷积结束。

3个全连接层,隐含节点4096、4096、1000,计算量很小。

评估AlexNet每轮计算时间函数time_tensorflow_run。第一输入TensorFlow Session,第二变量评测运算算子,第三变量测试名称。定义预热轮数num_steps_burn_in=10,给程序热身,头几轮迭代显存加载、cache命中问题跳过,10轮迭代后计算时间。记录总时间total_duration、平方和total_duration_squared,计算方差。

num_batches+num_steps_burn_in次迭代计算,time.time()记录时间,session.run(target)执行每次迭代。初始热身num_steps_burn_in次迭代后,每10轮迭代显示当前迭代时间。每轮total_duration、total_duration_squared累加。

循环结束,计算每轮耗时均值mn、标准差sd,显示结果。

主函数run_benchmark。with tf.Graph().as_default()定义默认Graph。tf.random_nomal函数构造正态颁上(标准差 0.1)随机tensor,第一维度batch_size,每轮迭代样本数,第二、三维度图片尺寸image_size 224,第四维度图片颜色通道数。inference函数构建整个AlexNet网络,最后池化层输出pool5,训练参数集合parameters。tf.Session()创建新Session,tf.global_variables_initializer()初始化所有参数。

AlexNet forward计算评测,time_tensorflow_run 统计运算时间,传入target pool5,卷积网络最后池化层输出。backward 训练过程评测,最后输出pool5设置优化目标loss。tf.nn.l2_loss计算,tf.gradients求loss所有模型参数梯度,模拟训练过程,根据梯度更新参数。time_tensorflow_run统计backward运算时间,target求整个网络梯度gard。

执行主函数。

程序显示三段结果。AlexNet网络结构、输出tensor尺寸。forward计算时间,有LRN层每轮迭代时间0.026s,去除LRN层0.007s,对最终准确率影响不大。backward运算时间,有LRN层每轮迭代时间0.078s,去除LRN层0.025s。backward运算耗时约forward三倍。

CNN训练过程(backward计算)比较耗时,过很多遍数据,大量迭代。CNN瓶劲在训练。TensorFlow已经支持iOS、Android,手机CPU做人脸识别、图片分类非常方便、响应速度很快。

传统机器学习模型适合学习小型数据集,大型数据集需要更大学习容量(Learning Capacity)模型,深度学习模型。卷积层参数量少,抽取特征能力非常强。

    from datetime import datetime
    import math
    import time
    import tensorflow as tf
    batch_size=32
    num_batches=100
    def print_activations(t):
        print(t.op.name, ' ', t.get_shape().as_list())
    def inference(images):
        parameters = []
        # conv1
        with tf.name_scope('conv1') as scope:
            kernel = tf.Variable(tf.truncated_normal([11, 11, 3, 64], dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
            conv = tf.nn.conv2d(images, kernel, [1, 4, 4, 1], padding='SAME')
            biases = tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float32),
                             trainable=True, name='biases')
            bias = tf.nn.bias_add(conv, biases)
            conv1 = tf.nn.relu(bias, name=scope)
            print_activations(conv1)
            parameters += [kernel, biases]
      # pool1
        lrn1 = tf.nn.lrn(conv1, 4, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='lrn1')
        pool1 = tf.nn.max_pool(lrn1,
                           ksize=[1, 3, 3, 1],
                           strides=[1, 2, 2, 1],
                           padding='VALID',
                           name='pool1')
        print_activations(pool1)
      # conv2
        with tf.name_scope('conv2') as scope:
            kernel = tf.Variable(tf.truncated_normal([5, 5, 64, 192], dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
            conv = tf.nn.conv2d(pool1, kernel, [1, 1, 1, 1], padding='SAME')
            biases = tf.Variable(tf.constant(0.0, shape=[192], dtype=tf.float32),
                             trainable=True, name='biases')
            bias = tf.nn.bias_add(conv, biases)
            conv2 = tf.nn.relu(bias, name=scope)
            parameters += [kernel, biases]
        print_activations(conv2)
      # pool2
        lrn2 = tf.nn.lrn(conv2, 4, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='lrn2')
        pool2 = tf.nn.max_pool(lrn2,
                           ksize=[1, 3, 3, 1],
                           strides=[1, 2, 2, 1],
                           padding='VALID',
                           name='pool2')
        print_activations(pool2)
      # conv3
        with tf.name_scope('conv3') as scope:
            kernel = tf.Variable(tf.truncated_normal([3, 3, 192, 384],
                                                 dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
            conv = tf.nn.conv2d(pool2, kernel, [1, 1, 1, 1], padding='SAME')
            biases = tf.Variable(tf.constant(0.0, shape=[384], dtype=tf.float32),
                             trainable=True, name='biases')
            bias = tf.nn.bias_add(conv, biases)
            conv3 = tf.nn.relu(bias, name=scope)
            parameters += [kernel, biases]
            print_activations(conv3)
      # conv4
        with tf.name_scope('conv4') as scope:
            kernel = tf.Variable(tf.truncated_normal([3, 3, 384, 256],
                                                 dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
            conv = tf.nn.conv2d(conv3, kernel, [1, 1, 1, 1], padding='SAME')
            biases = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float32),
                             trainable=True, name='biases')
            bias = tf.nn.bias_add(conv, biases)
            conv4 = tf.nn.relu(bias, name=scope)
            parameters += [kernel, biases]
            print_activations(conv4)
      # conv5
        with tf.name_scope('conv5') as scope:
            kernel = tf.Variable(tf.truncated_normal([3, 3, 256, 256],
                                                 dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
            conv = tf.nn.conv2d(conv4, kernel, [1, 1, 1, 1], padding='SAME')
            biases = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float32),
                             trainable=True, name='biases')
            bias = tf.nn.bias_add(conv, biases)
            conv5 = tf.nn.relu(bias, name=scope)
            parameters += [kernel, biases]
            print_activations(conv5)
      # pool5
        pool5 = tf.nn.max_pool(conv5,
                           ksize=[1, 3, 3, 1],
                           strides=[1, 2, 2, 1],
                           padding='VALID',
                           name='pool5')
        print_activations(pool5)
        return pool5, parameters
    def time_tensorflow_run(session, target, info_string):
        num_steps_burn_in = 10
        total_duration = 0.0
        total_duration_squared = 0.0
        for i in range(num_batches + num_steps_burn_in):
            start_time = time.time()
            _ = session.run(target)
            duration = time.time() - start_time
            if i >= num_steps_burn_in:
                if not i % 10:
                    print ('%s: step %d, duration = %.3f' %
                       (datetime.now(), i - num_steps_burn_in, duration))
                total_duration += duration
                total_duration_squared += duration * duration
        mn = total_duration / num_batches
        vr = total_duration_squared / num_batches - mn * mn
        sd = math.sqrt(vr)
        print ('%s: %s across %d steps, %.3f +/- %.3f sec / batch' %
           (datetime.now(), info_string, num_batches, mn, sd))
    def run_benchmark():
        with tf.Graph().as_default():
            image_size = 224
            images = tf.Variable(tf.random_normal([batch_size,
                                           image_size,
                                           image_size, 3],
                                          dtype=tf.float32,
                                          stddev=1e-1))
            pool5, parameters = inference(images)
            init = tf.global_variables_initializer()
            config = tf.ConfigProto()
            config.gpu_options.allocator_type = 'BFC'
            sess = tf.Session(config=config)
            sess.run(init)
            time_tensorflow_run(sess, pool5, "Forward")
            objective = tf.nn.l2_loss(pool5)
            grad = tf.gradients(objective, parameters)
            time_tensorflow_run(sess, grad, "Forward-backward")
    run_benchmark()

参考资料:
《TensorFlow实战》

【深度学习】使用tensorflow实现AlexNet 转载注明出处:http://blog.youkuaiyun.com/accepthjp/article/details/69999309 AlexNet是2012年ImageNet比赛的冠军,虽然过去了很长时间,但是作为深度学习中的经典模型,AlexNet不但有助于我们理解其中所使用的很多技巧,而且非常有助于提升我们使用深度学习工具箱的熟练度。尤其是我刚入门深度学习,迫切需要一个能让自己熟悉tensorfl 阅读详情

相关推荐

Tensorflow实现经典CNN网络AlexNet

AlexNet在图像分类中是一个比较重要的网络,在学习的过程中不仅要学会写网络结构,知道每一层的结构,更重要的是得知道为什么要这样设计,这样设计有什么好处,如果对某些参数进行一些调整结果会有什么变化?为什么会产生这样的变化。在实际应用中,如果需要对网络结构做一些调整,应该如何调整使得网络更适合我们的实际数据?这些才是我们关心的。

一夜白头催人泪 1753

Tensorflow 基础与实战

也可以编码成维度一样的,如北京就是 [1, 0, 0] , 其他 [0, 1, 0] ,[0, 0, 1]activity_regularizer:施加在输出上的正则项 (详见API的regularizer)kernel_regularizer:施加在权重w上的正则项 (详见API的regularizer)bias_regularizer:施加在偏置向量b上的正则项 (详见API的regularizer)bias_constraint:施加在偏置b上的约束项 (详见API的constraints)

清园暖歌的博客 2058

AlexNet 网络详解及Tensorflow实现源码

作者:行动派Xdpie 1. 图片数据处理 一张图片是由一个个像素组成,每个像素的颜色常常用RGB、HSB、CYMK、RGBA等颜色值来表示,每个颜色值的取值范围不一样,但都代表了一个像素点数据信息。对图片的数据处理过程中,RGB使用得最多,RGB表示红绿蓝三通道色,取值范围为0~255,所以一个像素点可以把它看作是一个三维数组,即:array([[[0, 255, 255]]]),三个数值分

36大数据 2万+

tensorflow实战例子

tensorflow实战1.简单线性回归(1)数据准备(2)准备好placeholder(3)初始化参数/权重(4)计算预测结果(5)计算损失函数值(6)初始化optimizer(7)指定迭代次数,并在session里执行graph 1.简单线性回归 (1)数据准备 实际的数据大家可以通过pandas等package读入,也可以使用自带的Boston House Price数据集,这里为了简单,我们自己手造一点数据集。 %matplotlib inline import numpy as np import

u014168855的博客 4875

深度学习小白——Alexnet之tensorflow实现

一、Alexnet简介 2012年,Imagenet比赛冠军的model——Alexnet [2](以第一作者alex命名)。 说实话,这个model的意义比后面那些model都大很多,首先它证明了CNN在复杂模型下的有效性,然后GPU实现使得训练在可接受的时间范围内得到结果,确实让CNN和GPU都大火了一把,顺便推动了有监督DL的发展。 模型结构见下图,别看只有寥寥八层(不算inp

MargretWG的博客 2519

常用本体建模工具

常用本体建模工具: Apollo、OntoStudio、TopBraid Composer、Semantic Turkey、Knoodl、Chimaera、OliEd、WebODE、Kmgen和DOME Protégé Protégé[1]是一款由斯坦福大学编写并维护的开源本体建模和编辑工具,其支持Web版本和PC版本,使用OWL语言(关于OWL的详细介绍可参看前文2.1节内容)对知识进行表示,读者可以通过Protégé的官方网站访问Web版本或下载桌面版本。Protégé最早开发于1987年,最初目的是

qq_40503347的博客 6158

TensorFlow 深度学习实战指南:1~5 全

您需要做的第一件事是下载本书的源代码包并打开simple.py文件。您可以使用此文件将行复制并粘贴到 TensorFlow 或 CoCalc 中,也可以直接键入它们。首先,让我们将tensorflow导入为tf。这是在 Python 中引用它的便捷方法。您需要在通话中保留常数。例如,做和当然,您可以将它们相加并相乘以获得其他值,即c和dd = a * bTensorFlow 数字以张量存储,这是多维数组的一个花哨术语。

龙哥盟 3094

群晖NAS从入门到精通的所有帖子汇总,只要这一篇就够了

本站陆陆续续的转载、原创帖子也有十几二十篇了,从不同的角度对群晖NAS的各种骚操作都有深入的讲解,虽然很多文章都不是讲的很深入,但是针对小白入门已经是足够了,希望对小白来说是一个入门,群晖NAS的大佬们勿喷,哪里写的不对的,请随时留言西安SEO优化站长一定在第一时间纠正修改。

西安SEO优化网站资源 8万+

【深度学习01】TensorFlow神经网络理论实战

TensorFlow是运用最广的深度学习框架之一。他还有另外一个同行叫做pytorch。他俩的区别就是TensorFlow比pytorch难写不止一点半点。而且TensorFlow它的版本迭代,很多版本之间是互相不兼容的。TensorFlow既服务于科研,又服务于生产。他还是多平台支持的,丰富的生态环境。TensorFlow的运作方式是先构建计算图,这个计算图里面是没有东西的,只有当我们把数据送到里面的时候,开始一个session的计算的时候,他才有数据的流动。所以这跟我们平常的编程模式是有一些差别的。

weixin_55252589的博客 2204

R分析|怎么样使用piecewiseSEM构建结构方程模型?保姆级教程

计算科学的发展让我们有了更先进的工具揭示自然规律。结构方程模型(SEM)已被广泛应用于多学科进行数据挖掘。其中在R中实现的结构方程模型是方便快捷的。今天要介绍的piecewiseSEM包就是R中实现SEM的一种方式。piecewiseSEM被开发出来主要目的是为了解决复杂模型简化后进行分段分析。个人认为最大的特点是更灵活,且采用的是原始数据,并不是传统的协方差矩阵。其次,将SEM破碎化为多个独立的方程,对样本量要求较少。

weixin_46814750的博客 6922

利用docx4j与docx4j-ImportXHTML高效实现HTML到Word的自动化转换

本文详细介绍了如何利用docx4j与docx4j-ImportXHTML库,在Java环境中高效实现HTML到Word文档的自动化转换。内容涵盖从环境搭建、核心依赖配置,到集成Spring Boot REST API的完整实战流程,并深入解析了处理图片、CSS样式、字体设置以及使用模板保证样式统一等高级技巧与常见问题解决方案,帮助开发者构建稳定的文档自动化生成流水线。

cnn8visionary的博客 364

【深度学习】AlexNet原理解析及实现

【深度学习】AlexNet原理解析及实现    Alex提出的alexnet网络结构模型,在imagenet2012图像分类challenge上赢得了冠军。    要研究CNN类型DL网络模型在图像分类上的应用,就逃不开研究alexnet,这是CNN在图像分类上的经典模型。一、Alexnet结构alexNet为8层深度网络,其中5层卷积层和3层全连接层,不计LRN层和池化层。如下图所示:     ...

gogo小Sa的专栏 3万+

【LE Audio】CAP精讲[1]: 从理论到实操,CAP 协同流程入门全攻略

LEAudio生态中的CommonAudioProfile(CAP)是一个关键协同框架,它通过整合基础音频协议(BAP/VCP/MICP等)构建多设备协同能力。CAP定义了三大核心功能:音频流管理、设备组控制和统一交互服务,解决了传统蓝牙音频在多设备场景下的协同痛点。其规范历经v1.0到v1.0.1的优化,修正了角色定义、连接流程等关键模块,提升设备兼容性。CAP采用严格的语言约定(shall/must/should)和术语体系(ContextType/CCID/协同集),确保不同厂商设备能相互理解。

byte轻骑兵的技术小窝 2万+

AlexNet原理及Tensorflow实现

\quadAlexNet的出现点燃了深度学习的热潮,下面对其进行介绍,并使用tensorflow实现.1. AlexNet网络结构图片来源:AlexNet的论文\quad整个网络有8个需要训练的层,前5个为卷积层,最后3层为全连接层.第一个卷积层 输入的图片大小为:224*224*3 第一个卷积层为:11*11*96即尺寸为11*11,有96个卷积核,步长为4,卷积层后跟ReLU,因此输出的尺寸为

yqtao的博客 4万+

Linux内核进程管理子系统有什么第五十一回 —— 进程主结构详解(47)

Linux内核进程管理子系统有什么第五十一回 —— 进程主结构详解(47)

phmatthaus的专栏 1383

【车载以太网】Eth Stack Bringup

摘要:本文基于AUTOSAR架构,详细介绍了在TC3xx硬件平台上实现EthStack Bringup的全过程。作者通过配置MCAL和Davinci工具,完成了EthTrcv、Eth、EthIf、EthSM和TcpIp等模块的集成,并解决了16字节内存对齐和以太网速率不匹配等问题。最终实现了PC端与开发板的Ping通,并通过WireShark验证了数据包收发。文章总结了调试中的关键问题与解决方案,强调了实践的重要性,为后续EthStack的深入分析奠定了基础。

qq_36056498的博客 180

TensorFlow2学习十三、实现AlexNet

一、简介 以下内容整理来自百度百科 AlexNet是2012年ImageNet竞赛冠军获得者Hinton和他的学生Alex Krizhevsky设计的。也是在那年之后,更多的更深的神经网络被提出,比如优秀的vgg,GoogLeNet。 这对于传统的机器学习分类算法而言,已经相当的出色。 网络模型: AlexNet中包含了几个比较新的技术点,也首次在CNN中成功应用了ReLU、Dropout和LR...

猿来这样-谢厂节的博客 1978

第一节:Vben Admin 最新 v5.0 (vben5) + Python Flask 快速入门

vben5 快速入门。 Vben Admin 框架新出的版本V5.5.4,而之前的Vben Admin 2.x 目前已存档,仅进行重大问题修复。之前在2.x版本曾经简单完成了一版专栏文章,当时也是收获了一些好评和建议。本次决定在v5 版本基础上再完成一次前后端的搭建。希望大家继续多多支持。项目精简后,再次启动项目,执行 pnpm run dev点击登录,可以看到接口报错,现在前端请求的后端有报错,下一节处理这部分逻辑。

cuiwin的专栏 7059

基于TensorFlow微调AlexNet

基于TensorFlow微调AlexNet(Finetuning AlexNet with TensorFlow) 讲解了如何在TensorFlow上搭建一个AlexNet网络,并进行微调

two_vv的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

AlexNet原理及tensorflow实现

AlexNet的介绍 在前一篇博客卷积神经网络CNN介绍了Le-Net5网络的结构以及tensorflow实现,下面介绍一下另一种经典的卷积神经网络AlexNet的结构以及实现。AlexNet可以看作Le-Net5网络的一个更深更宽的版本。其首次在CNN中成功应用了dropout,ReLu,和LRN等trick. 1. dropout防止模型过拟合,增强模型的健壮性。 2....

开到荼蘼的博客 4174

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Alexnet详细介绍与TensorFlow实现

1. 介绍Alexnet的网络结构 2. 使用Tensorflow实现Alexnet

SpiritedAway 2373

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

AlexNet模型微调实战:基于finetune_alexnet_with_tensorflow的图像分类任务

finetune_alexnet_with_tensorflow是一个专为TensorFlow(版本≥1.2rc0)设计的AlexNet模型微调项目,它能帮助开发者快速实现图像分类任务的模型优化。通过该项目,即使是深度学习新手也能轻松掌握迁移学习技术,将预训练的AlexNet模型应用于自定义图像数据集。 ## 📋 项目核心文件解析 项目结构清晰,主要包含以下关键文件: - **alexne

gitblog_00064的博客 477

Alexnet的tensorflow实现

代码:https://github.com/kratzert/finetune_alexnet_with_tensorflow(juypter notebook) Alexnet: 代码解析: 一、首先定义一个类: class AlexNet(object): 二、之后定义类的初始化: 注意下,'bvlc_alexnet.npy'为别人训练好的A...

qq_35752161的博客 674

Tensorflow 实现AlexNet 猫狗分类

原文地址:AlexNet 关于文章的理解,网上有很多博客可以参考,这里只给出LRN(local response normalization)的一篇回答,其中形象的解释了LRN,如下图所示。地址链接 实现步骤: 1.构建网络 import tensorflow as tf from tensorflow.contrib import slim import numpy as...

爱明爱夏的博客 8689

Tensorflow实现Alexnet对Imagenet的训练与评测

        在上一篇博文中已经提到了如何对Imagenent 2012图像分类大赛的数据进行预处理。在此基础之上,我们可以搭建不同的神经网络来学习如何对Imagenet的数据进行训练和预测。Imagenet的数据集足够庞大,有120多万张图片和1000个类别,是CIFAR 10数据集无法比拟的,我觉得只有真正在Imagenet的数据集上训练出一个好的模型,才能证明在计算机视觉领域具备解决实际问...

6486

探索深度学习经典:基于TensorFlow的AlexNet在ImageNet上的实战

探索深度学习经典:基于TensorFlow的AlexNet在ImageNet上的实战 imagenetTensorFlow implementation of AlexNet and its training and testing on ImageNet ILSVRC 2012 dataset项目地址:https://gitcode.com/gh_mirrors/ima/imagenet 项目...

gitblog_00099的博客 991
上一篇: Tensorflow实战学习(二十九)【实现进阶卷积网络】
下一篇: Tensorflow实战学习(三十一)【实现VGGNet】
.NET跨平台
博客等级 码龄15年 6066粉丝 738原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值