00 环境

#《深度学习原理与TensorFlow实战》04 CNN看懂世界
# 书源码地址:https://github.com/DeepVisionTeam/TensorFlowBook.git
# 视频讲座地址:http://edu.csdn.net/course/detail/5222
# win10 Tensorflow1.2.0 python3.6.1
# CUDA v8.0 cudnn-8.0-windows10-x64-v5.1
# https://github.com/tflearn/tflearn/blob/master/examples/images/residual_network_mnist.py
# https://github.com/tflearn/tflearn/blob/master/examples/images/residual_network_cifar10.py

01 residual_network_mnist.py

# -*- coding: utf-8 -*-""" Deep Residual Network.Applying a Deep Residual Network to MNIST Dataset classification task.References:- K. He, X. Zhang, S. Ren, and J. Sun. Deep Residual Learning for ImageRecognition, 2015.- Y. LeCun, L. Bottou, Y. Bengio, and P. Haffner. "Gradient-basedlearning applied to document recognition." Proceedings of the IEEE,86(11):2278-2324, November 1998.Links:- [Deep Residual Network](http://arxiv.org/pdf/1512.03385.pdf)- [MNIST Dataset](http://yann.lecun.com/exdb/mnist/)"""from __future__ import division, print_function, absolute_importimport tflearn
import tflearn.data_utils as du# Data loading and preprocessing
import tflearn.datasets.mnist as mnist
X, Y, testX, testY = mnist.load_data(one_hot=True)
X = X.reshape([-1, 28, 28, 1])
testX = testX.reshape([-1, 28, 28, 1])
X, mean = du.featurewise_zero_center(X)
testX = du.featurewise_zero_center(testX, mean)# Building Residual Network
net = tflearn.input_data(shape=[None, 28, 28, 1])
net = tflearn.conv_2d(net, 64, 3, activation='relu', bias=False)
# Residual blocks
net = tflearn.residual_bottleneck(net, 3, 16, 64)
net = tflearn.residual_bottleneck(net, 1, 32, 128, downsample=True)
net = tflearn.residual_bottleneck(net, 2, 32, 128)
net = tflearn.residual_bottleneck(net, 1, 64, 256, downsample=True)
net = tflearn.residual_bottleneck(net, 2, 64, 256)
net = tflearn.batch_normalization(net)
net = tflearn.activation(net, 'relu')
net = tflearn.global_avg_pool(net)
# Regression
net = tflearn.fully_connected(net, 10, activation='softmax')
net = tflearn.regression(net, optimizer='momentum',loss='categorical_crossentropy',learning_rate=0.1)
# Training
model = tflearn.DNN(net, checkpoint_path='model_resnet_mnist',max_checkpoints=10, tensorboard_verbose=0)
model.fit(X, Y, n_epoch=100, validation_set=(testX, testY),show_metric=True, batch_size=256, run_id='resnet_mnist')
'''
Extracting mnist/train-images-idx3-ubyte.gz
Extracting mnist/train-labels-idx1-ubyte.gz
Extracting mnist/t10k-images-idx3-ubyte.gz
Extracting mnist/t10k-labels-idx1-ubyte.gz
---------------------------------
Run id: resnet_mnist
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 55000
Validation samples: 10000
--
Training Step: 1  | time: 6.395s
| Momentum | epoch: 001 | loss: 0.00000 - acc: 0.0000 -- iter: 00256/55000
Training Step: 2  | total loss: 2.07091 | time: 11.896s
| Momentum | epoch: 001 | loss: 2.07091 - acc: 0.0844 -- iter: 00512/55000
Training Step: 3  | total loss: 2.25693 | time: 17.365s
...
Training Step: 242  | total loss: 0.07294 | time: 156.351s
| Momentum | epoch: 002 | loss: 0.07294 - acc: 0.9785 -- iter: 06912/55000
Training Step: 243  | total loss: 0.07384 | time: 162.524s
| Momentum | epoch: 002 | loss: 0.07384 - acc: 0.9783 -- iter: 07168/55000
Training Step: 244  | total loss: 0.07520 | time: 168.575s
| Momentum | epoch: 002 | loss: 0.07520 - acc: 0.9789 -- iter: 07424/55000
...
'''

02 residual_network_cifar10.py

# -*- coding: utf-8 -*-""" Deep Residual Network.Applying a Deep Residual Network to CIFAR-10 Dataset classification task.References:
    - K. He, X. Zhang, S. Ren, and J. Sun. Deep Residual Learning for Image
      Recognition, 2015.
    - Learning Multiple Layers of Features from Tiny Images, A. Krizhevsky, 2009.Links:
    - [Deep Residual Network](http://arxiv.org/pdf/1512.03385.pdf)
    - [CIFAR-10 Dataset](https://www.cs.toronto.edu/~kriz/cifar.html)"""from __future__ import division, print_function, absolute_importimport tflearn# Residual blocks
# 32 layers: n=5, 56 layers: n=9, 110 layers: n=18
n = 5# Data loading
from tflearn.datasets import cifar10
(X, Y), (testX, testY) = cifar10.load_data()
Y = tflearn.data_utils.to_categorical(Y, 10)
testY = tflearn.data_utils.to_categorical(testY, 10)# Real-time data preprocessing
img_prep = tflearn.ImagePreprocessing()
img_prep.add_featurewise_zero_center(per_channel=True)# Real-time data augmentation
img_aug = tflearn.ImageAugmentation()
img_aug.add_random_flip_leftright()
img_aug.add_random_crop([32, 32], padding=4)# Building Residual Network
net = tflearn.input_data(shape=[None, 32, 32, 3],data_preprocessing=img_prep,data_augmentation=img_aug)
net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
net = tflearn.residual_block(net, n, 16)
net = tflearn.residual_block(net, 1, 32, downsample=True)
net = tflearn.residual_block(net, n-1, 32)
net = tflearn.residual_block(net, 1, 64, downsample=True)
net = tflearn.residual_block(net, n-1, 64)
net = tflearn.batch_normalization(net)
net = tflearn.activation(net, 'relu')
net = tflearn.global_avg_pool(net)
# Regression
net = tflearn.fully_connected(net, 10, activation='softmax')
mom = tflearn.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
net = tflearn.regression(net, optimizer=mom,
                         loss='categorical_crossentropy')
# Training
model = tflearn.DNN(net, checkpoint_path='model_resnet_cifar10',max_checkpoints=10, tensorboard_verbose=0,clip_gradients=0.)model.fit(X, Y, n_epoch=200, validation_set=(testX, testY),
          snapshot_epoch=False, snapshot_step=500,
          show_metric=True, batch_size=128, shuffle=True,
          run_id='resnet_cifar10')
'''
# 注意自解压目录,需要手动修改一下目录层次,cifar-10-batches-py==>cifar-10-batches-py/cifar-10-batches-py。
---------------------------------
Run id: resnet_cifar10
Log directory: /tmp/tflearn_logs/
---------------------------------
Preprocessing... Calculating mean over all dataset (this may take long)...
Mean: [ 0.49139968  0.48215841  0.44653091] (To avoid repetitive computation, add it to argument 'mean' of `add_featurewise_zero_center`)
---------------------------------
Training samples: 50000
Validation samples: 10000
--
Training Step: 1  | time: 3.993s
| Momentum | epoch: 001 | loss: 0.00000 - acc: 0.0000 -- iter: 00128/50000
Training Step: 2  | total loss: 2.08295 | time: 7.453s
| Momentum | epoch: 001 | loss: 2.08295 - acc: 0.0562 -- iter: 00256/50000
Training Step: 3  | total loss: 2.26373 | time: 10.725s
...
Training Step: 121  | total loss: 1.72538 | time: 425.664s
| Momentum | epoch: 001 | loss: 1.72538 - acc: 0.3421 -- iter: 15488/50000
Training Step: 122  | total loss: 1.72287 | time: 429.461s
| Momentum | epoch: 001 | loss: 1.72287 - acc: 0.3415 -- iter: 15616/50000
Training Step: 123  | total loss: 1.71641 | time: 433.079s
| Momentum | epoch: 001 | loss: 1.71641 - acc: 0.3448 -- iter: 15744/50000
...
'''

tensorflow67 《深度学习原理与TensorFlow实战》04 CNN看懂世界 04深度残差网络相关推荐

  1. tensorflow63 《深度学习原理与TensorFlow实战》03 Hello TensorFlow

    00 基本信息 <深度学习原理与TensorFlow实战>书中涉及到的代码主要来源于: A:Tensorflow/TensorflowModel/TFLean的样例, B:https:// ...

  2. tensorflow71 《深度学习原理与TensorFlow实战》05 RNN能说会道 02语言模型

    01 基本信息 #<深度学习原理与TensorFlow实战>05 RNN能说会道 # 书源码地址:https://github.com/DeepVisionTeam/TensorFlowB ...

  3. tensorflow70 《深度学习原理与TensorFlow实战》05 RNN能说会道 01 正弦序列预测

    01 基本环境 #<深度学习原理与TensorFlow实战>05 RNN能说会道 # 书源码地址:https://github.com/DeepVisionTeam/TensorFlowB ...

  4. tensorflow72 《深度学习原理与TensorFlow实战》05 RNN能说会道 03 对话机器人(chatbot)

    01 基本环境 #<深度学习原理与TensorFlow实战>05 RNN能说会道 # 书源码地址:https://github.com/DeepVisionTeam/TensorFlowB ...

  5. python神经网络原理pdf_《深度学习原理与 TensorFlow实践》高清完整PDF版 下载

    1.封面介绍 2.出版时间 2019年7月 3.推荐理由 本书介绍了深度学习原理与TensorFlow实践.着重讲述了当前学术界和工业界的深度学习核心知识:机器学习概论.神经网络.深度学习.着重讲述了 ...

  6. 深度学习原理与TensorFlow实践

    深度学习原理与TensorFlow实践 王琛,胡振邦,高杰 著 ISBN:9787121312984 包装:平装 开本:16开 用纸:胶版纸 正文语种:中文 出版社:电子工业出版社 出版时间:2017 ...

  7. 《深度学习原理与TensorFlow实践》喻俨,莫瑜

    1. 深度学习简介 2. TensorFlow系统介绍 3. Hello TensorFlow 4. CNN看懂世界 5. RNN能说会道 6. CNN LSTM看图说话 7. 损失函数与优化算法 T ...

  8. 漫画笔记--深度学习,能让人一图看懂,通俗易懂

    漫画笔记--深度学习,能让人一图看懂,通俗易懂!! 漫画笔记--深度学习,能让人一图看懂,通俗易懂!! 漫画笔记–深度学习,能让人一图看懂,通俗易懂!! 这本漫画笔记很有意思,非常适合初学者学习.除非 ...

  9. tornado项目搭建_Python深度学习原理及项目实战2019年3月21日上海举办

    一.课程背景 众所周知,人工智能是高级计算智能最宽泛的概念,机器学习是研究人工智能的一个工具,深度学习是机器学习的一个子集,是目前研究领域卓有成效的学习方法.深度学习的框架有很多,而TenforFlo ...

最新文章

  1. 网站SEO优化值得收藏的技巧介绍
  2. error LNK2019: 无法解析的外部符号 __imp__inet_ntoa@4
  3. 技术人员如何参与产品设计讨论:激活那一潭死水
  4. 如何发现 Kubernetes 中服务和工作负载的异常
  5. keepalived(4)——演练故障出现时keepalived的状态
  6. 《WinForm开发系列之控件篇》Item3 BindingSource (暂无)
  7. 1.docker学习
  8. Application,Session,Cookie和ViewState等对象用法和区别
  9. Angularjs中设置cookies的过期时间
  10. antdesign 所兼容的浏览器_React爬坑之路——Antd兼容IE
  11. java利用随机数简单发牌,!!!!!!!java新手求助,请教一个数组下标越界异常的问题...
  12. Linux下挂载iscsi存储及多路径功能配置
  13. educoder平台哪里有答案_GRE机经哪里找?如何获取准确的GRE机经资料
  14. MySQL卸载与安装
  15. 测试方案包含哪些内容?
  16. android中的后退功能,在Android中单击按钮时触发后退按钮功能
  17. 【亲测】80个经典在线休闲H5小游戏源码合集,直接上传空间即可使用,可玩性还不错
  18. 信息学奥赛一本通1379:热浪(heatwv) 图论dijkastra算法
  19. 阿里云对运营10多年来持续最久的故障发布复盘说明
  20. python股票成交明细_Python股票成交价格-买卖额分布图(三)

热门文章

  1. OpenCV实现动态人脸识别(第一讲)
  2. SAP BW/4HANA学习笔记2
  3. Missile Silos CodeForces - 144D
  4. 利用gltfloader.dll或者SharpGLTF生成gltf、glb数据
  5. 数字电子技术实验作业(5)
  6. (5)微信UI自动化-实现静默鼠标点击(C#)
  7. COJ1972-大梵天的恩赐
  8. android 01
  9. c语言中error c2065: c: 未声明的标识符,error C2065: “L”: 未声明的标识符 需要加什么头文件或者声明什么东西...
  10. 比肩Salesforce 销售易即将发布旗舰版移动CRM及PaaS平台