INNER CODE UNIT · Python

__getitem__

aangelopoulos/conformal-prediction · generation-scripts/generate-imagenet.py:18

    def __getitem__(self, index):
        # this is what ImageFolder normally returns
        original_tuple = super(ImageFolderWithPaths, self).__getitem__(index)
        # the image file path
        path = self.imgs[index][0]
        # make a new tuple that includes original and the path
        tuple_with_path = (original_tuple + (path,))
        return tuple_with_path

if __name__ == "__main__":
    with torch.no_grad():
        # Transform as in https://github.com/pytorch/examples/blob/42e5b996718797e45c46a25c55b031e6768f8440/imagenet/main.py#L92
        transform = torchvision.transforms.Compose([
                        torchvision.transforms.Resize(256),
                        torchvision.transforms.CenterCrop(224),
                        torchvision.transforms.ToTensor(),
                        torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                                         std= [0.229, 0.224, 0.225])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…