I’m trying to convert a DETR hugging face model to a Tensorflow Lite model using Optimum for an android app. I installed the requirements:
!pip install optimum
!pip install optimum[exporters-tf]
then I tried an example converting a pretrained model and it works, but on my model:
!optimum-cli export tflite --model /content/drive/MyDrive/Modele/model-litter --sequence_length 128 --task object-detection Model_Litter/
an error occurs about Transformer module about not having an attribute named TFAutoModelForObjectDetection
2024-05-01 11:53:55.895865: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
2024-05-01 11:54:01.347392: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.10/dist-packages/optimum/exporters/tflite/__main__.py", line 148, in <module>
main()
File "/usr/local/lib/python3.10/dist-packages/optimum/exporters/tflite/__main__.py", line 61, in main
model = TasksManager.get_model_from_task(
File "/usr/local/lib/python3.10/dist-packages/optimum/exporters/tasks.py", line 1905, in get_model_from_task
model_class = TasksManager.get_model_class_for_task(
File "/usr/local/lib/python3.10/dist-packages/optimum/exporters/tasks.py", line 1375, in get_model_class_for_task
return getattr(loaded_library, model_class_name)
File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1503, in __getattr__
raise AttributeError(f"module {self.__name__} has no attribute {name}")
AttributeError: module transformers has no attribute TFAutoModelForObjectDetection
Traceback (most recent call last):
File "/usr/local/bin/optimum-cli", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/optimum/commands/optimum_cli.py", line 163, in main
service.run()
File "/usr/local/lib/python3.10/dist-packages/optimum/commands/export/tflite.py", line 243, in run
subprocess.run(full_command, shell=True, check=True)
File "/usr/lib/python3.10/subprocess.py", line 526, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'python3 -m optimum.exporters.tflite --model /content/drive/MyDrive/Modele/model-litter --sequence_length 128 --task object-detection Model_Litter/' returned non-zero exit status 1
I saw on some forums the error might happen because I haven’t updated the Transformer module, but even after I updated the module the error still occurs.