Hello everybody, wanted to know if ulltralytics team would finally build a package of their tool using opencv-python-headless and not opencv-python ? With the regular opencv version, libGL is required (openGL support), which is not really necessary in some project when doing inference only (no need for visuals created with opencv highgui lib). There are tricks to avoid that issue (like removing regular opencv and reinstalling the headless version) but it’s not so clean.
Thanks!
There have been a few Pull Requests opened for this exact request
- Build with `opencv-python` in headless version by Pandede · Pull Request #7068 · ultralytics/ultralytics · GitHub
- refactor: split out base dependencies to reduce docker image size by antoniomdk · Pull Request #17527 · ultralytics/ultralytics · GitHub
and a recent issue (with several others):
From what I’m aware of, there are complications in using the headless
install of OpenCV for Python WRT existing code and user workflows. It’s always a difficult to decide which features to integrate vs leave out, especially when they’re requested frequently. It’s entirely plausible that it could be added, but there would need to be a bit of effort put in to ensure that the default install would work as expected, and that a headless
option would be secondary.
I think for anyone building a Docker image for running a container, your suggestion about removing regular OpenCV and installing the headless version instead, might be a valid step, but libGL
would probably get installed/updated anyhow to get the base install working. I suspect that for many in this situation, cloning the repo, modifying the pyproject.toml
, updating the Dockerfile, and then building the Docker image would be the quickest way to create a headless
version.
If not using Docker, then modifying the pyproject.toml
in a local clone of Ultralytics and building the project should provide an installable of a headless
version. The effort for either is relatively low, and if it breaks existing workflows for training or validation, it might not matter for the individual where it would impact many more users if integrated directly into Ultralytics.
Many thanks for your answer! We appreciate your reactivity! I understand your point of view. For information, libGL is not necessary if opencv-python-headless is used. And that was what i wanted: don’t install libGL on my linux image. Another way is to infer with another lib that ultralytics: thanks to your export functions, it is possible to work with openvino or onnx. And with that way i can work without libGL installed. Now i’ve got another question related to that: i wanted to use pure pytorch tools for inference but when loading my model (.pt file) there are always artifacts from ultralytics remaining in the serialized file. Isn’t it possible to make an export structure which is 100% pytorch compatible ?
There isn’t such a thing as pure PyTorch. All custom modules have definition. And loading .pt
file requires those definition to be present. This is true for any model, not just the ones in Ultralytics and it is simply how .pt
(or pickle to be precise) files work. You can’t decouple them from the module definitions. Best you can do is use a format like TorchScript.
I suspect the easiest and quickest way to get a build without libGL
would be to clone the repo, modify the pyproject.toml
dependencies to use opencv-python-headless
, update the Dockerfile to avoid the libGL
install, and then build the container.