Prepare image for inputting to the neural network. Returns a Variable
(img, inp_dim)
| 22 | |
| 23 | |
| 24 | def prep_image(img, inp_dim): |
| 25 | """ |
| 26 | Prepare image for inputting to the neural network. |
| 27 | |
| 28 | Returns a Variable |
| 29 | """ |
| 30 | if type(img) == str: |
| 31 | orig_im = cv2.imread(img) |
| 32 | else: |
| 33 | orig_im = img |
| 34 | dim = orig_im.shape[1], orig_im.shape[0] |
| 35 | img = (letterbox_image(orig_im, (inp_dim, inp_dim))) |
| 36 | img_ = img[:, :, ::-1].transpose((2, 0, 1)).copy() |
| 37 | img_ = torch.from_numpy(img_).float().div(255.0).unsqueeze(0) |
| 38 | return img_, orig_im, dim |
| 39 | |
| 40 | |
| 41 | def prep_image_pil(img, network_dim): |
nothing calls this directly
no test coverage detected