testing.py 615 B

12345678910111213141516171819202122232425
  1. import json
  2. import os.path as osp
  3. import labelme.utils
  4. def assert_labelfile_sanity(filename):
  5. assert osp.exists(filename)
  6. data = json.load(open(filename))
  7. assert 'imagePath' in data
  8. imageData = data.get('imageData', None)
  9. if imageData is None:
  10. assert osp.exists(data['imagePath'])
  11. img = labelme.utils.img_b64_to_arr(imageData)
  12. H, W = img.shape[:2]
  13. assert 'shapes' in data
  14. for shape in data['shapes']:
  15. assert 'label' in shape
  16. assert 'points' in shape
  17. for x, y in shape['points']:
  18. assert 0 <= x <= W
  19. assert 0 <= y <= H