| 14 | |
| 15 | @DATASETS.register_module() |
| 16 | class BinaryFaceForensic(CommonDataset): |
| 17 | def __init__(self, |
| 18 | config, |
| 19 | split, |
| 20 | **kwargs): |
| 21 | """ |
| 22 | @params: |
| 23 | config: Dataset config |
| 24 | split: train/val/test which directs to the split folders |
| 25 | """ |
| 26 | self.split = split |
| 27 | if kwargs is not None: |
| 28 | for k,v in kwargs.items(): |
| 29 | if v is None: |
| 30 | raise ValueError(f'{k}:{v} retrieve a None value!') |
| 31 | self.__setattr__(k, v) |
| 32 | super().__init__(config, **kwargs) |
| 33 | |
| 34 | #Load data |
| 35 | self.image_paths, self.labels, self.mask_paths = self._load_data(split) |
| 36 | |
| 37 | #Calling transform methods for inputs |
| 38 | self.geo_transform = build_pipeline(config.TRANSFORM.geometry, PIPELINES) |
| 39 | self.colorjitter_transform = build_pipeline(config.TRANSFORM.color, PIPELINES) |
| 40 | |
| 41 | def _load_data(self, split): |
| 42 | from_file = self._cfg.FROM_FILE |
| 43 | |
| 44 | if not from_file: |
| 45 | image_paths, labels, mask_paths = self._load_from_path(split) |
| 46 | else: |
| 47 | image_paths, labels, mask_paths = self._load_from_file(split) |
| 48 | |
| 49 | assert len(image_paths) != 0, "Image paths have not been loaded! Please check image directory!" |
| 50 | assert len(labels) != 0, "Labels have not been loaded! Please check image folder path!" |
| 51 | return image_paths, labels, mask_paths |
| 52 | |
| 53 | def _load_img(self, img_path): |
| 54 | img = Image.open(img_path) |
| 55 | img = np.array(img) |
| 56 | return img |
| 57 | |
| 58 | def __len__(self): |
| 59 | return len(self.labels) |
| 60 | |
| 61 | def __getitem__(self, idx): |
| 62 | img_path = self.image_paths[idx] |
| 63 | label = np.expand_dims(self.labels[idx], axis=-1) |
| 64 | img = self._load_img(img_path) |
| 65 | |
| 66 | #Applying geo transform to inputs |
| 67 | geo_transfomed = self.geo_transform(img) |
| 68 | img_trans = geo_transfomed['image'] |
| 69 | |
| 70 | #Applying color transform to inputs |
| 71 | color_transfomed = self.colorjitter_transform(img_trans) |
| 72 | img_trans = color_transfomed['image'] |
| 73 |
nothing calls this directly
no outgoing calls
no test coverage detected