LayoutLMv3 transformers.onnx
Hi, I’m trying to export a given LayoutLMv3 fine tuned model to onnx format following thisguide.The actual model I’m trying to export isthisone from@nielsr.My current configuration is the following:transformersversion: 4.21.3Platform: Windows-10-10.0.22000-SP0Python version: 3.10.4Huggingface_hub version: 0.9.1PyTorch version (GPU?): 1.12.0+cpu (False)Tensorflow version (GPU?): not installed (NA)Flax version (CPU?/GPU?/TPU?): not installed (NA)Jax version: not installedJaxLib version: not installedUsing GPU in script?: NoUsing 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+cpuTraceback (most recent call last):File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\runpy.py”, line 196, in _run_module_as_mainreturnrun_code(code, main_globals, None,File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\runpy.py”, line 86, inrun_codeexec(code, run_globals)File "C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx_main.py", line 107, inmain()File "C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx_main.py", line 89, in mainonnx_inputs, onnx_outputs = export(File “C:\Users\nk-alex\miniconda3\envs\sparrow\lib\site-packages\transformers\onnx\convert.py”, line 336, in exportreturn 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_pytorchmodel_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_inputssetattr(processor.feature_extractor, “apply_ocr”, False)AttributeError: ‘RobertaTokenizerFast’ object has no attribute ‘feature_extractor’Am I doing something wrong?
2022-09-15T12:11:55Z
Hi,Thanks for your interest in that modelthe reason was that the repo on the hub didn’t contain apreprocessor_config.jsonfile. 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-classificationto the script. Without this, it would just convert the base LayoutLMv3Model, not LayoutLMv3ForTokenClassification:!pip install -q transformers[onnx]
!python -m transformers.onnx --model=nielsr/layoutlmv3-finetuned-cord onnx/ --feature token-classification