(raw_pil_img, img_size)
| 6 | |
| 7 | |
| 8 | def _prepare_pil_image(raw_pil_img, img_size): |
| 9 | raw_pil_img = raw_pil_img.convert('RGB') |
| 10 | w, h = raw_pil_img.size |
| 11 | coef = w / h |
| 12 | image_h, image_w = img_size, img_size |
| 13 | if coef >= 1: |
| 14 | image_w = int(round(img_size / 8 * coef) * 8) |
| 15 | else: |
| 16 | image_h = int(round(img_size / 8 / coef) * 8) |
| 17 | |
| 18 | pil_img = raw_pil_img.resize( |
| 19 | (image_w, image_h), resample=getattr(Image, 'Resampling', Image).BICUBIC, reducing_gap=None |
| 20 | ) |
| 21 | img = np.array(pil_img) |
| 22 | img = img.astype(np.float32) / 127.5 - 1 |
| 23 | img = np.transpose(img, [2, 0, 1]) |
| 24 | img = torch.from_numpy(img).unsqueeze(0) |
| 25 | return img |
no outgoing calls
no test coverage detected