1、导入模块
导入必要的模块,这对于传统神经网络的可视化非常重要。
import os import numpy as np import pandas as pd from scipy.misc import imread from sklearn.metrics import accuracy_score import keras from keras.models import Sequential, Model from keras.layers import Dense, Dropout, Flatten, Activation, Input from keras.layers import Conv2D, MaxPooling2D import torch
2、得到数据集
为了停止训练和测试数据的潜在随机性,调用下面代码中给出的各自的数据集:
seed = 128 rng = np.random.RandomState(seed) data_dir = "../../datasets/MNIST" train = pd.read_csv('../../datasets/MNIST/train.csv') test = pd.read_csv('../../datasets/MNIST/Test_fCbTej3.csv') img_name = rng.choice(train.filename) filepath = os.path.join(data_dir, 'train', img_name) img = imread(filepath, flatten=True)
3、绘制图像
绘制必要的图像,以获得训练和测试数据,以完美的方式定义使用下面的代码:
pylab.imshow(img, cmap ='gray') pylab.axis('off') pylab.show()
输出显示如下: