(
self,
img: PILImage,
mean: Tuple[float, float, float],
std: Tuple[float, float, float],
size: Tuple[int, int],
*args,
**kwargs
)
| 38 | ) |
| 39 | |
| 40 | def normalize( |
| 41 | self, |
| 42 | img: PILImage, |
| 43 | mean: Tuple[float, float, float], |
| 44 | std: Tuple[float, float, float], |
| 45 | size: Tuple[int, int], |
| 46 | *args, |
| 47 | **kwargs |
| 48 | ) -> Dict[str, np.ndarray]: |
| 49 | im = img.convert("RGB").resize(size, Image.Resampling.LANCZOS) |
| 50 | |
| 51 | im_ary = np.array(im) |
| 52 | im_ary = im_ary / max(np.max(im_ary), 1e-6) |
| 53 | |
| 54 | tmpImg = np.zeros((im_ary.shape[0], im_ary.shape[1], 3)) |
| 55 | tmpImg[:, :, 0] = (im_ary[:, :, 0] - mean[0]) / std[0] |
| 56 | tmpImg[:, :, 1] = (im_ary[:, :, 1] - mean[1]) / std[1] |
| 57 | tmpImg[:, :, 2] = (im_ary[:, :, 2] - mean[2]) / std[2] |
| 58 | |
| 59 | tmpImg = tmpImg.transpose((2, 0, 1)) |
| 60 | |
| 61 | return { |
| 62 | self.inner_session.get_inputs()[0] |
| 63 | .name: np.expand_dims(tmpImg, 0) |
| 64 | .astype(np.float32) |
| 65 | } |
| 66 | |
| 67 | def predict(self, img: PILImage, *args, **kwargs) -> List[PILImage]: |
| 68 | raise NotImplementedError |
no outgoing calls
no test coverage detected