- Practical Convolutional Neural Networks
- Mohit Sewak Md. Rezaul Karim Pradeep Pujari
- 140字
- 2021-06-24 18:58:51
Visualizing the training data
The following function will help you visualize the MNIST data. By passing in the index of a training example, the show_digit function will display that training image along with its corresponding label in the title:
# Visualize the data import matplotlib.pyplot as plt %matplotlib inline #Displaying a training image by its index in the MNIST set def display_digit(index): label = y_train[index].argmax(axis=0) image = X_train[index] plt.title('Training data, index: %d, Label: %d' % (index, label)) plt.imshow(image, cmap='gray_r') plt.show() # Displaying the first (index 0) training image display_digit(0)
X_train = X_train.reshape(60000, 784) X_test = X_test.reshape(10000, 784) X_train = X_train.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_test /= 255 print("Train the matrix shape", X_train.shape) print("Test the matrix shape", X_test.shape)
#One Hot encoding of labels. from keras.utils.np_utils import to_categorical print(y_train.shape) y_train = to_categorical(y_train, 10) y_test = to_categorical(y_test, 10) print(y_train.shape)
推薦閱讀
- MySQL數據庫進階實戰
- 同步:秩序如何從混沌中涌現
- 大數據技術基礎
- 云計算環境下的信息資源集成與服務
- Visual Studio 2015 Cookbook(Second Edition)
- Python數據分析:基于Plotly的動態可視化繪圖
- 軟件成本度量國家標準實施指南:理論、方法與實踐
- 大數據營銷:如何讓營銷更具吸引力
- “互聯網+”時代立體化計算機組
- HikariCP連接池實戰
- Google Cloud Platform for Developers
- 中國云存儲發展報告
- Node.js High Performance
- AndEngine for Android Game Development Cookbook
- 數據之美:一本書學會可視化設計