def transform(self, transform):
     if isinstance(transform, collections.abc.MutableSequence):
         transform = torchvision.Compose(transform)
     self._transform = transform
Пример #2
0
        self.val = val
        self.sum += val * n
        self.count += n
        self.avg = self.sum / self.count




8. Image Dataset Loader:

torchvision.datasets.ImageFolder(root, transform=None, target_transform=None, loader=<function default_loader>)
>>> import torchvision.datasets as datasets
>>> import torchvision as transforms
>>> transform = transforms.Compose([
        transforms.Resize(args.image_size),
        transforms.CenterCrop(args.image_size),
        transforms.ToTensor(),
        transforms.Lambda(lambda x: x.mul(255))  
    ])
>>> dataset = datasets.ImageFolder(dataset_path, transform)
# A generic data loader where the images are arranged in this way:

# root/dog/xxx.png
# root/dog/xxy.png
# root/dog/xxz.png

# root/cat/123.png
# root/cat/nsdf3.png
# root/cat/asd932_.png