如何使用Tensorflow配置花卉資料集以提高效能?
花卉資料集在建立模型時會給出一定的準確率。如果需要配置模型以提高效能,則定義一個函式,該函式第二次執行緩衝預取,然後進行洗牌。此函式用於訓練資料集以提高模型的效能。
閱讀更多: 什麼是TensorFlow以及Keras如何與TensorFlow一起建立神經網路?
我們將使用花卉資料集,其中包含數千朵花的影像。它包含5個子目錄,每個類都有一個子目錄。
我們使用Google Colaboratory執行以下程式碼。Google Colab或Colaboratory幫助透過瀏覽器執行Python程式碼,無需任何配置,並可免費訪問GPU(圖形處理單元)。Colaboratory構建在Jupyter Notebook之上。
print("A function is defined that configures the dataset for perfromance")
def configure_for_performance(ds):
ds = ds.cache()
ds = ds.shuffle(buffer_size=1000)
ds = ds.batch(batch_size)
ds = ds.prefetch(buffer_size=AUTOTUNE)
return ds
print("The function is called on training dataset")
train_ds = configure_for_performance(train_ds)
print("The function is called on validation dataset")
val_ds = configure_for_performance(val_ds)程式碼來源:https://www.tensorflow.org/tutorials/load_data/images
輸出
A function is defined that configures the dataset for perfromance The function is called on training dataset The function is called on validation dataset
解釋
- 需要使用資料集訓練模型。
- 模型首先被充分洗牌,然後分批處理,然後這些批次可用。
- 這些功能是使用“tf.data”API新增的。
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP