# LayoutLMv3 transformers.onnx

**URL:** <https://discuss.huggingface.co/t/layoutlmv3-transformers-onnx/23166>\
**Category:** 🤗Transformers\
**Created:** [September 15, 2022, 10:08am UTC](https://discuss.huggingface.co/t/layoutlmv3-transformers-onnx/23166 "2022-09-15T10:08:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexgg94](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@alexgg94](https://discuss.huggingface.co/u/alexgg94)\
**Post date:** [September 15, 2022, 10:08am UTC](https://discuss.huggingface.co/t/layoutlmv3-transformers-onnx/23166/1 "2022-09-15T10:08:35Z")

</div>

Hi, I’m trying to export a given LayoutLMv3 fine tuned model to onnx format following this [guide](https://huggingface.co/docs/transformers/serialization?highlight=onnx#converting-an-onnx-model-using-the-transformers-onnx-package).  
The actual model I’m trying to export is [this](https://huggingface.co/nielsr/layoutlmv3-finetuned-cord) one from @nielsr .

My current configuration is the following:

- `transformers` version: 4.21.3
- Platform: Windows-10-10.0.22000-SP0
- Python version: 3.10.4
- Huggingface\_hub version: 0.9.1
- PyTorch version (GPU?): 1.12.0+cpu (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: -

When I’m trying to run the command from the tutorial ( **python -m transformers.onnx --model=nielsr/layoutlmv3-finetuned-cord onnx/** ) I get this error:

Some weights of the model checkpoint at nielsr/layoutlmv3-finetuned-cord were not used when initializing LayoutLMv3Model: [‘classifier.out\_proj.bias’, ‘classifier.dense.bias’, ‘classifier.dense.weight’, ‘classifier.out\_proj.weight’]

- This IS expected if you are initializing LayoutLMv3Model from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing LayoutLMv3Model from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).  
Using framework PyTorch: 1.12.0+cpu  
Traceback (most recent call last):  
File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\runpy.py”, line 196, in \_run\_module\_as\_main  
return _run\_code(code, main\_globals, None,  
File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\runpy.py”, line 86, in run\_code  
exec(code, run\_globals)  
File "C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx\_main.py", line 107, in   
main()  
File "C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx\_main_.py", line 89, in main  
onnx\_inputs, onnx\_outputs = export(  
File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx\convert.py”, line 336, in export  
return export\_pytorch(preprocessor, model, config, opset, output, tokenizer=tokenizer, device=device)  
File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx\convert.py”, line 143, in export\_pytorch  
model\_inputs = config.generate\_dummy\_inputs(preprocessor, framework=TensorType.PYTORCH)  
File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\models\layoutlmv3\configuration\_layoutlmv3.py”, line 264, in generate\_dummy\_inputs  
setattr(processor.feature\_extractor, “apply\_ocr”, False)  
AttributeError: ‘RobertaTokenizerFast’ object has no attribute ‘feature\_extractor’

Am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [September 15, 2022, 12:11pm UTC](https://discuss.huggingface.co/t/layoutlmv3-transformers-onnx/23166/2 "2022-09-15T12:11:55Z")

</div>

Hi,

Thanks for your interest in that model 🙂 the reason was that the repo on the hub didn’t contain a `preprocessor_config.json` file. I’ve uploaded it to the repo.

Also note that, in order to convert the model that includes the token classification head, you need to provide` --feature token-classification` to the script. Without this, it would just convert the base LayoutLMv3Model, not LayoutLMv3ForTokenClassification:

```auto
!pip install -q transformers[onnx]
!python -m transformers.onnx --model=nielsr/layoutlmv3-finetuned-cord onnx/ --feature token-classification

```
