如何使用 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' 庫完成的。

更新於: 2021年2月20日

89 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告