看到很多代码会有类似于这种数据增强变换
T = transforms.Compose([
transforms.ToTensor(),
transforms.Resize(120),
transforms.CenterCrop(120),
])
有些疑惑,既然resize成120了,又crop一样大小,不是白忙活了吗?后来阅读了一下源码,发现,resize是取了一个最小的边给缩放到120,整体是不会变形的,并不是变成120120。再结合crop,才给变成120120,
具体见官方文档解释.
- Parameters:
size (sequence or int) –
Desired output size. If size is a sequence like (h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size).
效果参考 https://www.jianshu.com/p/43b541caba7f