(self, root, instance)
| 101 | return metadata, stats |
| 102 | |
| 103 | def get_instance(self, root, instance): |
| 104 | pack = super().get_instance(root, instance) |
| 105 | |
| 106 | image_root = os.path.join(root, 'renders_cond', instance) |
| 107 | with open(os.path.join(image_root, 'transforms.json')) as f: |
| 108 | metadata = json.load(f) |
| 109 | n_views = len(metadata['frames']) |
| 110 | view = np.random.randint(n_views) |
| 111 | metadata = metadata['frames'][view] |
| 112 | |
| 113 | image_path = os.path.join(image_root, metadata['file_path']) |
| 114 | image = Image.open(image_path) |
| 115 | |
| 116 | alpha = np.array(image.getchannel(3)) |
| 117 | bbox = np.array(alpha).nonzero() |
| 118 | bbox = [bbox[1].min(), bbox[0].min(), bbox[1].max(), bbox[0].max()] |
| 119 | center = [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2] |
| 120 | hsize = max(bbox[2] - bbox[0], bbox[3] - bbox[1]) / 2 |
| 121 | aug_size_ratio = 1.2 |
| 122 | aug_hsize = hsize * aug_size_ratio |
| 123 | aug_center_offset = [0, 0] |
| 124 | aug_center = [center[0] + aug_center_offset[0], center[1] + aug_center_offset[1]] |
| 125 | aug_bbox = [int(aug_center[0] - aug_hsize), int(aug_center[1] - aug_hsize), int(aug_center[0] + aug_hsize), int(aug_center[1] + aug_hsize)] |
| 126 | image = image.crop(aug_bbox) |
| 127 | |
| 128 | image = image.resize((self.image_size, self.image_size), Image.Resampling.LANCZOS) |
| 129 | alpha = image.getchannel(3) |
| 130 | image = image.convert('RGB') |
| 131 | image = torch.tensor(np.array(image)).permute(2, 0, 1).float() / 255.0 |
| 132 | alpha = torch.tensor(np.array(alpha)).float() / 255.0 |
| 133 | image = image * alpha.unsqueeze(0) |
| 134 | pack['cond'] = image |
| 135 | |
| 136 | return pack |
| 137 |
nothing calls this directly
no test coverage detected