The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0
#Convert behind('RGB)And change the number of channels to 3
input_image = Image.open(filename).convert('RGB')
from torchvision import transforms
input_image = Image.open('test.png') #This is the problem
preprocess = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
input_tensor = preprocess(input_image)
from torchvision import transforms
input_image = Image.open('test.png') #Corrected here
preprocess = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
input_tensor = preprocess(input_image)
https://stackoverflow.com/questions/58496858/pytorch-runtimeerror-the-size-of-tensor-a-4-must-match-the-size-of-tensor-b
Recommended Posts