tensorflow / tflite-support

TFLite Support is a toolkit that helps users to develop ML and deploy TFLite models onto mobile / ioT devices.
Apache License 2.0
378 stars 128 forks source link

Possibility of channel-by-channel image normalization when adding metadata #968

Open doroshsmm opened 8 months ago

doroshsmm commented 8 months ago

My model is trained on a certain mean and std: mean = [151.2405, 119.5950, 107.8395] std = [63.0105, 56.4570, 55.0035] The problem is that the attempt to add these values to the metadata fails at the verification stage in mediapipe studio: "Error: UNIMPLEMENTED: Per-channel image normalization is not available.; Initialize was not ok; StartGraph failed." Did I understand correctly that there is no possibility of channel-by-channel normalization? Are there any plans to add it? Unfortunately, if I normalize all channels with one number, the quality of my model deteriorates significantly.

servercalap commented 2 months ago

I got the same error.

I get it when I try to inference in python code in mediapipe in the model I converted from pytorch.

I did the conversion with onnx2tf (pytorch model) and then I ran the following code to add metadata:

`from tflite_support.metadata_writers import image_classifier from tflite_support.metadata_writers import writer_utils

ImageClassifierWriter = image_classifier.MetadataWriter _MODEL_PATH = ‘modelc_float16.tflite’

_LABEL_FILE = ‘labels.txt’ _SAVE_TO_PATH = ‘modelc_float16_metadata.tflite’

_INPUT_NORM_MEAN = [0.4521, 0.4200, 0.4150] _INPUT_NORM_STD = [0.2821, 0.2562, 0.2538]

writer = ImageClassifierWriter.create_for_inference( writer_utils.load_file(_MODEL_PATH), [], [], [_LABEL_FILE])

print(writer.get_metadata_json())

writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)`