(self, idx)
| 101 | return len(self.local_images) |
| 102 | |
| 103 | def __getitem__(self, idx): |
| 104 | path = self.local_images[idx] |
| 105 | with bf.BlobFile(path, "rb") as f: |
| 106 | pil_image = Image.open(f) |
| 107 | pil_image.load() |
| 108 | pil_image = pil_image.convert("RGB") |
| 109 | |
| 110 | if self.random_crop: |
| 111 | arr = random_crop_arr(pil_image, self.resolution) |
| 112 | else: |
| 113 | arr = center_crop_arr(pil_image, self.resolution) |
| 114 | |
| 115 | if self.random_flip and random.random() < 0.5: |
| 116 | arr = arr[:, ::-1] |
| 117 | |
| 118 | arr = arr.astype(np.float32) / 127.5 - 1 |
| 119 | |
| 120 | out_dict = {} |
| 121 | if self.local_classes is not None: |
| 122 | out_dict["y"] = np.array(self.local_classes[idx], dtype=np.int64) |
| 123 | return np.transpose(arr, [2, 0, 1]), out_dict |
| 124 | |
| 125 | |
| 126 | def center_crop_arr(pil_image, image_size): |
nothing calls this directly
no test coverage detected