• 热门专题

TensorflowMNIST数据集测试代码入门

作者:  发布日期:2016-02-19 21:13:41
Tag标签:代码  数据  
  • 测试代码已上传至GitHub:yhlleo/mnist

    将MNIST数据集,下载后拷贝到文件夹Mnist_data中,如果已经配置好tensorflow环境,主要的四个测试代码文件,都可以直接编译运行:

    mnist_softmax.py: MNIST机器学习入门 mnist_deep.py: 深入MNIST fully_connected_feed.py: TensorFlow运作方式入门 mnist_with_summaries.py: Tensorboard训练过程可视化

    mnist_softmax.py运行结果比较简单,就不列举。

    mnist_deep.py迭代运行较为耗时,结果已显示在博客: 深入MNIST code测试 。

    fully_connected_feed.py的运行结果如下(本人电脑为2 CPU,没有使用GPU):

    Extracting Mnist_data/train-images-idx3-ubyte.gz
    Extracting Mnist_data/train-labels-idx1-ubyte.gz
    Extracting Mnist_data/t10k-images-idx3-ubyte.gz
    Extracting Mnist_data/t10k-labels-idx1-ubyte.gz
    I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 2
    I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 2
    Step 0: loss = 2.33 (0.023 sec)
    Step 100: loss = 2.09 (0.007 sec)
    Step 200: loss = 1.76 (0.009 sec)
    Step 300: loss = 1.36 (0.007 sec)
    Step 400: loss = 1.12 (0.007 sec)
    Step 500: loss = 0.74 (0.008 sec)
    Step 600: loss = 0.78 (0.006 sec)
    Step 700: loss = 0.69 (0.007 sec)
    Step 800: loss = 0.67 (0.007 sec)
    Step 900: loss = 0.52 (0.010 sec)
    Training Data Eval:
      Num examples: 55000  Num correct: 47532  Precision @ 1: 0.8642
    Validation Data Eval:
      Num examples: 5000  Num correct: 4360  Precision @ 1: 0.8720
    Test Data Eval:
      Num examples: 10000  Num correct: 8705  Precision @ 1: 0.8705
    Step 1000: loss = 0.56 (0.013 sec)
    Step 1100: loss = 0.50 (0.145 sec)
    Step 1200: loss = 0.33 (0.007 sec)
    Step 1300: loss = 0.44 (0.006 sec)
    Step 1400: loss = 0.39 (0.006 sec)
    Step 1500: loss = 0.33 (0.009 sec)
    Step 1600: loss = 0.56 (0.008 sec)
    Step 1700: loss = 0.50 (0.007 sec)
    Step 1800: loss = 0.42 (0.006 sec)
    Step 1900: loss = 0.41 (0.006 sec)
    Training Data Eval:
      Num examples: 55000  Num correct: 49220  Precision @ 1: 0.8949
    Validation Data Eval:
      Num examples: 5000  Num correct: 4520  Precision @ 1: 0.9040
    Test Data Eval:
      Num examples: 10000  Num correct: 9014  Precision @ 1: 0.9014
    [Finished in 22.8s]

    mnist_with_summaries.py主要提供了一种在Tensorboard可视化方法,首先,编译运行代码:

    tensorboard

    运行完毕后,打开终端Terminal,输入tensorboard --logdir=/tmp/mnist_logs(与writer = tf.train.SummaryWriter('/tmp/mnist_logs', sess.graph_def)中的文件路径一致),终端中就会运行显示:Starting TensorBoard on port 6006 (You can navigate to http://localhost:6006)

    然后,打开浏览器,输入链接http://localhost:6006:

    tensorboard2

    其中,有一些选项,例如菜单栏里包括EVENTS, IMAGES, GRAPH, HISTOGRAMS,都可以一一点开查看~

    另外,此时如果不关闭该终端,是无法在其他终端中重新生成可视化结果的,会出现端口占用的错误,更多详细信息可以查看英文原文:TensorBoard: Visualizing Learning。

    如有纰漏,欢迎指正!


    本系列文章由 @yhl_leo 出品,转载请注明出处。
    文章链接: http://blog.csdn.net/yhl_leo/article/details/50614444

     


About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规