Moment-DETR

repository·main·Indexed 43 days ago

https://github.com/jayleicn/moment_detr

A model designed to predict moment coordinates and saliency scores in videos based on natural language queries. It supports end-to-end training, weakly supervised pretraining with ASR captions, and inference on custom video data using SlowFast and Open AI CLIP features.

Tokens
2.3K
Snippets
8
Records
13
Agent score
56%

What's inside Moment-DETR

  1. Use the CLIP-only feature extraction checkpoint

    main

    This directory provides a simplified model checkpoint, model_best.ckpt, designed to streamline the feature extraction pipeline.

    Key Characteristics:

    • Inputs: Uses only CLIP image and text features.
    • Training: Trained from scratch without ASR (Automatic Speech Recognition) pre-training.
    • Performance Note: Because it lacks ASR pre-training, performance may be lower than the results reported in the original paper.

    Included Files:

    • model_best.ckpt: The model checkpoint.
    • Training/evaluation log files.
    • Training configurations.
    • Prediction files for the QVHighlights validation split.
  2. Use subtitle files for weakly supervised ASR pre-training

    main
    The project provides subs_train.jsonl for weakly supervised ASR pre-training. This file follows the same JSON Line format as the main annotation files but does not include the saliency_scores field. This file is optional and only required if you intend to perform pre-training using subtitles.
  3. Install Moment-DETR and set up the environment

    main

    To use Moment-DETR, you need to clone the repository, prepare the feature files, and set up a Conda environment with specific dependencies.

    1. Clone the repository:
    git clone https://github.com/jayleicn/moment_detr.git
    cd moment_detr
    1. Prepare feature files: Download moment_detr_features.tar.gz (8GB) and extract it into the project root directory:
    tar -xf path/to/moment_detr_features.tar.gz
    1. Create Conda environment and install dependencies: This project requires Python 3.7 and PyTorch (tested with version 1.9.0).
    # create conda env
    conda create --name moment_detr python=3.7
    # activate env
    conda activate moment_detr
    # install pytorch with CUDA 11.0
    conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
    # install other python packages
    pip install tqdm ipython easydict tensorboard tabulate scikit-learn pandas
    git clone https://github.com/jayleicn/moment_detr.git
    cd moment_detr
    
    tar -xf path/to/moment_detr_features.tar.gz
    
    conda create --name moment_detr python=3.7
    conda activate moment_detr
    conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
    pip install tqdm ipython easydict tensorboard tabulate scikit-learn pandas
  4. Run inference with a trained model

    main

    To run inference using a saved checkpoint, use the inference.sh script. You must provide the path to the checkpoint and the name of the split you are evaluating (e.g., val or test).

    bash moment_detr/scripts/inference.sh CHECKPOINT_PATH SPLIT_NAME
  5. Pretrain and Finetune Moment-DETR

    main

    Moment-DETR supports weakly supervised pretraining using ASR captions and subsequent finetuning.

    1. Pretraining: Run the pretraining script to train for 100 epochs on ASR captions. Checkpoints are saved in results.
    bash moment_detr/scripts/pretrain.sh
    1. Finetuning: To finetune, use the standard training script but pass the path to your pretrained checkpoint using the --resume flag.
    bash moment_detr/scripts/train.sh --resume ${PRETRAIN_CHECKPOINT_PATH}
    # Pretraining
    bash moment_detr/scripts/pretrain.sh
    
    # Finetuning
    bash moment_detr/scripts/train.sh --resume ${PRETRAIN_CHECKPOINT_PATH}
  6. Prepare Codalab submission package

    main

    To submit to the Codalab evaluation server (if available), you must create a single .zip file.

    Important: The .zip file must not contain an enclosing folder; the files must be at the root of the archive.

    The archive must contain exactly two files:

    1. hl_val_submission.jsonl
    2. hl_test_submission.jsonl

    Both files must follow the JSONL format specified in the prediction format documentation.

  7. Train Moment-DETR

    main

    You can train Moment-DETR on the QVHighlights train split using the provided training script. By default, it trains for 200 epochs using SlowFast and Open AI CLIP features. Results and checkpoints are saved in the results directory.

    To train without the saliency loss, you can set the --lw_saliency flag to 0.

    # Standard training
    bash moment_detr/scripts/train.sh 
    
    # Training without saliency loss
    bash moment_detr/scripts/train.sh --lw_saliency 0
  8. Run predictions on custom videos and queries

    main

    To run predictions on your own raw videos and text queries, follow these steps:

    1. Install additional dependencies:
    pip install ffmpeg-python ftfy regex
    1. Execute the prediction script: Set the PYTHONPATH to the current directory and run run_on_video/run.py. This script loads a default checkpoint and runs an example prediction.

    For custom implementations, refer to the run_example function inside run_on_video/run.py.

    pip install ffmpeg-python ftfy regex
    PYTHONPATH=$PYTHONPATH:. python run_on_video/run.py
  9. Prediction file JSONL format

    main

    The prediction file must be in JSON Line (.jsonl) format, where each line is a valid JSON object representing a single query's results.

    Each entry contains:

    • qid (int): Unique query ID.
    • query (str): The natural language query (not used by the evaluation script).
    • vid (str): Unique video ID.
    • pred_relevant_windows (list(list)): Moment retrieval predictions. Each sublist must contain exactly three elements: [start (seconds), end (seconds), score].
    • pred_saliency_scores (list(float)): Highlight prediction scores. Higher scores indicate higher saliency. This list must contain one score for every 2-second clip in the video, ordered sequentially.
    {
      "qid": 2579,
      "query": "A girl and her mother cooked while talking with each other on facetime.",
      "vid": "NUsG9BgSes0_210.0_360.0",
      "pred_relevant_windows": [
        [0, 70, 0.9986],
        [78, 146, 0.4138],
        [0, 146, 0.0444]
      ],
      "pred_saliency_scores": [-0.2452, -0.3779, -0.4746]
    }