tensorflow卷积神经网络详解(2)

直观的感受一下卷积操作,数据集还采用mnist手写字体数据。

首先读取一幅图片:

#读取mnist中的一个数据
from __future__ import division,print_function
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
#Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/",one_hot = True)
def train_size(num):
    print('Total Training Image in Dataset = '+
    str(mnist.train.images.shape))
    print('-----------------------------------')
    x_train = mnist.train.images[:num,:]
    print('x_train Examples Loaded = ' + str(x_train.shape))
    y_train = mnist.train.labels[:num,:]
    print('y_train Examples Loaded = ' + str(y_train.shape))
    print('')
    return x_train,y_train
def test_size(num):
    print('Total Test Examples in Dataset = '+
    str(mnist.test.images.shape))
    print('-----------------------------------')
    x_test = mnist.test.images[:num,:]
    print('x_test Examples Loaded =' + str(x_test.shape))
    y_test = mnist.test.labels[:num,:]
    print('y_test Examples Loaded =' + str(y_test.shape))
    return x_test,y_test
x_train,y_train = train_size(55000)#抽取全部的训练集
image = x_train[1] #读取训练集的第一个样本

对它进行显示:

image = x_train[1] #读取训练集的第一个样本
image_label = y_train[1]
image_label_num = y_train[1].argmax(axis = 0)
image = image.reshape([28,28])#调整
plt.title("Raw Picture  lable = %d" %image_label_num)
plt.imshow(image,cmap = plt.get_cmap('gray_r')) 
plt.show()

tensorflow卷积神经网络详解(2)

 

上一篇:tensorflow安装问题


下一篇:TensorFlowX.Y核心基础与AI模型设计03:AI模型编程常用(二)