Models trained on 16-bit gray images do not detect anything
I made several tests. 16-bit images prepared in Gimp, by converting 8-bit regular images to 16-bit and gray scale, and saving them as png.
The first scenario:
- Create a project, import three 16-bit gray images. Annotate them.
- Train any model, D-FINE-M for instance.
- Observe mAP and run inference on one of the images from this dataset.
Then, repeat the same steps in another project for the original RGB images.
For 16-bit, mAP is 1%, the model does not detect anything. For 8-bit RGB, mAP is 97%, the model detects objects pretty nicely.
As this model was trained only on one image, I created 38 16-bit gray images, annotated all of them and followed the same scenario. The same result: mAP 1% and the model does not detect anything.
I shared the dataset with @kprokofi .
I did a basic test with some thermal images in 16 bit form for multiclass classification. In 8 bit greyscale they can reach a very high accuracy, though in 16 bit form it appears the accuracy is non-existent (same as randomly selecting class). The model training metrics look good and the test_metrics = engine.test() look good, however our inference code is not reflecting the accuracy. I am adjusting the mean and scale values based on the bit depth (255 vs 65535).
input_scale = 2**16 - 1 if (input_dtype.lower() == 'u16') else 2**8 - 1
...
mean_values = [v * input_scale for v in mean_values]
scale_values = [v * input_scale for v in scale_values]
...
ppp.input().preprocess().resize(ResizeAlgorithm.RESIZE_LINEAR)
ppp.input().preprocess().convert_layout(Layout(model_layout))
ppp.input().preprocess().convert_element_type(Type.f32)
ppp.input().preprocess().mean(mean_values).scale(scale_values)
Hi @j99ca , do you use ModelAPI for the inference? If so, ModelAPI should care about the input pre-processing and you don't need to change anything for inference. Just pass a raw 16bit image Also, do you see same behavior in annotations / inference page in application?
If metrics you see in application good, then it is a matter of the pre-processing for the inference
@kprokofi I believe you are correct! Looks like my code had ppp.input().tensor().set_element_type(Type.u8) then later after applying some preprocessing ops ppp.input().preprocess().convert_element_type(Type.f32). Changing this seems to have resolved the issue. Though looks like ppp.input().tensor().set_element_type(Type.u16) does not work so we'll go directly info f32 before applying some processing ops
When you export a model in Geti application, you can check demo.py file there in zip archive and see how we do a pre-processing, also In XML file of the model you can see the applied pre-processing in the ModelAPI:
If you don't want to use ModelAPI in your project, then pass an already scaled and fully pre-processed (as for training) image to the model. The model itself (raw openvino IR) expects fp32 image scaled to 0:1 range
Thanks for the info @kprokofi ! We already use the XML file for writing custom details in the model_info about the model for edge usage. Generally we are running the models in a C++ environment using OpenVINO directly with the preprocessor ops configured based on stuff we read from the model.xml. We have some Python code that uses the model API for sanity checking / smaller tasks, but we try to keep our Python code for our inference pipelines mirroring our C++ code
We'll likely end up reconfiguring our ML pipelines (both cloud and edge) with these latest updates now that 16 bit is supported. Currently we use a mix of custom OTX (soon to be Getitune) for training models from our platform, as well as Geti itself for models / tasks our platform doesn't directly support