如何使用TensorFlow和預訓練模型來理解學習曲線?
TensorFlow和預訓練模型可以透過視覺化對輸入資料集執行的操作來理解學習曲線。訓練精度和驗證精度藉助於'matplotlib'庫繪製出來。訓練損失和驗證損失也同樣視覺化。
閱讀更多: 什麼是TensorFlow以及Keras如何與TensorFlow一起建立神經網路?
包含至少一層卷積層的神經網路被稱為卷積神經網路。我們可以使用卷積神經網路來構建學習模型。
我們將瞭解如何藉助於來自預訓練網路的遷移學習來對貓和狗的影像進行分類。影像分類中遷移學習背後的直覺是,如果一個模型在大型通用資料集上進行訓練,則此模型可以有效地用作視覺世界的通用模型。它已經學習了特徵圖,這意味著使用者不必從頭開始在一個大型資料集上訓練大型模型。
閱讀更多: 如何預訓練自定義模型?
我們正在使用Google Colaboratory來執行以下程式碼。Google Colab或Colaboratory幫助在瀏覽器上執行Python程式碼,無需任何配置,並且可以免費訪問GPU(圖形處理單元)。Colaboratory構建在Jupyter Notebook之上。
示例
print("Loss and accuracy are being determined") acc = history.history['accuracy'] val_acc = history.history['val_accuracy'] loss = history.history['loss'] val_loss = history.history['val_loss'] print("The data is being visualized") plt.figure(figsize=(8, 8)) plt.subplot(2, 1, 1) plt.plot(acc, label='Training Accuracy') plt.plot(val_acc, label='Validation Accuracy') plt.legend(loc='lower right') plt.ylabel('Accuracy') plt.ylim([min(plt.ylim()),1]) plt.title('Training and Validation Accuracy') plt.subplot(2, 1, 2) plt.plot(loss, label='Training Loss') plt.plot(val_loss, label='Validation Loss') plt.legend(loc='upper right') plt.ylabel('Cross Entropy') plt.ylim([0,1.0]) plt.title('Training and Validation Loss') plt.xlabel('epoch') plt.show()
程式碼來源 −https://www.tensorflow.org/tutorials/images/transfer_learning
輸出
解釋
訓練和驗證精度/損失的學習曲線被視覺化。
這是使用MobileNet V2基本模型作為固定的特徵提取器完成的。
廣告