(self, image: np.ndarray)
| 203 | self.images[name], self.scales[name] = self.preprocess(image) |
| 204 | |
| 205 | def preprocess(self, image: np.ndarray): |
| 206 | image = image.astype(np.float32, copy=False) |
| 207 | size = image.shape[:2][::-1] |
| 208 | scale = np.array([1.0, 1.0]) |
| 209 | |
| 210 | if self.conf.resize_max: |
| 211 | scale = self.conf.resize_max / max(size) |
| 212 | if scale < 1.0: |
| 213 | size_new = tuple(int(round(x*scale)) for x in size) |
| 214 | image = resize_image(image, size_new, 'cv2_area') |
| 215 | scale = np.array(size) / np.array(size_new) |
| 216 | |
| 217 | if self.conf.grayscale: |
| 218 | assert image.ndim == 2, image.shape |
| 219 | image = image[None] |
| 220 | else: |
| 221 | image = image.transpose((2, 0, 1)) # HxWxC to CxHxW |
| 222 | image = torch.from_numpy(image / 255.0).float() |
| 223 | |
| 224 | # assure that the size is divisible by dfactor |
| 225 | size_new = tuple(map( |
| 226 | lambda x: int(x // self.conf.dfactor * self.conf.dfactor), |
| 227 | image.shape[-2:])) |
| 228 | image = F.resize(image, size=size_new) |
| 229 | scale = np.array(size) / np.array(size_new)[::-1] |
| 230 | return image, scale |
| 231 | |
| 232 | def __len__(self): |
| 233 | return len(self.pairs) |
no test coverage detected