Skip to content

Visualizer().render fails for 16-bit images #596

Description

@piotrgrubicki
  1. Train a model with 16-bit images using Geti.
  2. Export model
  3. Use the following piece of code to run inference using Model API
  4. The code throws an exception as shown below (ignore the line numbers).
    model = Model.create_model(str(MODEL_PATH))
    image_bgr = cv2.imread(str(IMAGE_PATH), cv2.IMREAD_UNCHANGED)
    if image_bgr is None:
        raise RuntimeError(f"Failed to decode image: {IMAGE_PATH}")
    result = model(image_bgr)
    output = Visualizer().render(image_bgr, result)
    cv2.imwrite(str(OUTPUT_PATH), output)
Traceback (most recent call last):
  File "/home/osboxes/deployment/16bit/demo.py", line 51, in <module>
    main()
    ~~~~^^
  File "/home/osboxes/deployment/16bit/demo.py", line 45, in main
    output = Visualizer().render(image_bgr, result)
  File "/home/osboxes/deployment/16bit/.venv/lib/python3.13/site-packages/model_api/visualizer/visualizer.py", line 85, in render
    image = Image.fromarray(image)
  File "/home/osboxes/deployment/16bit/.venv/lib/python3.13/site-packages/PIL/Image.py", line 3431, in fromarray
    raise TypeError(msg) from e
TypeError: Cannot handle this data type: (1, 1, 3), <u2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions