如何使用 TensorFlow 和 Python 驗證 CIFAR 資料集?
CIFAR 資料集可以透過在控制檯上繪製資料集中的影像來驗證。由於 CIFAR 標籤是陣列,因此需要額外的索引。'matplotlib' 庫中的 'imshow' 方法用於顯示影像。
閱讀更多: 什麼是 TensorFlow 以及 Keras 如何與 TensorFlow 協同工作以建立神經網路?
我們正在使用 Google Colaboratory 來執行以下程式碼。Google Colab 或 Colaboratory 幫助在瀏覽器上執行 Python 程式碼,無需任何配置,並且可以免費訪問 GPU(圖形處理單元)。Colaboratory 建立在 Jupyter Notebook 之上。
print("Verifying the data")
plt.figure(figsize=(10,10))
print("Plot the first 15 images")
print("An extra index is needed since CIFAR labels are arrays")
for i in range(15):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i], cmap=plt.cm.binary)
plt.xlabel(class_names[train_labels[i][0]])
plt.show()程式碼來源:https://www.tensorflow.org/tutorials/images/cnn
輸出
Verifying the data Plot the first 15 images An extra index is needed since CIFAR labels are arrays
解釋
- 視覺化已標準化的資料。
- 這是使用 'matplotlib' 庫完成的。
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP