2 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
由于您有一個(gè)自定義序列生成器,您可以創(chuàng)建一個(gè)在紀(jì)元開(kāi)始或結(jié)束時(shí)運(yùn)行的函數(shù)。您可以在其中放置代碼來(lái)修改圖像。文檔位于[此處。][1]
Epoch-level methods (training only)
on_epoch_begin(self, epoch, logs=None)
Called at the beginning of an epoch during training.
on_epoch_end(self, epoch, logs=None)
Called at the end of an epoch during training.
[1]: https://keras.io/guides/writing_your_own_callbacks/

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
沒(méi)有必要CustomCallback為此目的創(chuàng)建一個(gè);最后,您希望在訓(xùn)練期間進(jìn)行增強(qiáng)。
解決方案是應(yīng)用旋轉(zhuǎn)操作的概率
# read, resize and rotate the image and return a batch of images
def __getitem__(self, idx):
angle = self.angles[self.current_angle_idx]
print(f"Rotating Angle: {angle}")
batch_x = self.filenames[idx * self.batch_size:(idx + 1) * self.batch_size]
batch_y = self.labels[idx * self.batch_size:(idx + 1) * self.batch_size]
#These new lines (say we augment with probability > 0.5)
#Number between 0 and 1
images = []
for filename in batch_x:
probability = random.random()
apply_rotate = probability > 0.5
if apply_rotate:
images.append(rotate(resize(imread(filename), (15, 15)), angle))
else:
images.append(resize(imread(filename), (15, 15)))
return np.array(images), np.array(batch_y)
添加回答
舉報(bào)