Args: tensor (bool): if True, returns 3xHxW tensor. else, returns a HxWx3 numpy array. Returns: an image, in BGR color.
(tensor=True)
| 39 | |
| 40 | |
| 41 | def get_sample_coco_image(tensor=True): |
| 42 | """ |
| 43 | Args: |
| 44 | tensor (bool): if True, returns 3xHxW tensor. |
| 45 | else, returns a HxWx3 numpy array. |
| 46 | |
| 47 | Returns: |
| 48 | an image, in BGR color. |
| 49 | """ |
| 50 | try: |
| 51 | file_name = DatasetCatalog.get("coco_2017_train")[0]["file_name"] |
| 52 | if not PathManager.exists(file_name): |
| 53 | raise FileNotFoundError() |
| 54 | except IOError: |
| 55 | # for public CI to run |
| 56 | file_name = "http://images.cocodataset.org/train2017/000000000009.jpg" |
| 57 | ret = read_image(file_name, format="BGR") |
| 58 | if tensor: |
| 59 | ret = torch.from_numpy(np.ascontiguousarray(ret.transpose(2, 0, 1))) |
| 60 | return ret |
| 61 | |
| 62 | |
| 63 | def assert_instances_allclose(input, other, rtol=1e-5, msg=""): |
nothing calls this directly
no test coverage detected