def test_image_feature_encode_example(shared_datadir, build_example): import PIL.Image image_path = str(shared_datadir / "test_image_rgb.jpg") image = Image() encoded_example = image.encode_example(build_example(image_path)) assert isinstance(encoded_example, dict) assert encoded_example.keys() == {"bytes", "path"} assert encoded_example["bytes"] is not None or encoded_example["path"] is not None decoded_example = image.decode_example(encoded_example) assert isinstance(decoded_example, PIL.Image.Image)
def test_image_decode_example(shared_datadir): import PIL.Image image_path = str(shared_datadir / "test_image_rgb.jpg") image = Image() decoded_example = image.decode_example(image_path) assert isinstance(decoded_example, PIL.Image.Image) assert os.path.samefile(decoded_example.filename, image_path) assert decoded_example.size == (640, 480) assert decoded_example.mode == "RGB"
def test_image_decode_example(shared_datadir): import PIL.Image image_path = str(shared_datadir / "test_image_rgb.jpg") image = Image() decoded_example = image.decode_example({"path": image_path, "bytes": None}) assert isinstance(decoded_example, PIL.Image.Image) assert os.path.samefile(decoded_example.filename, image_path) assert decoded_example.size == (640, 480) assert decoded_example.mode == "RGB" with pytest.raises(RuntimeError): Image(decode=False).decode_example(image_path)