cutout是2017年提出的一种数据增强方法,想法比较简单,即在训练时随机裁剪掉图像的一部分,也可以看作是一种类似dropout的正则化方法。
Improved Regularization of Convolutional Neural Networks with Cutout
paper: https://arxiv.org/pdf/1708.04552.pdf
code: https://github.com/uoguelph-mlrg/Cutout
cutout采用的操作是随机裁剪掉图像中的一块正方形区域,并在原图中补0。由于作者在cutout早期版本中使用了不规则大小区域的方式,但是对比发现,固定大小区域能达到同等的效果,因此就没必要这么麻烦去生成不规则区域了。
实现代码比较简单,cutout.py,如下:
import torch
import numpy as np
class Cutout(object):
"""Randomly mask out one or more patches from an image.
Args:
n_holes (int): Number of patches to cut out of each image.
length (int): The length (in pixels) of each square patch.
"""
def __init__(self, n_holes=1, length=16):
s