img should be PIL Image. Got <class ‘numpy.ndarray‘>

img should be PIL Image. Got

解决方法1:

from PIL import Image PIL_image = Image.fromarray(ndarray_image) #这里ndarray_image为原来的numpy数组类型的输入

解决方法2:

import math
import random

import torch

# -*- coding: utf-8 -*-

import numpy as np
import cv2
from torchvision.transforms import transforms

def __resize(img):
    data=random.randrange(84,128,1)
    temp=img.resize((data,data))
    tempp=temp.resize((128,128))
    return tempp
transformx=transforms.Lambda(lambda img: __resize(img))

if __name__ == '__main__':
     train_transform = transforms.Compose([
          transforms.RandomChoice([transforms.ToPILImage(),
          transforms.ColorJitter(brightness=(0.6, 1.4)),
          transforms.RandomResizedCrop((128, 128), scale=(0.9, 1.0), ratio=(1.0, 1.0), interpolation=3), transforms.RandomApply([transformx], p=0.15)]), transforms.ToTensor(),
          transforms.Normalize(mean=0.5, std=0.5)])

你可能感兴趣的:(pytorch知识宝典,python,深度学习)