Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
doroshsmm opened this issue Mar 13, 2024 · 1 comment

Comments

@doroshsmm
Copy link

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
Copy link

servercalap commented Sep 26, 2024

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)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants