Scale the image and output it in torch.tensor. :param img: input rgb is in shape [H, W, C], input depth/disp is in shape [H, W] :param scale: the scale factor. float :return: img. [C, H, W]
(img)
| 422 | |
| 423 | |
| 424 | def scale_torch(img): |
| 425 | """ |
| 426 | Scale the image and output it in torch.tensor. |
| 427 | :param img: input rgb is in shape [H, W, C], input depth/disp is in shape [H, W] |
| 428 | :param scale: the scale factor. float |
| 429 | :return: img. [C, H, W] |
| 430 | """ |
| 431 | if len(img.shape) == 2: |
| 432 | img = img[np.newaxis, :, :] |
| 433 | if img.shape[2] == 3: |
| 434 | transform = transforms.Compose( |
| 435 | [transforms.ToTensor(), transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))]) |
| 436 | img = transform(img.astype(np.float32)) |
| 437 | else: |
| 438 | img = img.astype(np.float32) |
| 439 | img = torch.from_numpy(img) |
| 440 | return img |
| 441 | |
| 442 | |
| 443 | def estimatezoedepth(img, model, w, h): |