(Please note this blog is written on 30 September, 2023. The situation may change in future.)
In the fast-paced realm of sports analytics, precise and robust video tracking solutions are more critical than ever. Especially in sports like football, where detailed player and ball tracking can unveil invaluable insights into team strategy and player prowess. But what do you do when the elite solutions, such as Metrica Sports, come with a hefty price tag, soaring over 1000 euros annually? For many, building an in-house solution becomes a tempting prospect. However, developing such a system is not always straightforward, especially when navigating the labyrinth of software dependencies. In this blog post, we delve deep into the challenges and offer solutions for setting up a Python environment primed for video tracking in football, leveraging powerhouse tools like PyTorch and mmcv on macOS.
The Brewing Challenge with Python
If you are a macOS user and rely on Homebrew (often abbreviated as brew), you might opt for a quick Python installation with brew install python3. However, this seemingly simple action can sometimes lead to a pesky error: [SSL: CERTIFICATE_VERIFY_FAILED]. This error indicates that Python isn't able to verify SSL certificates, which can hinder operations that rely on secure internet connections.
Solution: If you encounter this error, you're not alone. A comprehensive solution can be found on this StackOverflow thread.
PyTorch and mmcv: Version Dependencies
As of this writing (30 September 2023), if you're aiming to work with PyTorch, there's a catch: You'd need Python version = 3.10 to install PyTorch version 1.13.x. Why this specific version? As it turns out, mmcv (a foundational library for computer vision research) only supports this version of PyTorch at the moment.
To get the right versions installed on 3.10, use the following command:
install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 -c pytorch
Navigating the mmcv Challenge
Once you get past the Python and PyTorch installations, there's another hurdle: the dreaded No module named 'mmcv._ext' error.
Solution:
- First, uninstall the current mmcv version:
pip uninstall mmcv
- To install the right version, you don't have to guess. Instead, generate the appropriate install command by visiting the mmcv official documentation.
- This solution is credited to a useful source on GitHub, which discusses similar challenges faced by other developers.
## MBP M2's PyTorch Quirk
If you're wielding an MBP with an M2 chip, there's a crucial caveat to be aware of. Due to an existing issue where the operator aten::cumsum.out hasn't been implemented for PyTorch on the MPS device source, operations on the local MBP M2 can only be executed using the CPU. This means that while the M2 chip offers tantalizing processing prowess, when it comes to PyTorch, we're momentarily confined to CPU-bound computations.
The performance on CPU only is acceptable. It takes 5 minutes to render a 80 seconds tracking video. The final output looks not bad:

Conclusion
Setting up a video tracking solution, especially for small target tracking in football videos, is a nuanced task. There's a delicate balance of getting the right versions of Python, PyTorch, and mmcv to play nicely together. While the process might seem daunting initially, the community-driven solutions and documentation are there to guide you. However, it's worth noting that the current landscape is based on the state of these tools as of September 2023. As software ecosystems are ever-evolving, the situation might be different in the future. So always ensure you're referring to the most recent and relevant documentation.
Remember, the journey of building any robust system is filled with challenges. Embrace them, seek community support, and move forward with your pioneering video tracking solution!