MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / get_sample_coco_image

Function get_sample_coco_image

detectron2/utils/testing.py:41–60  ·  view source on GitHub ↗

Args: tensor (bool): if True, returns 3xHxW tensor. else, returns a HxWx3 numpy array. Returns: an image, in BGR color.

(tensor=True)

Source from the content-addressed store, hash-verified

39
40
41def 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
63def assert_instances_allclose(input, other, rtol=1e-5, msg=""):

Callers

nothing calls this directly

Calls 2

read_imageFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected