'2021/02/01'에 해당되는 글 2건

  1. 2021.02.01 tensorflow bazel build
  2. 2021.02.01 convert from tensorflow to tensorflow lite

bazel로 빌드시에 어떤 옵션이 가능한지 보는 법 없나...

현재 발견(?) 한건

 

--config=monolithic

[링크 : https://www.tensorflow.org/lite/guide/ops_select]

 

c와 c++용 라이브러리 생성

bazel build --config=elinux_aarch64 -c opt //tensorflow/lite/c:libtensorflowlite_c.so
bazel build --config=elinux_aarch64 -c opt //tensorflow/lite:libtensorflowlite.so

[링크 : https://www.tensorflow.org/lite/guide/build_arm64?hl=ko]

 

$ bazel build tensorflow/examples/label_image

[링크 : https://chromium.googlesource.com/external/github.com/tensorflow/tensorflow/+/refs/heads/master/tensorflow/examples/label_image/]

 

[ github.com/tensorflow/tensorflow/issues/38077]

[ github.com/tensorflow/tensorflow/issues/35590]

Posted by 구차니

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 구차니