Pytorch 通过datasets.ImageFolder直接从文件中加载数据集

     tf = transforms.Compose([
            transforms.Resize((64,64)),
            transforms.ToTensor(),
        ])
        db=torchvision.datasets.ImageFolder(root="pokemon",transform=tf)
        loader=DataLoader(db,batch_size=32,shuffle=True)
        print("make-code",db.class_to_idx)
        for x, y in loader:
            viz.images(x, nrow=8, win="batch", opts=dict(title="batch"))
            viz.text(str(y.numpy()), win="lablel", opts=dict(title="batch-y"))
            time.sleep(10)

 

你可能感兴趣的:(pytorch学习工具包)