File "C:\ProgramData\Anaconda3\envs\pt19py38uuuuu\lib\site-packages\torch\nn\modules\conv.py", line 439, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: Given groups=1, weight of size [768, 3, 16, 16], expected input[32, 224, 224, 3] to have 3 channels, but got 224 channels instead
就像如上报错显示, 卷积层要求你的输入格式为(N, C, H, W), 输入通道为3, 而你通过debug发现你的格式为[32, 224, 224, 3] 即(N, H, W,C),提示你需要3通道,你却提供了224通道。
这个原因是因为你的transform.Compose中缺少Totensor(或者TotensorV2),而
torchvision.transforms.ToTensor
做了什么:
简单来说就是把PIL.Image或ndarray从 (H x W x C)形状转换为 (C x H x W) 的tensor
这就是原因所在!!