HyperImageAugment
類別keras_tuner.applications.HyperImageAugment(
input_shape=None,
input_tensor=None,
rotate=0.5,
translate_x=0.4,
translate_y=0.4,
contrast=0.3,
augment_layers=3,
**kwargs
)
一個影像增強超模型。
HyperImageAugment
類別會搜尋 Keras 預處理層中影像增強操作的最佳組合。模型的輸入形狀應為 (高度, 寬度, 通道)。模型的輸出與輸入具有相同的形狀。
參數
(256, 256, 3)
。layers.Input()
的輸出),用作模型的影像輸入。rotate
是單一數字時,搜尋範圍是 [0, rotate
]。設定為 None 時,轉換會關閉。translate_x
是單一數字時,搜尋範圍是 [0, translate_x
]。設定為 None 時,轉換會關閉。translate_y
是單一數字時,搜尋範圍是 [0, translate_y
]。設定為 None 時,轉換會關閉。contrast
是單一數字時,搜尋範圍是 [0, contrast
]。設定為 None 時,轉換會關閉。augment_layers
為 0 時,所有轉換會依序套用。當 augment_layers
為非零值或兩個 int 的列表時,則會使用 RandAugment 的簡單版本(https://arxiv.org/abs/1909.13719)。會建立 'augment_layers' 的搜尋空間,以搜尋 [0, augment_layers
],或介於兩個 int 之間(如果 augment_layers
為列表)。對於每個試驗,超參數 'augment_layers' 會決定套用的增強轉換層的數量,每層都會從所有可用的轉換類型中隨機選取,且每個樣本的機率均等。keras_tuner.HyperModel
。範例
hm_aug = HyperImageAugment(input_shape=(32, 32, 3),
augment_layers=0,
rotate=[0.2, 0.3],
translate_x=0.1,
translate_y=None,
contrast=None)
然後,超模型 hm_aug
將在 [0.2, 0.3] 之間搜尋 'factor_rotate',並在 [0, 0.1] 之間搜尋 'factor_translate_x'。這兩個增強會套用至所有樣本,且每個試驗都會選取因數。
hm_aug = HyperImageAugment(input_shape=(32, 32, 3),
translate_x=0.5,
translate_y=[0.2, 0.4]
contrast=None)
然後,超模型 hm_aug
將在 [0, 0.2] 之間搜尋 'factor_rotate',在 [0, 0.5] 之間搜尋 'factor_translate_x',並在 [0.2, 0.4] 之間搜尋 'factor_translate_y'。它將使用 RandAugment,並在 [0, 3] 之間搜尋 'augment_layers'。每個樣本的每一層都將從旋轉、水平平移和垂直平移中選取。