Infer score and mask for a batch of images.
(self, images)
| 201 | return scores, masks, labels_gt, masks_gt |
| 202 | |
| 203 | def _predict(self, images): |
| 204 | """Infer score and mask for a batch of images.""" |
| 205 | images = images.to(torch.float).to(self.device) |
| 206 | _ = self.forward_modules.eval() |
| 207 | |
| 208 | batchsize = images.shape[0] |
| 209 | with torch.no_grad(): |
| 210 | features, patch_shapes = self._embed(images, provide_patch_shapes=True) |
| 211 | features = np.asarray(features) |
| 212 | |
| 213 | patch_scores = image_scores = self.anomaly_scorer.predict([features])[0] |
| 214 | image_scores = self.patch_maker.unpatch_scores( |
| 215 | image_scores, batchsize=batchsize |
| 216 | ) |
| 217 | image_scores = image_scores.reshape(*image_scores.shape[:2], -1) |
| 218 | image_scores = self.patch_maker.score(image_scores) |
| 219 | |
| 220 | patch_scores = self.patch_maker.unpatch_scores( |
| 221 | patch_scores, batchsize=batchsize |
| 222 | ) |
| 223 | scales = patch_shapes[0] |
| 224 | patch_scores = patch_scores.reshape(batchsize, scales[0], scales[1]) |
| 225 | |
| 226 | masks = self.anomaly_segmentor.convert_to_segmentation(patch_scores) |
| 227 | |
| 228 | return [score for score in image_scores], [mask for mask in masks] |
| 229 | |
| 230 | @staticmethod |
| 231 | def _params_file(filepath, prepend=""): |
no test coverage detected