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_coco_dataset.py 1.3 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import os.path as osp
  3. import tempfile
  4. import mmcv
  5. import pytest
  6. from mmdet.datasets import CocoDataset
  7. def _create_ids_error_coco_json(json_name):
  8. image = {
  9. 'id': 0,
  10. 'width': 640,
  11. 'height': 640,
  12. 'file_name': 'fake_name.jpg',
  13. }
  14. annotation_1 = {
  15. 'id': 1,
  16. 'image_id': 0,
  17. 'category_id': 0,
  18. 'area': 400,
  19. 'bbox': [50, 60, 20, 20],
  20. 'iscrowd': 0,
  21. }
  22. annotation_2 = {
  23. 'id': 1,
  24. 'image_id': 0,
  25. 'category_id': 0,
  26. 'area': 900,
  27. 'bbox': [100, 120, 30, 30],
  28. 'iscrowd': 0,
  29. }
  30. categories = [{
  31. 'id': 0,
  32. 'name': 'car',
  33. 'supercategory': 'car',
  34. }]
  35. fake_json = {
  36. 'images': [image],
  37. 'annotations': [annotation_1, annotation_2],
  38. 'categories': categories
  39. }
  40. mmcv.dump(fake_json, json_name)
  41. def test_coco_annotation_ids_unique():
  42. tmp_dir = tempfile.TemporaryDirectory()
  43. fake_json_file = osp.join(tmp_dir.name, 'fake_data.json')
  44. _create_ids_error_coco_json(fake_json_file)
  45. # test annotation ids not unique error
  46. with pytest.raises(AssertionError):
  47. CocoDataset(ann_file=fake_json_file, classes=('car', ), pipeline=[])

No Description

Contributors (2)