图片转tensor

tfms = transforms.Compose([transforms.Resize(224), transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),])
img = tfms(Image.open('img.jpg')).unsqueeze(0)
print(img.shape) # torch.Size([1, 3, 224, 224])
img = Image.open(img_path)
img = np.array(img, dtype=np.uint8)
if self.augmentations is not None:
    img, lbl = self.augmentations(img, lbl)
if self.is_transform:
    img, lbl = self.transform(img, lbl)

你可能感兴趣的:(笔记)