1.torchvision.datasets.ImageFolder(root,transform=None,target_transform=None,loader=default_loader)
??????? 是一种组织数据集的方法,把存在文件夹里的数据转化成用来训练和测试的数据集,
root参数是地址,必须写到分类文件夹的上一层,transform是图片转换形式,target_transform :对label进行变换,loader: 指定加载图片的函数,默认操作是读取PIL image对象
train_data_transforms=transforms.Compose([transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485,0.456,0.406],0.229,0.224,0.225])])
train_data_dir="10_monkey_species/training/training"#下次层一定是分类文件夹
train_data=ImageFolder(train_data_dir,transform=train_data_transforms)
train_data_loader=Data.DataLoader(train_data,batch_size=32,shuffle=True,num_workers=2)
|