tensorflow深度学习-mnist数据集读入-初试

 1 import os
 2 os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
 3 import tensorflow as tf
 4 from tensorflow import keras
 5 from  tensorflow.keras import layers
 6 import numpy as np
 7 import matplotlib.pyplot as plt
 8 
 9 # from tensorflow.keras.datasets import mnist
10 # mnist is the handwriting number dataset 0-9
11 
12 def load_mnist(path):
13     f=np.load(path)
14     x_train, y_train = f['x_train'], f['y_train']
15     x_test, y_test = f['x_test'], f['y_test']
16     f.close()
17     return (x_train, y_train), (x_test, y_test)
18 
19 
20 (x_train, y_train), (x_test, y_test) = load_mnist("......")
21 print(x_train.shape)
22 print(y_train.shape)
23 
24 
25 N=3
26 idx=0
27 for pages in range(5):
28     for i in range(N):
29         for j in range(N):
30             num=i*N+j
31             plt.subplot(N,N,num+1)
32             plt.imshow(x_train[num+idx],cmap=plt.get_cmap('gray'))
33     idx+=N*N
34     # show the plot
35     plt.show()

网络还没有搭建,先就读入看看效果

输出了五张3*3手写数字的图片,还阔以

 

posted @ 2021-03-12 01:10  墨鳌  阅读(66)  评论(0编辑  收藏  举报