ITADN

Question: tflite support

#1035Openthepian 创建于 2026-05-10
T
thepiancommented
I'm trying to export a tflite model via ONNX based on version 1.6.5 I tried to do the same as what you have in 1.7 The TFLite conversion blows up though. I've tried to exclude segmentation thinking it might be the cause. Have you seen this? Do you know 1.7 to correctly export TFLite models? ``` PYTHONUNBUFFERED=1 uv run python objects/export_onnx.py --format tflite --no-seg Checkpoint: /Volumes/Datasets/.cache/evidentnet/models/seg-nano-stage2_full/checkpoint_best_ema.pth Classes (34): ['hand', 'person', 'receipt', 'document', 'warranty_card', 'price_tag', 'product_label', 'envelope']… Mode: detection only (seg head stripped) Exporting ONNX to /Volumes/Datasets/.cache/evidentnet/models/seg-nano-stage2_full/ (CPU, opset 17) ... [2026-05-10 20:01:00] [WARNING] rf-detr - Using a different number of positional encodings than DINOv2, which means we're not loading DINOv2 backbone weights. This is not a problem if finetuning a pretrained RF-DETR model. [2026-05-10 20:01:00] [WARNING] rf-detr - Using patch size 12 instead of 14, which means we're not loading DINOv2 backbone weights. This is not a problem if finetuning a pretrained RF-DETR model. /Volumes/Projects/Evidently/evidentnet/objects/export_onnx.py:200: DeprecationWarning: You are using the legacy TorchScript-based ONNX export. Starting in PyTorch 2.9, the new torch.export-based ONNX exporter has become the default. Learn more about the new export logic: https://docs.pytorch.org/docs/stable/onnx_export.html. For exporting control flow: https://pytorch.org/tutorials/beginner/onnx/export_control_flow_model_to_onnx_tutorial.html torch.onnx.export( /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/backbone/dinov2.py:212: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! assert x.shape[2] % block_size == 0 and x.shape[3] % block_size == 0, ( /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/backbone/dinov2_with_windowed_attn.py:313: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if num_channels != self.num_channels: /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/backbone/dinov2.py:201: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if num_patches == num_positions and height == width: /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/transformer.py:285: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! topk = min(self.num_queries, enc_outputs_class_unselected_gidx.shape[-2]) /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/transformer.py:57: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if pos_tensor.size(-1) == 2: /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/transformer.py:59: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! elif pos_tensor.size(-1) == 4: /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/torch/__init__.py:2253: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if not condition: /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/ops/modules/ms_deform_attn.py:149: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if reference_points.shape[-1] == 2: /Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/rfdetr/models/ops/modules/ms_deform_attn.py:155: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! elif reference_points.shape[-1] == 4: Detection-only ONNX: /Volumes/Datasets/.cache/evidentnet/models/seg-nano-stage2_full/inference_model_detect.onnx (119 MB) Converting ONNX → TFLite (quantization=None) ... Automatic generation of each OP name started ======================================== Automatic generation of each OP name complete! Model loaded ======================================================================== Model conversion started ============================================================ ERROR: The trace log is below. Traceback (most recent call last): File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/onnx2tf/utils/common_functions.py", line 314, in print_wrapper_func result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/onnx2tf/utils/common_functions.py", line 388, in inverted_operation_enable_disable_wrapper_func result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/onnx2tf/utils/common_functions.py", line 57, in get_replacement_parameter_wrapper_func func(*args, **kwargs) File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/onnx2tf/ops/Expand.py", line 151, in make_node val_model = tf_keras.Model( ^^^^^^^^^^^^^^^ File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/tensorflow/python/trackable/base.py", line 204, in _method_wrapper result = method(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/tf_keras/src/engine/functional.py", line 166, in __init__ self._init_graph_network(inputs, outputs) File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/tensorflow/python/trackable/base.py", line 204, in _method_wrapper result = method(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/tf_keras/src/engine/functional.py", line 207, in _init_graph_network self._validate_graph_inputs_and_outputs() File "/Volumes/Projects/Evidently/evidentnet/.venv/lib/python3.11/site-packages/tf_keras/src/engine/functional.py", line 874, in _validate_graph_inputs_and_outputs raise ValueError( ValueError: Output tensors of a Functional model must be the output of a TensorFlow `Layer` (thus holding past layer metadata). Found: [[ 0.] [ 1.] [ 2.] [ 3.] [ 4.] [ 5.] [ 6.] [ 7.] [ 8.] [ 9.] [10.] [11.] [12.] [13.] [14.] [15.] [16.] [17.] [18.] [19.] [20.] [21.] [22.] [23.] [24.] [25.]] ERROR: input_onnx_file_path: /Volumes/Datasets/.cache/evidentnet/models/seg-nano-stage2_full/inference_model_detect.onnx ERROR: onnx_op_name: wa/transformer/Expand_2 ERROR: Read this and deal with it. https://github.com/PINTO0309/onnx2tf#parameter-replacement ERROR: Alternatively, if the input OP has a dynamic dimension, use the -b or -ois option to rewrite it to a static shape and try again. ERROR: If the input OP of ONNX before conversion is NHWC or an irregular channel arrangement other than NCHW, use the -kt or -kat option. ERROR: Also, for models that include NonMaxSuppression in the post-processing, try the -onwdt option. Attempting automatic JSON generation due to conversion error ============================== Error occurred at ONNX operation: wa/transformer/Expand_2 JSON generation attempt 1/3 Starting automatic JSON generation... Error from ONNX operation: wa/transformer/Expand_2 Conversion error analysis: ValueError Problematic operations: ['wa/transformer/Expand_2'] Suggested operation types: [] Found specific node from error: wa/transformer/Expand_2 (type: Expand) Added fixes for all Expand operations due to error in wa/transformer/Expand_2 Generated 92 candidate fixes for conversion error ```
4 条评论