Giter VIP home page Giter VIP logo

soccer-video-analytics's Introduction

Soccer Video Analytics

This repository contains the companion code of the blog post Automatically measuring soccer ball possession with AI and video analytics by Tryolabs.

For further information on the implementation, please check out the post.

How to install

To install the necessary dependencies we use Poetry. After you have it installed, follow these instructions:

  1. Clone this repository:

    git clone [email protected]:tryolabs/soccer-video-analytics.git
  2. Install the dependencies:

    poetry install
  3. Optionally, download the ball.pt file from the GitHub release. Please note that this is just a toy model that overfits to a few videos, not a robust ball detection model.

How to run

First, make sure to initialize your environment using poetry shell.

To run one of the applications (possession computation and passes counter) you need to use flags in the console.

These flags are defined in the following table:

Argument Description Default value
application Set it to possession to run the possession counter or passes if you like to run the passes counter None, but mandatory
path-to-the-model Path to the soccer ball model weights (pt format) /models/ball.pt
path-to-the-video Path to the input video /videos/soccer_possession.mp4

The following command shows you how to run this project.

python run.py --<application> --model <path-to-the-model> --video <path-to-the-video>

Warning: You have to run this command on the root of the project folder.

Here is an example on how to run the command:

python run.py --possession --model models/ball.pt --video videos/soccer_possession.mp4

An mp4 video will be generated after the execution. The name is the same as the input video with the suffix _out added.

soccer-video-analytics's People

Contributors

dekked avatar diegofernandezc avatar diegomarvid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

soccer-video-analytics's Issues

Installing torch (1.12.1): Failed

When I start running "poetry install" command, I get this error message.

Installing torch (1.12.1): Failed

RuntimeError

Unable to find installation candidates for torch (1.12.1)

at ~/.local/pipx/venvs/poetry/lib/python3.11/site-packages/poetry/installation/chooser.py:109 in choose_for
105│
106│ links.append(link)
107│
108│ if not links:
→ 109│ raise RuntimeError(f"Unable to find installation candidates for {package}")
110│
111│ # Get the best link
112│ chosen = max(links, key=lambda link: self._sort_key(package, link))
113│

model.pt file

Hi. Than you for your work!
Can you please add ball.pt file for running this code?
I can't run this without the ML model

Referee track

Hi,

Congratulations for the excellent work! An information, could you give me some indications on how to track the movements of the referee by drawing lines on the field that show how he moved throughout the game?

Thank you

Sergio

Ball Dataset

Hey fam. Can you please provide the ball dataset? I would like to train on YOLOv8 model. Thanks.

Missing file

Without the ball.pt file, we can not know the weights and architecture of the pre-trained model. And without those information it's pretty hard to run correctly the projet. I guess it would be possible to train the model again with norfair, but that will be perfect if you could just add the ball.pt file on the project !

models/ball.pt is missing

Running the run.py on another machine I was able to get the script better working after installing
opencv-python-headless, but the script still fails with missing models/ball.pt

└─> python run.py --video ./REC_0014.MP4
cpu
Using cache found in /home/waboring/.cache/torch/hub/ultralytics_yolov5_master
YOLOv5 🚀 2023-8-7 Python-3.10.11 torch-1.12.1+cu102 CPU

Fusing layers...
YOLOv5x summary: 444 layers, 86705005 parameters, 0 gradients
Adding AutoShape...
cpu
Using cache found in /home/waboring/.cache/torch/hub/ultralytics_yolov5_master
YOLOv5 🚀 2023-8-7 Python-3.10.11 torch-1.12.1+cu102 CPU

Traceback (most recent call last):
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 49, in _create
    model = DetectMultiBackend(path, device=device, fuse=autoshape)  # detection model
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 344, in __init__
    model = attempt_load(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse)
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/models/experimental.py", line 79, in attempt_load
    ckpt = torch.load(attempt_download(w), map_location='cpu')  # load
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/serialization.py", line 699, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'models/ball.pt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 60, in _create
    model = attempt_load(path, device=device, fuse=False)  # arbitrary model
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/models/experimental.py", line 79, in attempt_load
    ckpt = torch.load(attempt_download(w), map_location='cpu')  # load
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/serialization.py", line 699, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'models/ball.pt'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/waboring/test/soccer-video-analytics/run.py", line 49, in <module>
    ball_detector = YoloV5(model_path=args.model)
  File "/home/waboring/test/soccer-video-analytics/inference/yolov5.py", line 27, in __init__
    self.model = torch.hub.load("ultralytics/yolov5", "custom", path=model_path)
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/hub.py", line 540, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/home/waboring/test/.venv/lib/python3.10/site-packages/torch/hub.py", line 569, in _load_local
    model = entry(*args, **kwargs)
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 83, in custom
    return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
  File "/home/waboring/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 78, in _create
    raise Exception(s) from e
Exception: [Errno 2] No such file or directory: 'models/ball.pt'. Cache may be out of date, try `force_reload=True` or see https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help.

run.py fails to start

Installed via poetry install which was successfull. But run.py fails.

╭─soccer-video-analytics on  main is 📦 v0.1.0 via 🐍 v3.10.9 took 19s ❯
└─> poetry install
Installing dependencies from lock file

Package operations: 41 installs, 5 updates, 0 removals

  • Installing pyparsing (3.0.9)
  • Installing numpy (1.23.4)
  • Updating packaging (23.1 -> 21.3)
  • Installing setuptools (65.4.1)
  • Installing typing-extensions (4.4.0)
  • Installing contourpy (1.0.5)
  • Installing cycler (0.11.0)
  • Installing fonttools (4.37.4)
  • Installing kiwisolver (1.4.4)
  • Installing pillow (9.2.0)
  • Installing python-dateutil (2.8.2)
  • Installing setuptools-scm (7.0.5)
  • Installing asttokens (2.0.8)
  • Updating certifi (2023.7.22 -> 2022.9.24)
  • Updating charset-normalizer (3.2.0 -> 2.1.1)
  • Installing commonmark (0.9.1)
  • Installing executing (1.1.1)
  • Installing matplotlib (3.6.1)
  • Installing parso (0.8.3)
  • Installing pure-eval (0.2.2)
  • Installing pygments (2.13.0)
  • Installing pytz (2022.4)
  • Installing scipy (1.9.2)
  • Installing traitlets (5.4.0)
  • Updating urllib3 (1.26.16 -> 1.26.12)
  • Installing wcwidth (0.2.5)
  • Installing appnope (0.1.3)
  • Installing backcall (0.2.0)
  • Installing decorator (5.1.1)
  • Installing filterpy (1.4.5)
  • Installing jedi (0.18.1)
  • Installing matplotlib-inline (0.1.6)
  • Installing pandas (1.5.0)
  • Installing pickleshare (0.7.5)
  • Installing prompt-toolkit (3.0.31)
  • Updating requests (2.31.0 -> 2.28.1)
  • Installing rich (12.6.0)
  • Installing stack-data (0.5.1)
  • Installing torch (1.12.1)
  • Installing ipython (8.5.0)
  • Installing norfair (2.0.0 1e42a8f)
  • Installing opencv-python (4.6.0.66)
  • Installing pyyaml (6.0)
  • Installing seaborn (0.12.0)
  • Installing torchvision (0.13.1)
  • Installing tqdm (4.64.1)
Traceback (most recent call last):
  File "/Users/i530566/mount/soccer-video-analytics/run.py", line 3, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'

training

Hello, I'm interested in this project. Does it include a training section?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.