PyTorch-导入自己文件夹里面的图像-使用imagefolder
先在自己的路径下创建文件夹 然后把自己想要放进去的图片放进去
import torch import numpy as np import torchvision #torch的视觉包 import torchvision.datasets as datasets import torchvision.transforms as transforms import matplotlib.pyplot as plt import os os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE" data=datasets.ImageFolder(root='D:/Project_Encyclopedia/catdog') help(data) data.classes#类别 data.class_to_idx #具体的类别 data.imgs len(data) type(data) data[0] data[0][0] data[0][1] plt.imshow(data[1][0]) new_im=transforms.Resize((224,224))(data[1][0]) plt.imshow(new_im)
转载请注明出处,欢迎讨论和交流!