Code Monkey home page Code Monkey logo

tracknetv3's Introduction

TrackNetV3

We present TrackNetV3, a model composed of two core modules: trajectory prediction and rectification. The trajectory prediction module leverages an estimated background as auxiliary data to locate the shuttlecock in spite of the fluctuating visual interferences. This module also incorporates mixup data augmentation to formulate complex scenarios to strengthen the network’s robustness. Given that a shuttlecock can occasionally be obstructed, we create repair masks by analyzing the predicted trajectory, subsequently rectifying the path via inpainting. [paper]

Performance

Model Accuracy Precision Recall F1 FPS
YOLOv7 57.82% 78.53% 59.96% 68.00% 34.77
TrackNetV2 94.98% 99.64% 94.56% 97.03% 27.70
TrackNetV3 97.51% 97.79% 99.33% 98.56% 25.11

Installation

  • Develop Environment

    Ubuntu 16.04.7 LTS
    Python 3.8.7
    torch 1.10.0
    
  • Clone this reposity.

    git clone https://github.com/qaz812345/TrackNetV3.git
    
  • Install the requirements.

    pip install -r requirements.txt
    

Inference

  • Download the checkpoints

  • Unzip the file and place the parameter files to ckpts

    unzip TrackNetV3_ckpts.zip
    
  • Predict the label csv from the video

    python predict.py --video_file test.mp4 --tracknet_file ckpts/TrackNet_best.pt --inpaintnet_file ckpts/InpaintNet_best.pt --save_dir prediction
    
  • Predict the label csv from the video, and output a video with predicted trajectory

    python predict.py --video_file test.mp4 --tracknet_file ckpts/TrackNet_best.pt --inpaintnet_file ckpts/InpaintNet_best.pt --save_dir prediction --output_video
    

Training

1. Prepare Dataset

  • Download Shuttlecock Trajectory Dataset
  • Set the data root directory to data_dir in dataset.py.
  • Data Preprocessing
    python preprocess.py
    
  • The frame directories and the val directory will be generated after preprocessing.
  • Check the estimated background images in <data_dir>/median
    • If available, the dataset will use the median image of the match; otherwise, it will use the median image of the rally.
    • For example, you can exclude train/match16/median.npz due to camera angle discrepancies; therefore, the dataset will resort to the median image of the rally within match 16.
  • The preprocessed dataset will be cached using npy files, so please ensure that you delete these files if you make any modifications to the dataset.
  • Dataset File Structure:
  data
    ├─ train
    |   ├── match1/
    |   │   ├── csv/
    |   │   │   ├── 1_01_00_ball.csv
    |   │   │   ├── 1_02_00_ball.csv
    |   │   │   ├── …
    |   │   │   └── *_**_**_ball.csv
    |   │   ├── frame/
    |   │   │   ├── 1_01_00/
    |   │   │   │   ├── 0.png
    |   │   │   │   ├── 1.png
    |   │   │   │   ├── …
    |   │   │   │   └── *.png
    |   │   │   ├── 1_02_00/
    |   │   │   │   ├── 0.png
    |   │   │   │   ├── 1.png
    |   │   │   │   ├── …
    |   │   │   │   └── *.png
    |   │   │   ├── …
    |   │   │   └── *_**_**/
    |   │   │
    |   │   └── video/
    |   │       ├── 1_01_00.mp4
    |   │       ├── 1_02_00.mp4
    |   │       ├── …
    |   │       └── *_**_**.mp4
    |   ├── match2/
    |   │ ⋮
    |   └── match26/
    ├─ val
    |   ├── match1/
    |   ├── match2/
    |   │ ⋮
    |   └── match26/
    └─ test
        ├── match1/
        ├── match2/
        └── match3/
  • Attributes in each csv files: Frame, Visibility, X, Y

2. Train Tracking Module

  • Train the tracking module from scratch

    python train.py --model_name TrackNet --seq_len 8 --epochs 30 --batch_size 10 --bg_mode concat --alpha 0.5 --save_dir exp --verbose
    
  • Resume training (start from the last epoch to the specified epoch)

    python train.py --model_name TrackNet --epochs 30 --save_dir exp --resume_training --verbose
    

3. Generate Predited Trajectories and Inpainting Masks

  • Generate predicted trajectories and inpainting masks for training rectification module
    • Noted that the coordinate range corresponds to the input spatial dimensions, not the size of the original image.
    python generate_mask_data.py --tracknet_file ckpts/TrackNet_best.pt --batch_size 16
    

4. Train Rectification Module

  • Train the rectification module from scratch.

    python train.py --model_name InpaintNet --seq_len 16 --epoch 300 --batch_size 32 --lr_scheduler StepLR --mask_ratio 0.3 --save_dir exp --verbose
    
  • Resume training (start from the last epoch to the specified epoch)

    python train.py --model_name InpaintNet --epochs 30 --save_dir exp --resume_training
    

Evaluation

  • Evaluate TrackNetV3 on test set

    python generate_mask_data.py --tracknet_file ckpts/TrackNet_best.pt --split_list test
    python test.py --inpaintnet_file ckpts/InpaintNet_best.pt --save_dir eval
    
  • Evaluate the tracking module on test set

    python test.py --tracknet_file ckpts/TrackNet_best.pt --save_dir eval
    
  • Generate video with ground truth label and predicted result

    python test.py --tracknet_file ckpts/TrackNet_best.pt --video_file data/test/match1/video/1_05_02.mp4 
    

Error Analysis Interface

  • Evaluate TrackNetV3 on test set and save the detail results for error analysis

    python test.py --tracknet_file ckpts/TrackNet_best.pt --inpaintnet_file ckpts/InpaintNet_best.pt --save_dir eval --output_pred
    
  • Add json path of evaluation results to the file list in error_analysis.py

    30  # Evaluation result file list
    31  if split == 'train':
    32      eval_file_list = [
    33          {'label': label_name, 'value': json_path},
     ⋮                              ⋮
            ]
        elif split == 'val':
            eval_file_list = [
                {'label': label_name, 'value': json_path},
                                    ⋮
            ]
        elif split == 'test':
            eval_file_list = [
                {'label': label_name, 'value': json_path},
                                    ⋮
            ]
        else:
            raise ValueError(f'Invalid split: {split}')                                  
    
  • Run Dash application

    python error_analysis.py --split test --host 127.0.0.1
    

tracknetv3's People

Contributors

qaz812345 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

Watchers

 avatar  avatar

tracknetv3's Issues

evaluation command execution error:can't find drop_frame.json

hi, thank you for your great work.

when i want to evaluate tracknet, i found that evaluation command "python test.py --tracknet_file ckpts/TrackNet_best.pt --save_dir eval" execution error:can't find drop_frame.json. I can't find this json file but test.py loads this file:"drop_frame_dict = json.load(open(os.path.join(data_dir, 'drop_frame.json')))"

How can I solve this problem?
image

the operate system say don't find the "data/train"

dear author,
my os is win11, The fellow is my mistake information. do you know how to solve it?
FileNotFoundError: [WinError 3] 系统找不到指定的路径。: 'data\train'
when i create the "data/train", there is another probelm.
self = reduction.pickle.load(from_parent)
_pickle.UnpicklingError: pickle data was truncated

How to process large videos?

As far as I can see you're storing the input video as an list of frames and then you're processing them. But if the video is long enough my PC is just running out of memory when storing all the frames in a list obviously. How can I process long videos then? Should i divide them in smaller ones first or it's possible to process the video frame by frame using video.read()?

About how to label my own datasets

I want to train my own golf tracking dataset, could you please tell me how to label the data, because the label tool at TrackNetV2 is not accessible.

OSError: [Errno 22] Invalid argument

Hello!

I've trained Tracking Module and Rectification Module. But when I execute predict.py script on my video I'm getting an error.
How can I fix it and what is this error? I've tried to google but it says that I might be running out of RAM. But I got 16GB of it.

image

Can I read your paper ?

Hi,

Thanks for making this repository public. I am more interested to learn about your approach and want to read the paper. Unfortunately I cannot access the paper because I am not from academic background. Do you mind to send me the paper in my email id: [email protected] ?

Tennis dataset for V3

I remember in the initial research there was a tennis dataset and it was also trained. How can I train this V3 model for tennis and not for shuttlecock? Will it different in any way?

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.