Forked from andrewjong/pytorch_image_folder_with_file_paths.py
Created
October 24, 2019 13:10
-
-
Save JessicaDuFirst/5be1bb20af15a68223a2848473fe0dfa to your computer and use it in GitHub Desktop.
Revisions
-
andrewjong revised this gist
Jul 4, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ class ImageFolderWithPaths(datasets.ImageFolder): torchvision.datasets.ImageFolder """ # override the __getitem__ method. this is the method that dataloader calls def __getitem__(self, index): # this is what ImageFolder normally returns original_tuple = super(ImageFolderWithPaths, self).__getitem__(index) -
andrewjong revised this gist
Nov 5, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,8 @@ def __getitem__(self, index): # make a new tuple that includes original and the path tuple_with_path = (original_tuple + (path,)) return tuple_with_path # EXAMPLE USAGE: # instantiate the dataset and dataloader data_dir = "your/data_dir/here" dataset = ImageFolderWithPaths(data_dir) # our custom dataset -
andrewjong revised this gist
Jun 27, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ from torchvision import datasets class ImageFolderWithPaths(datasets.ImageFolder): """Custom dataset that includes image file paths. Extends torchvision.datasets.ImageFolder """ -
andrewjong revised this gist
Jun 27, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ class ImageFolderWithPaths(datasets.ImageFolder): torchvision.datasets.ImageFolder """ # override the __getitem__ method. this is the method dataloader calls def __getitem__(self, index): # this is what ImageFolder normally returns original_tuple = super(ImageFolderWithPaths, self).__getitem__(index) -
andrewjong revised this gist
Jun 27, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,4 +24,4 @@ def __getitem__(self, index): # iterate over data for inputs, labels, paths in dataloader: # use the above variables freely print(inputs, labels, paths) -
andrewjong revised this gist
Jun 27, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def __getitem__(self, index): dataset = ImageFolderWithPaths(data_dir) # our custom dataset dataloader = torch.utils.DataLoader(dataset) # iterate over data for inputs, labels, paths in dataloader: # use the above variables freely pass -
andrewjong revised this gist
Jun 27, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,9 +18,10 @@ def __getitem__(self, index): # instantiate the dataset and dataloader data_dir = "your/data_dir/here" dataset = ImageFolderWithPaths(data_dir) # our custom dataset dataloader = torch.utils.DataLoader(dataset) # iterate over data like this for inputs, labels, paths in dataloader: # use the above variables freely pass -
andrewjong created this gist
Jun 27, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import torch from torchvision import datasets class ImageFolderWithPaths(datasets.ImageFolder): """Custom dataset that includes image paths. Extends torchvision.datasets.ImageFolder """ # override the __getitem__ method that dataloader calls 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 # instantiate the dataset and dataloader data_dir = "your/data_dir/here" dataset = ImageFolderWithPaths(data_dir) dataloader = torch.utils.DataLoader(dataset) for inputs, labels, paths in dataloader: # use the above variables freely pass