Lin1007 commited on
Commit
9d05b02
1 Parent(s): 3627736

add scripts for conversion

Browse files
Files changed (1) hide show
  1. scripts/tflite_convert.py +15 -0
scripts/tflite_convert.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TFMobileViTForSemanticSegmentation
2
+ import tensorflow as tf
3
+
4
+ if __name__ == '__main__':
5
+ model = TFMobileViTForSemanticSegmentation.from_pretrained(".")
6
+ converter = tf.lite.TFLiteConverter.from_keras_model(model)
7
+ converter.optimizations = [tf.lite.Optimize.DEFAULT]
8
+ converter.target_spec.supported_ops = [
9
+ tf.lite.OpsSet.TFLITE_BUILTINS,
10
+ tf.lite.OpsSet.SELECT_TF_OPS,
11
+ ]
12
+ tflite_model = converter.convert()
13
+ tflite_filename = "tflite_model.tflite"
14
+ with open(tflite_filename, "wb") as f:
15
+ f.write(tflite_model)