toco랑은 또 다른건가..

보다 보니 tf.lite.Optimize.DEFAULT 라는 것도 새롭게 보이고

set_shape( ) 로 입력값이 변화하지 않도록 정해주는 것 같은데 무슨 차이인지 모르겠다 ㅠㅠ

 

!pip install tf-nightly
import tensorflow as tf

## TFLite Conversion
model = tf.saved_model.load("saved_model")
concrete_func = model.signatures[tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
concrete_func.inputs[0].set_shape([1, 300, 300, 3])
tf.saved_model.save(model, "saved_model_updated", signatures={"serving_default":concrete_func})
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir='saved_model_updated', signature_keys=['serving_default'])

converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model = converter.convert()

## TFLite Interpreter to check input shape
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test the model on random input data.
input_shape = input_details[0]['shape']
print(input_shape)

[링크 : https://stackoverflow.com/questions/63325216/]

    [링크 : https://github.com/tensorflow/tensorflow/issues/42114#issuecomment-671593386]

 

+

희망을 가졌던 tf.lite.Optimize.DEFAULT는 quantization 관련 옵션 ㅠㅠ

[링크 : https://www.tensorflow.org/lite/performance/post_training_quantization]

[링크 : https://www.tensorflow.org/lite/performance/model_optimization]

[링크 : https://www.tensorflow.org/lite/api_docs/python/tf/lite/Optimize]

Posted by 구차니