zoukankan      html  css  js  c++  java
  • tensorflow学习05(Mnist数据集)

    今天我主要学习了Mnist数据集的大致使用流程以及如何使用Mnist数据集

    1、导入工具包

    import numpy as np
    import tensorflow as tf
    import matplotlib.pyplot as plt
    #from tensorflow.examples.tutorials.mnist import input_data
    import input_data
    
    print ("packs loaded")

    2、输出Mnist数据集个数

    print ("Download and Extract MNIST dataset")
    mnist = input_data.read_data_sets('data/', one_hot=True)
    print
    print (" tpye of 'mnist' is %s" % (type(mnist)))
    print (" number of trian data is %d" % (mnist.train.num_examples))
    print (" number of test data is %d" % (mnist.test.num_examples))

    3、输出Mnist数据集种类及特征

    # What does the data of MNIST look like? 
    print ("What does the data of MNIST look like?")
    trainimg   = mnist.train.images
    trainlabel = mnist.train.labels
    testimg    = mnist.test.images
    testlabel  = mnist.test.labels
    print
    print (" type of 'trainimg' is %s"    % (type(trainimg)))
    print (" type of 'trainlabel' is %s"  % (type(trainlabel)))
    print (" type of 'testimg' is %s"     % (type(testimg)))
    print (" type of 'testlabel' is %s"   % (type(testlabel)))
    print (" shape of 'trainimg' is %s"   % (trainimg.shape,))
    print (" shape of 'trainlabel' is %s" % (trainlabel.shape,))
    print (" shape of 'testimg' is %s"    % (testimg.shape,))
    print (" shape of 'testlabel' is %s"  % (testlabel.shape,))

    4、输出训练数据种类及特征

    # How does the training data look like?
    print ("How does the training data look like?")
    nsample = 5
    randidx = np.random.randint(trainimg.shape[0], size=nsample)
    
    for i in randidx:
        curr_img   = np.reshape(trainimg[i, :], (28, 28)) # 28 by 28 matrix 
        curr_label = np.argmax(trainlabel[i, :] ) # Label
        plt.matshow(curr_img, cmap=plt.get_cmap('gray'))
        plt.title("" + str(i) + "th Training Data " 
                  + "Label is " + str(curr_label))
        print ("" + str(i) + "th Training Data " 
               + "Label is " + str(curr_label))
        plt.show()
  • 相关阅读:
    小项目心得交流
    自己写的web标准教程,帮你走进web标准设计的世界——第三讲(html终结篇)
    css之清除区域
    面向对象大作业(自主选题)
    关于vue在hash模式偶发不能后退的处理
    flex布局设置单个子元素靠右
    css 选择器
    Git常用命令及方法大全
    解决微信sdk之uploadImage上传多张图片时循环提示“上传中”
    grid 布局
  • 原文地址:https://www.cnblogs.com/yang2000/p/14535063.html
Copyright © 2011-2022 走看看