深度学习笔记1--Le_Net-5

1.Le-Net-5经典卷积网络一共有7层,分别是卷积,池化,卷积,池化,全连接,全连接,全连接。原始论文中卷积核大小是5*5,步长为1,池化核大小是2*2,步长为2。batcsize=128,经过10000次迭代后,loss = 0.0367,test_acc = 0.9888。


2.改变卷积结构,把5*5卷积核换为两个3*3卷积核,分别是卷积,卷积,最大池化,卷积,卷积,最大池化,全连接,全连接,全连接。batchsize = 128,经过10000次迭代后,loss=0.23026,test_acc  = 0.9894。


3.上面两种结构中,采用Adam优化器,loss = 交叉熵损失+正则化,用mnist数据集,初始学习率两者相同,都采用dropout随机失活。


4.可以看出第二种改变卷积核大小后,10000次迭代损失0.23026依旧较大,仍有优化空间,在迭代过程中发现大小来回跳动,没有收敛很好。分析可能原因是最后的学习率可能较大,可以继续尝试采用滑动平均,指数衰减等方式设置学习率大小,效果可能会更好,此处没有加入。


5.采用两个3*3卷积核替代一个5*5卷积核会减少参数个数,很大可能还会提高精准度。2*3*3 = 18 < 5*5 =25 ,参数个数减少。原Le-net加上池化共7层,改变卷积核大小后一共有9层,深度增加,尝试一次实验后效果稍微提升,但是还未最终收敛,如果最终收敛后效果可能会更好。


6.网络结构源码:

def inference(input_tensor,train,regularizer):

    conv1 = conv(input_tensor,[3, 3, 1, 6],[1,1,1,1],'layer1-conv1',"VALID")

    conv2 = conv(conv1, [3, 3, 6, 12], [1, 1, 1, 1], 'layer1-conv2', "VALID")

    pool1 = max_pooling(conv2,[1,2,2,1],[1,2,2,1],name='pool1',padding="SAME")

    conv3 = conv(pool1,[3,3,12,16],[1,1,1,1],'layer3-conv',padding="VALID")

    conv4 = conv(conv3, [3, 3, 16, 16], [1, 1, 1, 1], 'layer4-conv', padding="VALID")


    pool2 = max_pooling(conv4,[1,2,2,1],[1,2,2,1],name='poo2',padding="SAME")


    pool_shape = pool2.get_shape().as_list()
    nodes = pool_shape[1] * pool_shape[2] * pool_shape[3]
    reshaped = tf.reshape(pool2, [-1, nodes])


    with tf.variable_scope('layer5-fc1'):
        fc1_weights = tf.get_variable('weight', [nodes, 120], initializer=tf.truncated_normal_initializer(stddev=0.1))
        if regularizer != None:
            tf.add_to_collection('losses', regularizer(fc1_weights))
        fc1_biases = tf.get_variable('bias', [120], initializer=tf.constant_initializer(0.1))
        fc1 = tf.nn.relu(tf.matmul(reshaped, fc1_weights) + fc1_biases)
        if train:
            fc1 = tf.nn.dropout(fc1, 0.5)

    with tf.variable_scope('layer6-fc2'):
        fc2_weights = tf.get_variable('weight', [120, 84], initializer=tf.truncated_normal_initializer(stddev=0.1))
        if regularizer != None:
            tf.add_to_collection('losses', regularizer(fc2_weights))
        fc2_biases = tf.get_variable('bias', [84], initializer=tf.truncated_normal_initializer(stddev=0.1))
        fc2 = tf.nn.relu(tf.matmul(fc1, fc2_weights) + fc2_biases)
        if train:
            fc2 = tf.nn.dropout(fc2, 0.5)

    with tf.variable_scope('layer7-fc3'):
        fc3_weights = tf.get_variable('weight', [84, 10], initializer=tf.truncated_normal_initializer(stddev=0.1))
        if regularizer != None:
            tf.add_to_collection('losses', regularizer(fc3_weights))
        fc3_biases = tf.get_variable('bias', [10], initializer=tf.truncated_normal_initializer(stddev=0.1))
        logit = tf.matmul(fc2, fc3_weights) + fc3_biases
    return logit

7.文中如果错误,欢迎留言指正。


8.完整代码打包连接地址

https://download.csdn.net/download/jainszhang/10322721

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值