如何在Python中使用TensorFlow驗證Fashion MNIST的預測結果?
TensorFlow是Google提供的機器學習框架。它是一個開源框架,與Python結合使用,可以實現演算法、深度學習應用程式等等。它用於研究和生產目的。
可以使用以下程式碼行在Windows上安裝“tensorflow”包:
pip install tensorflow
“Fashion MNIST”資料集包含各種服裝的影像。它包含超過7萬張屬於10個不同類別的服裝的灰度影像。這些影像是低解析度的(28 x 28畫素)。
我們使用Google Colaboratory來執行以下程式碼。Google Colab或Colaboratory幫助在瀏覽器上執行Python程式碼,無需任何配置,並可免費訪問GPU(圖形處理單元)。Colaboratory構建在Jupyter Notebook之上。
以下是驗證Python中Fashion MNIST預測結果的程式碼片段:
示例
i = 0
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predictions[i], test_labels, test_images)
plt.subplot(1,2,2)
plot_value_array(i, predictions[i], test_labels)
plt.show()
i = 12
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predictions[i], test_labels, test_images)
plt.subplot(1,2,2)
plot_value_array(i, predictions[i], test_labels)
plt.show()
num_rows = 5
num_cols = 3
print("The test images, predicted labels and the true labels are plotted")
print("The correct predictions are in green and the incorrect predictions are in red")
num_images = num_rows*num_cols
plt.figure(figsize=(2*2*num_cols, 2*num_rows))
for i in range(num_images):
plt.subplot(num_rows, 2*num_cols, 2*i+1)
plot_image(i, predictions[i], test_labels, test_images)
plt.subplot(num_rows, 2*num_cols, 2*i+2)
plot_value_array(i, predictions[i], test_labels)
plt.tight_layout()
plt.show()程式碼來源 − https://www.tensorflow.org/tutorials/keras/classification
輸出



解釋
模型訓練完成後,可用於對其他影像進行預測。
對影像進行預測,並顯示預測陣列。
正確預測的標籤為綠色,錯誤預測的標籤為紅色。
數字表示預測標籤的百分比值。
它說明模型預測的標籤與影像的實際標籤的準確程度。
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP