img should be PIL Image. Got <class 'numpy.ndarray'>
解决方法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)])
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/jacke121/article/details/121723792
内容来源于网络,如有侵权,请联系作者删除!