다음은 데이터 증강 기법을 적용하여 훈련 데이터의 다양성을 높이겠습니다.
class Augment(tf.keras.layers.Layer): # ①
def __init__(self, seed=42):
super().__init__()
self.augment_inputs = tf.keras.layers.RandomFlip(mode="horizontal", seed=seed)
self.augment_labels = tf.keras.layers.RandomFlip(mode="horizontal", seed=seed)
def call(self, inputs, labels):
inputs = self.augment_inputs(inputs)
labels = self.augment_labels(labels)
return inputs, labels
train_batches = (
train_images
.cache()
.shuffle(BUFFER_SIZE)
.batch(BATCH_SIZE)
.repeat()
.map(Augment())
.prefetch(buffer_size=tf.data.AUTOTUNE)) # ②
test_batches = test_images.batch(BATCH_SIZE)