model_api
model_api copied to clipboard
Visualizer().render fails for 16-bit images
- Train a model with 16-bit images using Geti.
- Export model
- Use the following piece of code to run inference using Model API
- 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