You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_datasets_coco.py 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. import numpy as np
  16. import mindspore.dataset as ds
  17. import mindspore.dataset.text as text
  18. import mindspore.dataset.vision.c_transforms as vision
  19. DATA_DIR = "../data/dataset/testCOCO/train/"
  20. DATA_DIR_2 = "../data/dataset/testCOCO/train"
  21. ANNOTATION_FILE = "../data/dataset/testCOCO/annotations/train.json"
  22. KEYPOINT_FILE = "../data/dataset/testCOCO/annotations/key_point.json"
  23. PANOPTIC_FILE = "../data/dataset/testCOCO/annotations/panoptic.json"
  24. INVALID_FILE = "../data/dataset/testCOCO/annotations/invalid.json"
  25. LACKOFIMAGE_FILE = "../data/dataset/testCOCO/annotations/lack_of_images.json"
  26. INVALID_CATEGORY_ID_FILE = "../data/dataset/testCOCO/annotations/invalid_category_id.json"
  27. def test_coco_detection():
  28. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection",
  29. decode=True, shuffle=False, extra_metadata=True)
  30. data1 = data1.rename("_meta-filename", "filename")
  31. num_iter = 0
  32. file_name = []
  33. image_shape = []
  34. bbox = []
  35. category_id = []
  36. for data in data1.create_dict_iterator(num_epochs=1, output_numpy=True):
  37. file_name.append(text.to_str(data["filename"]))
  38. image_shape.append(data["image"].shape)
  39. bbox.append(data["bbox"])
  40. category_id.append(data["category_id"])
  41. num_iter += 1
  42. assert num_iter == 6
  43. assert file_name == ["000000391895", "000000318219", "000000554625", "000000574769",
  44. "000000060623", "000000309022"]
  45. assert image_shape[0] == (2268, 4032, 3)
  46. assert image_shape[1] == (561, 595, 3)
  47. assert image_shape[2] == (607, 585, 3)
  48. assert image_shape[3] == (642, 675, 3)
  49. assert image_shape[4] == (2268, 4032, 3)
  50. assert image_shape[5] == (2268, 4032, 3)
  51. np.testing.assert_array_equal(np.array([[10., 10., 10., 10.], [70., 70., 70., 70.]]), bbox[0])
  52. np.testing.assert_array_equal(np.array([[20., 20., 20., 20.], [80., 80., 80.0, 80.]]), bbox[1])
  53. np.testing.assert_array_equal(np.array([[30.0, 30.0, 30.0, 30.]]), bbox[2])
  54. np.testing.assert_array_equal(np.array([[40., 40., 40., 40.]]), bbox[3])
  55. np.testing.assert_array_equal(np.array([[50., 50., 50., 50.]]), bbox[4])
  56. np.testing.assert_array_equal(np.array([[60., 60., 60., 60.]]), bbox[5])
  57. np.testing.assert_array_equal(np.array([[1], [7]]), category_id[0])
  58. np.testing.assert_array_equal(np.array([[2], [8]]), category_id[1])
  59. np.testing.assert_array_equal(np.array([[3]]), category_id[2])
  60. np.testing.assert_array_equal(np.array([[4]]), category_id[3])
  61. np.testing.assert_array_equal(np.array([[5]]), category_id[4])
  62. np.testing.assert_array_equal(np.array([[6]]), category_id[5])
  63. def test_coco_stuff():
  64. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Stuff",
  65. decode=True, shuffle=False, extra_metadata=True)
  66. data1 = data1.rename("_meta-filename", "filename")
  67. num_iter = 0
  68. file_name = []
  69. image_shape = []
  70. segmentation = []
  71. iscrowd = []
  72. for data in data1.create_dict_iterator(num_epochs=1, output_numpy=True):
  73. file_name.append(text.to_str(data["filename"]))
  74. image_shape.append(data["image"].shape)
  75. segmentation.append(data["segmentation"])
  76. iscrowd.append(data["iscrowd"])
  77. num_iter += 1
  78. assert num_iter == 6
  79. assert file_name == ["000000391895", "000000318219", "000000554625", "000000574769",
  80. "000000060623", "000000309022"]
  81. assert image_shape[0] == (2268, 4032, 3)
  82. assert image_shape[1] == (561, 595, 3)
  83. assert image_shape[2] == (607, 585, 3)
  84. assert image_shape[3] == (642, 675, 3)
  85. assert image_shape[4] == (2268, 4032, 3)
  86. assert image_shape[5] == (2268, 4032, 3)
  87. np.testing.assert_array_equal(np.array([[10., 12., 13., 14., 15., 16., 17., 18., 19., 20.],
  88. [70., 72., 73., 74., 75., -1., -1., -1., -1., -1.]]),
  89. segmentation[0])
  90. np.testing.assert_array_equal(np.array([[0], [0]]), iscrowd[0])
  91. np.testing.assert_array_equal(np.array([[20.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0],
  92. [10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, -1.0]]),
  93. segmentation[1])
  94. np.testing.assert_array_equal(np.array([[0], [1]]), iscrowd[1])
  95. np.testing.assert_array_equal(np.array([[40., 42., 43., 44., 45., 46., 47., 48., 49., 40., 41., 42.]]),
  96. segmentation[2])
  97. np.testing.assert_array_equal(np.array([[0]]), iscrowd[2])
  98. np.testing.assert_array_equal(np.array([[50., 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63.]]),
  99. segmentation[3])
  100. np.testing.assert_array_equal(np.array([[0]]), iscrowd[3])
  101. np.testing.assert_array_equal(np.array([[60., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71., 72., 73., 74.]]),
  102. segmentation[4])
  103. np.testing.assert_array_equal(np.array([[0]]), iscrowd[4])
  104. np.testing.assert_array_equal(np.array([[60., 62., 63., 64., 65., 66., 67.], [68., 69., 70., 71., 72., 73., 74.]]),
  105. segmentation[5])
  106. np.testing.assert_array_equal(np.array([[0]]), iscrowd[5])
  107. def test_coco_keypoint():
  108. data1 = ds.CocoDataset(DATA_DIR, annotation_file=KEYPOINT_FILE, task="Keypoint",
  109. decode=True, shuffle=False, extra_metadata=True)
  110. data1 = data1.rename("_meta-filename", "filename")
  111. num_iter = 0
  112. file_name = []
  113. image_shape = []
  114. keypoints = []
  115. num_keypoints = []
  116. for data in data1.create_dict_iterator(num_epochs=1, output_numpy=True):
  117. file_name.append(text.to_str(data["filename"]))
  118. image_shape.append(data["image"].shape)
  119. keypoints.append(data["keypoints"])
  120. num_keypoints.append(data["num_keypoints"])
  121. num_iter += 1
  122. assert num_iter == 2
  123. assert file_name == ["000000391895", "000000318219"]
  124. assert image_shape[0] == (2268, 4032, 3)
  125. assert image_shape[1] == (561, 595, 3)
  126. np.testing.assert_array_equal(np.array([[368., 61., 1., 369., 52., 2., 0., 0., 0., 382., 48., 2., 0., 0., 0., 368.,
  127. 84., 2., 435., 81., 2., 362., 125., 2., 446., 125., 2., 360., 153., 2., 0.,
  128. 0., 0., 397., 167., 1., 439., 166., 1., 369., 193., 2., 461., 234., 2.,
  129. 361., 246., 2., 474., 287., 2.]]), keypoints[0])
  130. np.testing.assert_array_equal(np.array([[14]]), num_keypoints[0])
  131. np.testing.assert_array_equal(np.array([[244., 139., 2., 0., 0., 0., 226., 118., 2., 0., 0., 0., 154., 159., 2.,
  132. 143., 261., 2., 135., 312., 2., 271., 423., 2., 184., 530., 2., 261., 280.,
  133. 2., 347., 592., 2., 0., 0., 0., 123., 596., 2., 0., 0., 0., 0., 0., 0., 0.,
  134. 0., 0., 0., 0., 0.]]),
  135. keypoints[1])
  136. np.testing.assert_array_equal(np.array([[10]]), num_keypoints[1])
  137. def test_coco_panoptic():
  138. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic", decode=True, shuffle=False,
  139. extra_metadata=True)
  140. data1 = data1.rename("_meta-filename", "filename")
  141. num_iter = 0
  142. file_name = []
  143. image_shape = []
  144. bbox = []
  145. category_id = []
  146. iscrowd = []
  147. area = []
  148. for data in data1.create_dict_iterator(num_epochs=1, output_numpy=True):
  149. file_name.append(text.to_str(data["filename"]))
  150. image_shape.append(data["image"].shape)
  151. bbox.append(data["bbox"])
  152. category_id.append(data["category_id"])
  153. iscrowd.append(data["iscrowd"])
  154. area.append(data["area"])
  155. num_iter += 1
  156. assert num_iter == 2
  157. assert file_name == ["000000391895", "000000574769"]
  158. assert image_shape[0] == (2268, 4032, 3)
  159. np.testing.assert_array_equal(np.array([[472, 173, 36, 48], [340, 22, 154, 301], [486, 183, 30, 35]]), bbox[0])
  160. np.testing.assert_array_equal(np.array([[1], [1], [2]]), category_id[0])
  161. np.testing.assert_array_equal(np.array([[0], [0], [0]]), iscrowd[0])
  162. np.testing.assert_array_equal(np.array([[705], [14062], [626]]), area[0])
  163. assert image_shape[1] == (642, 675, 3)
  164. np.testing.assert_array_equal(np.array([[103, 133, 229, 422], [243, 175, 93, 164]]), bbox[1])
  165. np.testing.assert_array_equal(np.array([[1], [3]]), category_id[1])
  166. np.testing.assert_array_equal(np.array([[0], [0]]), iscrowd[1])
  167. np.testing.assert_array_equal(np.array([[43102], [6079]]), area[1])
  168. def test_coco_meta_column():
  169. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection",
  170. decode=True, shuffle=False, extra_metadata=True)
  171. for item in data1.create_tuple_iterator():
  172. assert len(item) == 4
  173. data2 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Stuff",
  174. decode=True, shuffle=False, extra_metadata=True)
  175. for item in data2.create_tuple_iterator():
  176. assert len(item) == 3
  177. data3 = ds.CocoDataset(DATA_DIR, annotation_file=KEYPOINT_FILE, task="Keypoint",
  178. decode=True, shuffle=False, extra_metadata=True)
  179. for item in data3.create_tuple_iterator():
  180. assert len(item) == 3
  181. data4 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic",
  182. decode=True, shuffle=False, extra_metadata=True)
  183. for item in data4.create_tuple_iterator():
  184. assert len(item) == 5
  185. def test_coco_detection_classindex():
  186. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection", decode=True)
  187. class_index = data1.get_class_indexing()
  188. assert class_index == {'person': [1], 'bicycle': [2], 'car': [3], 'cat': [4], 'dog': [5], 'monkey': [6],
  189. 'bag': [7], 'orange': [8]}
  190. num_iter = 0
  191. for _ in data1.create_dict_iterator(output_numpy=True):
  192. num_iter += 1
  193. assert num_iter == 6
  194. def test_coco_panootic_classindex():
  195. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic", decode=True)
  196. class_index = data1.get_class_indexing()
  197. assert class_index == {'person': [1, 1], 'bicycle': [2, 1], 'car': [3, 1]}
  198. num_iter = 0
  199. for _ in data1.create_dict_iterator(output_numpy=True):
  200. num_iter += 1
  201. assert num_iter == 2
  202. def test_coco_case_0():
  203. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection", decode=True)
  204. data1 = data1.shuffle(10)
  205. data1 = data1.batch(3, pad_info={})
  206. num_iter = 0
  207. for _ in data1.create_dict_iterator(num_epochs=1):
  208. num_iter += 1
  209. assert num_iter == 2
  210. def test_coco_case_1():
  211. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection", decode=True)
  212. sizes = [0.5, 0.5]
  213. randomize = False
  214. dataset1, dataset2 = data1.split(sizes=sizes, randomize=randomize)
  215. num_iter = 0
  216. for _ in dataset1.create_dict_iterator(num_epochs=1):
  217. num_iter += 1
  218. assert num_iter == 3
  219. num_iter = 0
  220. for _ in dataset2.create_dict_iterator(num_epochs=1):
  221. num_iter += 1
  222. assert num_iter == 3
  223. def test_coco_case_2():
  224. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection", decode=True)
  225. resize_op = vision.Resize((224, 224))
  226. data1 = data1.map(operations=resize_op, input_columns=["image"])
  227. data1 = data1.repeat(4)
  228. num_iter = 0
  229. for _ in data1.create_dict_iterator(output_numpy=True):
  230. num_iter += 1
  231. assert num_iter == 24
  232. def test_coco_case_3():
  233. data1 = ds.CocoDataset(DATA_DIR_2, annotation_file=ANNOTATION_FILE, task="Detection", decode=True)
  234. resize_op = vision.Resize((224, 224))
  235. data1 = data1.map(operations=resize_op, input_columns=["image"])
  236. data1 = data1.repeat(4)
  237. num_iter = 0
  238. for _ in data1.create_dict_iterator(output_numpy=True):
  239. num_iter += 1
  240. assert num_iter == 24
  241. def test_coco_case_exception():
  242. try:
  243. data1 = ds.CocoDataset("path_not_exist/", annotation_file=ANNOTATION_FILE, task="Detection")
  244. for _ in data1.create_dict_iterator(output_numpy=True):
  245. pass
  246. assert False
  247. except ValueError as e:
  248. assert "does not exist or is not a directory or permission denied" in str(e)
  249. try:
  250. data1 = ds.CocoDataset(DATA_DIR, annotation_file="./file_not_exist", task="Detection")
  251. for _ in data1.create_dict_iterator(output_numpy=True):
  252. pass
  253. assert False
  254. except ValueError as e:
  255. assert "does not exist or permission denied" in str(e)
  256. try:
  257. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Invalid task")
  258. for _ in data1.create_dict_iterator(output_numpy=True):
  259. pass
  260. assert False
  261. except ValueError as e:
  262. assert "Invalid task type" in str(e)
  263. try:
  264. data1 = ds.CocoDataset(DATA_DIR, annotation_file=LACKOFIMAGE_FILE, task="Detection")
  265. for _ in data1.create_dict_iterator(output_numpy=True):
  266. pass
  267. assert False
  268. except RuntimeError as e:
  269. assert "required node not found in JSON" in str(e)
  270. try:
  271. data1 = ds.CocoDataset(DATA_DIR, annotation_file=INVALID_CATEGORY_ID_FILE, task="Detection")
  272. for _ in data1.create_dict_iterator(output_numpy=True):
  273. pass
  274. assert False
  275. except RuntimeError as e:
  276. assert "category_id can't find in categories" in str(e)
  277. try:
  278. data1 = ds.CocoDataset(DATA_DIR, annotation_file=INVALID_FILE, task="Detection")
  279. for _ in data1.create_dict_iterator(output_numpy=True):
  280. pass
  281. assert False
  282. except RuntimeError as e:
  283. assert "failed to open JSON file" in str(e)
  284. try:
  285. sampler = ds.PKSampler(3)
  286. data1 = ds.CocoDataset(DATA_DIR, annotation_file=INVALID_FILE, task="Detection", sampler=sampler)
  287. for _ in data1.create_dict_iterator(output_numpy=True):
  288. pass
  289. assert False
  290. except ValueError as e:
  291. assert "CocoDataset doesn't support PKSampler" in str(e)
  292. def exception_func(item):
  293. raise Exception("Error occur!")
  294. try:
  295. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection")
  296. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  297. for _ in data1.create_dict_iterator(output_numpy=True):
  298. pass
  299. assert False
  300. except RuntimeError as e:
  301. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  302. try:
  303. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection")
  304. data1 = data1.map(operations=vision.Decode(), input_columns=["image"], num_parallel_workers=1)
  305. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  306. for _ in data1.create_dict_iterator(output_numpy=True):
  307. pass
  308. assert False
  309. except RuntimeError as e:
  310. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  311. try:
  312. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection")
  313. data1 = data1.map(operations=exception_func, input_columns=["bbox"], num_parallel_workers=1)
  314. for _ in data1.create_dict_iterator(output_numpy=True):
  315. pass
  316. assert False
  317. except RuntimeError as e:
  318. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  319. try:
  320. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Detection")
  321. data1 = data1.map(operations=exception_func, input_columns=["category_id"], num_parallel_workers=1)
  322. for _ in data1.create_dict_iterator(output_numpy=True):
  323. pass
  324. assert False
  325. except RuntimeError as e:
  326. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  327. try:
  328. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Stuff")
  329. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  330. for _ in data1.create_dict_iterator(output_numpy=True):
  331. pass
  332. assert False
  333. except RuntimeError as e:
  334. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  335. try:
  336. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Stuff")
  337. data1 = data1.map(operations=vision.Decode(), input_columns=["image"], num_parallel_workers=1)
  338. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  339. for _ in data1.create_dict_iterator(output_numpy=True):
  340. pass
  341. assert False
  342. except RuntimeError as e:
  343. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  344. try:
  345. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Stuff")
  346. data1 = data1.map(operations=exception_func, input_columns=["segmentation"], num_parallel_workers=1)
  347. for _ in data1.create_dict_iterator(output_numpy=True):
  348. pass
  349. assert False
  350. except RuntimeError as e:
  351. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  352. try:
  353. data1 = ds.CocoDataset(DATA_DIR, annotation_file=ANNOTATION_FILE, task="Stuff")
  354. data1 = data1.map(operations=exception_func, input_columns=["iscrowd"], num_parallel_workers=1)
  355. for _ in data1.create_dict_iterator(output_numpy=True):
  356. pass
  357. assert False
  358. except RuntimeError as e:
  359. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  360. try:
  361. data1 = ds.CocoDataset(DATA_DIR, annotation_file=KEYPOINT_FILE, task="Keypoint")
  362. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  363. for _ in data1.create_dict_iterator(output_numpy=True):
  364. pass
  365. assert False
  366. except RuntimeError as e:
  367. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  368. try:
  369. data1 = ds.CocoDataset(DATA_DIR, annotation_file=KEYPOINT_FILE, task="Keypoint")
  370. data1 = data1.map(operations=vision.Decode(), input_columns=["image"], num_parallel_workers=1)
  371. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  372. for _ in data1.create_dict_iterator(output_numpy=True):
  373. pass
  374. assert False
  375. except RuntimeError as e:
  376. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  377. try:
  378. data1 = ds.CocoDataset(DATA_DIR, annotation_file=KEYPOINT_FILE, task="Keypoint")
  379. data1 = data1.map(operations=exception_func, input_columns=["keypoints"], num_parallel_workers=1)
  380. for _ in data1.create_dict_iterator(output_numpy=True):
  381. pass
  382. assert False
  383. except RuntimeError as e:
  384. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  385. try:
  386. data1 = ds.CocoDataset(DATA_DIR, annotation_file=KEYPOINT_FILE, task="Keypoint")
  387. data1 = data1.map(operations=exception_func, input_columns=["num_keypoints"], num_parallel_workers=1)
  388. for _ in data1.create_dict_iterator(output_numpy=True):
  389. pass
  390. assert False
  391. except RuntimeError as e:
  392. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  393. try:
  394. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic")
  395. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  396. for _ in data1.create_dict_iterator(output_numpy=True):
  397. pass
  398. assert False
  399. except RuntimeError as e:
  400. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  401. try:
  402. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic")
  403. data1 = data1.map(operations=vision.Decode(), input_columns=["image"], num_parallel_workers=1)
  404. data1 = data1.map(operations=exception_func, input_columns=["image"], num_parallel_workers=1)
  405. for _ in data1.create_dict_iterator(output_numpy=True):
  406. pass
  407. assert False
  408. except RuntimeError as e:
  409. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  410. try:
  411. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic")
  412. data1 = data1.map(operations=exception_func, input_columns=["bbox"], num_parallel_workers=1)
  413. for _ in data1.create_dict_iterator(output_numpy=True):
  414. pass
  415. assert False
  416. except RuntimeError as e:
  417. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  418. try:
  419. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic")
  420. data1 = data1.map(operations=exception_func, input_columns=["category_id"], num_parallel_workers=1)
  421. for _ in data1.create_dict_iterator(output_numpy=True):
  422. pass
  423. assert False
  424. except RuntimeError as e:
  425. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  426. try:
  427. data1 = ds.CocoDataset(DATA_DIR, annotation_file=PANOPTIC_FILE, task="Panoptic")
  428. data1 = data1.map(operations=exception_func, input_columns=["area"], num_parallel_workers=1)
  429. for _ in data1.create_dict_iterator(output_numpy=True):
  430. pass
  431. assert False
  432. except RuntimeError as e:
  433. assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
  434. if __name__ == '__main__':
  435. test_coco_detection()
  436. test_coco_stuff()
  437. test_coco_keypoint()
  438. test_coco_panoptic()
  439. test_coco_detection_classindex()
  440. test_coco_panootic_classindex()
  441. test_coco_case_0()
  442. test_coco_case_1()
  443. test_coco_case_2()
  444. test_coco_case_3()
  445. test_coco_case_exception()