test_shape.py 727 B

123456789101112131415161718192021222324
  1. from labelme.utils import shape as shape_module
  2. from .util import get_img_and_data
  3. def test_shapes_to_label():
  4. img, data = get_img_and_data()
  5. label_name_to_value = {}
  6. for shape in data["shapes"]:
  7. label_name = shape["label"]
  8. label_value = len(label_name_to_value)
  9. label_name_to_value[label_name] = label_value
  10. cls, _ = shape_module.shapes_to_label(
  11. img.shape, data["shapes"], label_name_to_value
  12. )
  13. assert cls.shape == img.shape[:2]
  14. def test_shape_to_mask():
  15. img, data = get_img_and_data()
  16. for shape in data["shapes"]:
  17. points = shape["points"]
  18. mask = shape_module.shape_to_mask(img.shape[:2], points)
  19. assert mask.shape == img.shape[:2]