- ValueError: Expected input batch_size (16) to match target batch_size (4).
原因:之前用的数据集输入尺寸为batch*3*32*32,每张图片尺寸为3*32*32,现在的是3*64*64,因此需要修改网络输入尺寸,否则Pytorch会将输入resize到原来的3*32*32,以新的数据集为3*64*64来说,就会将一个输入resize成4个,得到4*batch*3*32*32的Tensors,因此batchsize也会产生错误,变为原来的4倍,也就是target的4倍。
对于我来说,我用了transforms
的RandomCrop
。
#Define transformations for the training set,
#flip the images randomly, crop out and apply mean and std normalization
train_transformations = transforms.Compose([
transforms.RandomHorizontalFlip(),