Home

Awesome

Official PyTorch Implementation of MME (CVPR2023)

avatar

PWC<br> PWC

Masked Motion Encoding for Self-Supervised Video Representation Learning
Xinyu Sun, Peihao Chen, Liangwei Chen, Changhao Li, Thomas H. Li, Mingkui Tan, Chuang Gan

<span id="main-results"></span>

Main Results

UCF101 & HMDB51

MethodPre-train DataFine-tune DataBackboneAcc@1Download Link
MMEK400UCF101ViT-B96.5log/cow/google
MMEK400HMDB51ViT-B78.0log/cow/google

Kinetics-400 (K400)

MethodPre-train DataBackboneEpoch#Frames x Clips x CropsAcc@1Download Link
MMEK400ViT-B160016x7x381.8log/cow/google

Something-Something V2 (SSV2)

MethodPre-train DataBackboneEpoch#Frames x Clips x CropsAcc@1Download Link
MMESSV2ViT-B40016x2x369.2log/cow/google
MMEK400ViT-B40016x2x369.5log/cow/google
MMEK400ViT-B80016x2x370.5log/cow/google
MMEK400ViT-B160016x2x371.5log/cow/google

Model Zoo

Pre-trained Weight

MethodPre-train DataBackboneEpochDownload Link
MMEK400ViT-B1600google/cow
MMEK400ViT-B800google/cow
MMESSV2ViT-B400[TODO]

Prepare Environment

Run install.sh to create environment and install packages.

cd ${MME_FOLDER_BASE} # cd the code base of MME

export CUDA_HOME=${PATH_TO_CUDA}
export PYTHONPATH=$PYTHONPATH:`pwd`

source scripts/tools/install.sh

Troubleshooting: replace the compiled cuda version of torch/torchvision in the install.sh with your installed cuda version.

Prepare Datasets

In this step, we will put the dataset folder into this work space. In our experiments, we use Kinetics-400, Something-Something V2, UCF101, and HMDB51 four datasets.

mkdir data
ln -s ${PATH_TO_DATASET} data/

After this process, the data folder should be organized as follows:

data/
├── csv
│   └── k400
│       ├── train.csv
│       ├── val.csv
│       └── test.csv
├── kinetics400
│   ├── train_video
│   │   └── abseiling
│   │       └── ztuc7tVNUDo_000003_000013.mp4
│   └── val_video
├── smth-smth-v2
│   ├── 20bn-something-something-v2
│   │   └── 8192.mp4
│   └── annotations
├── UCF101
│   ├── UCF-101
│   │   └── ApplyEyeMakeup
│   │       └── v_ApplyEyeMakeup_g24_c05.avi
│   └── ucfTrainTestlist
└── hmdb51
    ├── videos
    │   └── brush_hair
    │       └── Silky_Straight_Hair_Original_brush_hair_h_nm_np1_ba_goo_0.avi
    └── metafile

We use the csv file to provide data lists with video path for train, val and test. As the csv file can be customized, the data folder can be organized as you preferred. Default csv files can be found here.

Prepare Motion Trajectory

<span id="A-using-pre-extracted"></span>

A. Using Pre-extracted Motion Trajectories

We provide pre-extracted motion trajectories for MME pre-training on Kinetics-400 dataset. Decompress and put it into data/trajs/kinetics400. The trajs folder should be organized as follows:

data/trajs
└── kinetics400
    └── train_video
        └── abseiling
            └── ztuc7tVNUDo_000003_000013.mp4_4.gz

B. Extract Motion Trajectories From Scratch

See EXTRACT_FEATURE.md for details.

Run MME

1. Pretrain the Model Using MME

To pretrain the model on K400 on 2 nodes with 8 x a100(80G) GPUs on each, we set NUM_PROCESS = 8, NUM_NODES=2, BATCH_SIE = 64.

bash scripts/pretrain/k400-1600epo.sh 8 2 0 MASTER_IP 64

2. Finetune the Model on Downstream Datasets

bash scripts/finetune/ssv2/k400pt-800epo.sh 8 2 0 MASTER_IP 28

We also provide finetuned models in the Main Results, you are free to download them and run eval directly.

# first: download the checkpoint and put it into the OUTPUT_DIR
exps/m3video/
└── finetune
    └── ssv2
        └── k400pt-1600epo
            └── checkpoint-best
                └── mp_rank_00_model_states.pt

# sceond: run eval!
bash scripts/finetune/ssv2/k400pt-1600epo.sh 8 1 0 localhost 28 --eval

Cite MME

Please star the project and cite our paper if it is helpful for you~

@inproceedings{sun2023mme,
  title={Masked Motion Encoding for Self-Supervised Video Representation Learning},
  author={Sun, Xinyu and Chen, Peihao and Chen, Liangwei and Li, Changhao and Li, Thomas H and Tan, Mingkui and Gan, Chuang},
  booktitle={The IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2023}
}

@article{sun2022m3video,
  title={M $\^{} 3$ Video: Masked Motion Modeling for Self-Supervised Video Representation Learning},
  author={Sun, Xinyu and Chen, Peihao and Chen, Liangwei and Li, Thomas H and Tan, Mingkui and Gan, Chuang},
  journal={arXiv preprint arXiv:2210.06096},
  year={2022}
}

Acknowledgements

Our code is modified from VideoMAE. Thanks for their awesome work!