Download convert_dynamic.py from kanha1111/sentiment_analysis: direct link, hf CLI and curl.
- Browser
- Download file 690 Bytes
-
https://huggingface.co/kanha1111/sentiment_analysis/resolve/main/convert_dynamic.py
- Command line
-
hf download hf://kanha1111/sentiment_analysis/convert_dynamic.py
-
curl -L -o convert_dynamic.py https://huggingface.co/kanha1111/sentiment_analysis/resolve/main/convert_dynamic.py
690 Bytes
| import tensorflow as tf | |
| import os | |
| print("Loading model...") | |
| model = tf.keras.models.load_model("sentiment_model.h5") | |
| # Convert with dynamic batch size (None instead of 256) | |
| def predict(x): | |
| return model(x) | |
| converter = tf.lite.TFLiteConverter.from_concrete_functions( | |
| [predict.get_concrete_function()] | |
| ) | |
| converter.optimizations = [tf.lite.Optimize.DEFAULT] | |
| tflite_model = converter.convert() | |
| with open("sentiment_model.tflite", "wb") as f: | |
| f.write(tflite_model) | |
| print(f"Size: {os.path.getsize('sentiment_model.tflite') / 1024 / 1024:.1f} MB") | |
| print("Done! Dynamic batch size model created.") | |