第14章コンピュータビジョン
14.13.2. Image Augmentation14.13.2 画像の拡張
We use image augmentation to address overfitting. For example, images can be flipped horizontally at random during training. We can also perform standardization for the three RGB channels of color images. Below lists some of these operations that you can tweak.
英語のヒント
過学習に対処するため、画像の拡張を使う。たとえば、訓練のあいだ、画像をランダムに左右に反転できる。カラー画像の三つのRGBチャネルを標準化することもできる。下に、調整できるこうした操作のいくつかを挙げる。
transform_train = torchvision.transforms.Compose([
# Scale the image up to a square of 40 pixels in both height and width
torchvision.transforms.Resize(40),
# Randomly crop a square image of 40 pixels in both height and width to
# produce a small square of 0.64 to 1 times the area of the original
# image, and then scale it to a square of 32 pixels in both height and
# width
torchvision.transforms.RandomResizedCrop(32, scale=(0.64, 1.0),
ratio=(1.0, 1.0)),
torchvision.transforms.RandomHorizontalFlip(),
torchvision.transforms.ToTensor(),
# Standardize each channel of the image
torchvision.transforms.Normalize([0.4914, 0.4822, 0.4465],
[0.2023, 0.1994, 0.2010])])During testing, we only perform standardization on images so as to remove randomness in the evaluation results.
英語のヒント
テストのあいだは、評価結果からランダムさを取り除くため、画像の標準化だけを行う。
transform_test = torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize([0.4914, 0.4822, 0.4465],
[0.2023, 0.1994, 0.2010])])