【发布时间】:2021-02-24 12:59:34
【问题描述】:
我微调了 SSD 模型以识别自定义对象。 我按照教程,运行了训练过程并导出了模型,我测试了它的推理,一切都很好。 所以,现在我有一个类似的结构:
exported models/
|
---- SSD_custom_model/
|
--------checkpoint/
--------saved_model/
--------pipeline.config
我认为这就是 TensorFlow 文档中所谓的“已保存模型”。 因此,我想将此模型转换为 TensorFlow Lite 以在 Android 设备上进行测试,我查看了教程并正在尝试:
import tensorflow as tf
saved_model_dir = 'exported-models/SSD_custom_model/'
# # Convert the model
## I tried either just
# converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
## or, with more options
converter = tf.lite.TFLiteConverter.from_saved_model(
saved_model_dir, signature_keys=['serving_default'])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model = converter.convert()
# Save the model.
with open('tflite/custom_model.tflite', 'wb') as f:
f.write(tflite_model)
我得到了错误
File "/home/lews/anaconda3/envs/tf/lib/python3.8/site-packages/tensorflow/lite/python/convert.py", line 216, in toco_convert_protos
raise ConverterError(str(e))
tensorflow.lite.python.convert.ConverterError: <unknown>:0: error: loc(callsite(callsite("map/TensorArrayV2_1@__inference_call_func_11694" at "StatefulPartitionedCall@__inference_signature_wrapper_14068") at "StatefulPartitionedCall")): requires element_shape to be 1D tensor during TF Lite transformation pass
<unknown>:0: note: loc("StatefulPartitionedCall"): called from
<unknown>:0: error: loc(callsite(callsite("map/TensorArrayV2_1@__inference_call_func_11694" at "StatefulPartitionedCall@__inference_signature_wrapper_14068") at "StatefulPartitionedCall")): failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal
<unknown>:0: note: loc("StatefulPartitionedCall"): called from
它似乎在抱怨输入形状('在 TF Lite 转换过程中要求 element_shape 是一维张量')。也许我应该在微调过程之前对模型进行一些修改?还是在那之后?
【问题讨论】:
标签: tensorflow tensorflow2.0 tensorflow-lite object-detection-api