Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

V-JEPA: Video Joint Embedding Predictive Architecture

Official PyTorch codebase for the video joint-embedding predictive architecture, V-JEPA, a method for self-supervised learning of visual representations from video.

Meta AI Research, FAIR

Adrien Bardes, Quentin Garrido, Jean Ponce, Xinlei Chen, Michael Rabbat, Yann LeCun, Mahmoud Assran*, Nicolas Ballas*

[Blog][Paper][Yannic Kilcher's Video]

V-JEPA models are trained by passively watching video pixels from the VideoMix2M dataset, and produce versatile visual representations that perform well on downstream video and image tasks, without adaption of the model’s parameters; e.g., using a frozen backbone and only a light-weight task-specific attentive probe.

Method

V-JEPA pretraining is based solely on an unsupervised feature prediction objective, and does not utilize pretrained image encoders, text, negative examples, human annotations, or pixel-level reconstruction.

Visualizations

As opposed to generative methods that have a pixel decoder, V-JEPA has a predictor that makes predictions in latent space. We train a conditional diffusion model to decode the V-JEPA feature-space predictions to interpretable pixels; the pretrained V-JEPA encoder and predictor networks are kept frozen in this process. The decoder is only fed the representations predicted for the missing regions of the video, and does not have access to the unmasked regions of the video.

The V-JEPA feature predictions are indeed grounded, and exhibit spatio-temporal consistency with the unmasked regions of the video.



MODEL ZOO

Pretrained models

modelpatch sizeresolutioniterationsbatch sizedatadownload
ViT-L2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16224x22490K3072VideoMix2Mcheckpointconfigs
ViT-H2x16x16384x38490K2400VideoMix2Mcheckpointconfigs

K400 Attentive probes

modelresolutionaccuracy (16x8x3)download
ViT-L/16224x22480.8attentive probe checkpointconfigs
ViT-H/16224x22482.0attentive probe checkpointconfigs
ViT-H/16384x38481.9attentive probe checkpointconfigs

SSv2 Attentive probes

modelresolutionaccuracy (16x2x3)download
ViT-L/16224x22469.5attentive probe checkpointconfigs
ViT-H/16224x22471.4attentive probe checkpointconfigs
ViT-H/16384x38472.2attentive probe checkpointconfigs

ImageNet1K Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22474.8attentive probe checkpointconfigs
ViT-H/16224x22475.9attentive probe checkpointconfigs
ViT-H/16384x38477.4attentive probe checkpointconfigs

Places205 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22460.3attentive probe checkpointconfigs
ViT-H/16224x22461.7attentive probe checkpointconfigs
ViT-H/16384x38462.8attentive probe checkpointconfigs

iNat21 Attentive probes

modelresolutionaccuracydownload
ViT-L/16224x22467.8attentive probe checkpointconfigs
ViT-H/16224x22467.9attentive probe checkpointconfigs
ViT-H/16384x38472.6attentive probe checkpointconfigs

Code Structure

Config files: All experiment parameters are specified in config files (as opposed to command-line arguments). See the configs/ directory for example config files. Note, before launching an experiment, you must update the paths in the config file to point to your own directories, indicating where to save the logs and checkpoints and where to find the training data.

.
├── app # the only place where training loops are allowed
│ ├── vjepa # Video JEPA pre-training
│ ├── main_distributed.py # entrypoint for launching app on slurm cluster
│ └── main.py # entrypoint for launching app locally on your machine for debugging
├── evals # the only place where evaluation of 'apps' are allowed
│ ├── image_classification # training an attentive probe for image classification with frozen backbone
│ ├── video_classification # training an attentive probe for video classification with frozen backbone
│ ├── main_distributed.py # entrypoint for launching distributed evaluations on slurm cluster
│ └── main.py # entrypoint for launching evaluations locally on your machine for debugging
├── src # the package
│ ├── datasets # datasets, data loaders, ...
│ ├── models # model definitions
│ ├── masks # mask collators, masking utilities, ...
│ └── utils # shared utilities
└── configs # the only place where config files are allowed (specify experiment params for app/eval runs)
├── evals # configs for launching vjepa frozen evaluations
└── pretrain # configs for launching vjepa pretraining

Data preparation

Video Datasets

V-JEPA pretraining and evaluations work with many standard video formats. To make a video dataset compatible with the V-JEPA codebase, you simply need to create a .csv file with the following format and then specify the path to this CSV file in your config.

/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
/absolute_file_path.[mp4, webvid, etc.] $integer_class_label
...

Since V-JEPA is entirely unsupervised, the pretraining code will disregard the $integer_class_label in the CSV file. Thus, feel free to put a random value in this column. However, if you wish to run a supervised video classification evaluation on your video dataset, you must replace $integer_class_label with the ground truth label for each video.

Image Datasets

We use the standard PyTorch ImageFolder class in our image classification evals. Thus, to set up an image dataset for the image classification evaluation, first create a directory to store your image datasets $your_directory_containing_image_datasets. Next, download your image datasets into this directory in a format compatible with PyTorch ImageFolder.

For example, suppose we have a directory called my_image_datasets. We would then download our image datasets into this directory so that we end up with the following file tree

.
└── /my_image_datasets/ # where we store image datasets
├── places205/121517/pytorch/ # Places205
│ └── [...]
├── iNaturalist-2021/110421/ # iNaturalist21
│ └── [...]
├── [...] # Other Image Datasets
│ └── [...]
└── imagenet_full_size/061417/ # ImageNet1k
└── train
│ ├── $class_1
│ │ ├── xxx.[png, jpeg, etc.]
│ │ ├── [...]
│ │ └── xxz.[png, jpeg, etc.]
│ ├── [...]
│ └── $class_n
│ ├── abc.[png, jpeg, etc.]
│ ├── [...]
│ └── abz.[png, jpeg, etc.]
└── val
├── $class_1
│ ├── xxx.[png, jpeg, etc.]
│ ├── [...]
│ └── xxz.[png, jpeg, etc.]
├── [...]
└── $class_n
├── abc.[png, jpeg, etc.]
├── [...]
└── abz.[png, jpeg, etc.]

Launching V-JEPA pretraining

Local training

If you wish to debug your code or setup before launching a distributed training run, we provide the functionality to do so by running the pretraining script locally on a multi-GPU (or single-GPU) machine, however, reproducing our results requires launching distributed training.

The single-machine implementation starts from the app/main.py, which parses the experiment config file and runs the pretraining locally on a multi-GPU (or single-GPU) machine. For example, to run V-JEPA pretraining on GPUs "0", "1", and "2" on a local machine using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main \
--fname configs/pretrain/vitl16.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed training run, the implementation starts from app/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed pre-training experiment using the config configs/pretrain/vitl16.yaml, type the command:

python -m app.main_distributed \
--fname configs/pretrain/vitl16.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Launching Evaluations

Local training

If you wish to debug your eval code or setup before launching a distributed training run, we provide the functionality to do so by running the evaluation script locally on a multi-GPU (or single-GPU) machine, however, reproducing the full eval would require launching distributed training. The single-machine implementation starts from the eval/main.py, which parses the experiment config file and runs the eval locally on a multi-GPU (or single-GPU) machine.

For example, to run ImageNet image classification on GPUs "0", "1", and "2" on a local machine using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main \
--fname configs/eval/vitl16_in1k.yaml \
--devices cuda:0 cuda:1 cuda:2

Distributed training

To launch a distributed evaluation run, the implementation starts from eval/main_distributed.py, which, in addition to parsing the config file, also allows for specifying details about distributed training. For distributed training, we use the popular open-source submitit tool and provide examples for a SLURM cluster.

For example, to launch a distributed ImageNet image classification experiment using the config configs/eval/vitl16_in1k.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_in1k.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Similarly, to launch a distributed K400 video classification experiment using the config configs/eval/vitl16_k400.yaml, type the command:

python -m evals.main_distributed \
--fname configs/eval/vitl16_k400.yaml \
--folder $path_to_save_stderr_and_stdout \
--partition $slurm_partition

Setup

Run:

conda create -n jepa python=3.9 pip
conda activate jepa
python setup.py install

License

See the LICENSE file for details about the license under which this code is made available.

Citation

If you find this repository useful in your research, please consider giving a star ⭐ and a citation

@article{bardes2024revisiting,
title={Revisiting Feature Prediction for Learning Visual Representations from Video},
author={Bardes, Adrien and Garrido, Quentin and Ponce, Jean and Rabbat, Michael, and LeCun, Yann and Assran, Mahmoud and Ballas, Nicolas},
journal={arXiv:2404.08471},
year={2024}
}

About

PyTorch code and models for V-JEPA self-supervised learning from video.

Resources

Code of conduct

Contributing

Security policy

Stars

4.1k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages