MCPcopy Create free account
hub / github.com/DingXiaoH/RepVGG / CachedImageFolder

Class CachedImageFolder

data/cached_image_folder.py:201–244  ·  view source on GitHub ↗

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 Args: root (string): Root directory path. transform (cal

Source from the content-addressed store, hash-verified

199
200
201class CachedImageFolder(DatasetFolder):
202 """A generic data loader where the images are arranged in this way: ::
203 root/dog/xxx.png
204 root/dog/xxy.png
205 root/dog/xxz.png
206 root/cat/123.png
207 root/cat/nsdf3.png
208 root/cat/asd932_.png
209 Args:
210 root (string): Root directory path.
211 transform (callable, optional): A function/transform that takes in an PIL image
212 and returns a transformed version. E.g, ``transforms.RandomCrop``
213 target_transform (callable, optional): A function/transform that takes in the
214 target and transforms it.
215 loader (callable, optional): A function to load an image given its path.
216 Attributes:
217 imgs (list): List of (image path, class_index) tuples
218 """
219
220 def __init__(self, root, ann_file='', img_prefix='', transform=None, target_transform=None,
221 loader=default_img_loader, cache_mode="no"):
222 super(CachedImageFolder, self).__init__(root, loader, IMG_EXTENSIONS,
223 ann_file=ann_file, img_prefix=img_prefix,
224 transform=transform, target_transform=target_transform,
225 cache_mode=cache_mode)
226 self.imgs = self.samples
227
228 def __getitem__(self, index):
229 """
230 Args:
231 index (int): Index
232 Returns:
233 tuple: (image, target) where target is class_index of the target class.
234 """
235 path, target = self.samples[index]
236 image = self.loader(path)
237 if self.transform is not None:
238 img = self.transform(image)
239 else:
240 img = image
241 if self.target_transform is not None:
242 target = self.target_transform(target)
243
244 return img, target

Callers 1

build_datasetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected