tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.37k stars 1.92k forks source link

Enable metadata saving via TensorFlow.js frontend API #6414

Open jasonmayes opened 2 years ago

jasonmayes commented 2 years ago

Currently metadata is supported for conversion via the CLI converter on server side from models from Python however if you train a model in the browser there is no way to save custom key value pairs that you may need in future pre/post processing.

For example if you perform normalization on your training data you need to know the min/max values for a given attribute in order to normalize future data after the model is trained too at inference for any new prediction data that comes in.

Currently a user has to save this data in a different pipeline to the TensorFlow.js one which is inconvenient and does not make sense. It would be far more optimal to expose a simple interface to the end user to store their metadata as part of the model.json file and then able to read these values on model load such that they can be retrieved and used as needed for any custom pre/post processing when using the model.

All users training models in the browser either fully or via transfer learning could benefit from this feature.

halflings commented 2 years ago

For the specific use case of pre-processing, it would be great to have ops like the ones in tf transform: https://www.tensorflow.org/tfx/transform/get_started

Normalizing a feature would just require calling something like tft. scale_to_z_score(..) when building the model, and the rest is done more-or-less transparently (no need to manually serialize/deserialize metadata).

Here are some of the most common pre-processing steps I've used (either for MLConsole.com using custom JS code, or at work with TFX):

gaikwadrahul8 commented 1 year ago

Hi, @jasonmayes

Apologize for the delayed response and It seems like we have implemented this feature in Tensorflow.js If I'm not wrong so could you please close this issue if we have implemented this feature in Tensorflow.js?

If have I missed something here or we haven't implemented this feature in Tensorflow.js, Please let me know ? Thank you!

jasonmayes commented 1 year ago

It was? Can you point me to the docs or PR or such? I did not receive any update on this being implemented yet.

gaikwadrahul8 commented 1 year ago

Hi, @jasonmayes

I am truly sorry for my previous misunderstanding of this feature request. After further investigation, I believe that there is currently no Tensorflow.js frontend api to enable metadata saving. This would allow end users to store their metadata as part of themodel.json file and then read these values on model load. This would be useful for retrieving and using the metadata as needed for any custom pre- or post-processing steps when using the model. Thank you!

jasonmayes commented 1 year ago

@mattsoulanille Did you ever look into this by chance? I can not quite remember if we discussed this in one of our 1-1s a while back.

pyu10055 commented 10 months ago

metadata is supported with --metadata flag, https://github.com/tensorflow/tfjs/blob/master/tfjs-converter/README.md#conversion-flags