Open emigomez opened 2 years ago
Hi,
Please use the official "microsoft/table-transformer-detection" checkpoint instead of the legacy "nielsr/detr-table-detection".
The command to run to export DETR to ONNX is very easy now thanks to 🤗 Optimum, see this guide: https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model.
Hi,
Please use the official "microsoft/table-transformer-detection" checkpoint instead of the legacy "nielsr/detr-table-detection".
The command to run to export DETR to ONNX is very easy now thanks to hugs Optimum, see this guide: https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model.
Hi
I follow the guide page you mentioned. But optimum returns me an error like
KeyError: "table-transformer is not supported yet. Only {'mbart', 'marian', 'groupvit', 'xlm', 'unispeech-sat', 'electra', 't5', 'resnet', 'nystromformer', 'donut-swin', 'segformer', 'gpt-neox', 'mt5', 'deberta-v2', 'hubert', 'splinter', 'layoutlm', 'wav2vec2', 'data2vec-audio', 'bart', 'sew-d', 'mpnet', 'perceiver', 'flaubert', 'bert', 'gptj', 'roberta', 'clip', 'levit', 'sew', 'bloom', 'squeezebert', 'gpt2', 'mobilevit', 'albert', 'mobilebert', 'convnext', 'poolformer', 'detr', 'distilbert', 'camembert', 'codegen', 'deberta', 'convbert', 'mobilenet-v2', 'opt', 'data2vec-text', 'roformer', 'whisper', 'beit', 'xlm-roberta', 'blenderbot-small', 'blenderbot', 'swin', 'regnet', 'yolos', 'llama', 'vit', 'data2vec-vision', 'audio-spectrogram-transformer', 'm2m-100', 'wav2vec2-conformer', 'deit', 'imagegpt', 'speech-to-text', 'longt5', 'mobilenet-v1', 'gpt-neo', 'layoutlmv3', 'unispeech', 'ibert', 'pegasus', 'wavlm', 'vision-encoder-decoder'} are supported. If you want to support table-transformer please propose a PR or open up an issue."
version info
optimum
version: 1.8.8transformers
version: 4.30.2How can I deal with it? Thanks
ok
I've solved it by editing the config.json
file.
Setting model_type from "table-transformer" to "detr" makes Optimum works well for me.
Can you help provide the exported model for table detect and structure recognition? How to use above onnx models?
nielsr/detr-table-detection
Cannot run optimum in win10 command line? Any converted onnx models for tale detection and recognition for download? How to use these onnx models?
Finally, In my application, I use OpenCV to extract table grids. another candidate I considered is Paddleocr. Paddle2ONNX can easily translate the models to onnx models.
I am sorry that I developed my applications on Ubuntu, So I have no idea about models working on win10 now.
Thank you. I find paddleocr result is hard to train. It even fails for very clear tables.
Hi,
It seems that DETR is already supported by Optimum, but Table Transformer isn't yet. So one would need to open an issue on the Optimum repo for that.
I don't know how to convert to onnx, cli is invalid after pip install Optimum. Can you help provide an onnx model and a sample code for detection and recogniztion with onnx models?
Using the optimum cli optimum-cli export onnx --model microsoft/table-transformer-detection onnx_model
the warnings described by @emigomez are present still
//___/.venv/lib/python3.11/site-packages/transformers/models/table_transformer/modeling_table_transformer.py:558: 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 attn_weights.size() != (batch_size * self.num_heads, target_len, source_len): //___/.venv/lib/python3.11/site-packages/transformers/models/table_transformer/modeling_table_transformer.py:565: 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 attention_mask.size() != (batch_size, 1, target_len, source_len): /___/lib/python3.11/site-packages/transformers/models/table_transformer/modeling_table_transformer.py:589: 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!
Is this the expected behaviour? @NielsRogge
Also, when running the generated model the following error is thrown:
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Invalid input name: pixel_mask
The pixel_mask
is an optional argument for the table-transformer
, but It should be accepted by the onnx model.
I want to transform the table detection model from detr to onnx. Some models available in HF are either "nielsr/detr-table-detection" or "microsoft/table-transformer-detection".
I try both and with the first one is with the one I'm more close to obtaining the final result so... First, I was able to obtain an ONXX model doing:
!python -m transformers.onnx --model=nielsr/detr-table-detection onnx/
After that, I'm trying to do the inference with that ONNX model, and I manage to do it but i don't know how to understand the result:
These are some logs regarding the result obtained:
Does any know how to manage this result? it should be a bounding box of the table detected if there are.
Thanks in advance!