Run this model with HF Jobs
Run facebook/vit-msn-base on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/facebook/vit-msn-base. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/facebook/vit-msn-base on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use facebook/vit-msn-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/vit-msn-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="facebook/vit-msn-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModel processor = AutoImageProcessor.from_pretrained("facebook/vit-msn-base") model = AutoModel.from_pretrained("facebook/vit-msn-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Create README.md (#1)
Browse files- Create README.md (99787d09c374910b6530a6499413d24890975e51)
Co-authored-by: Sayak Paul <sayakpaul@users.noreply.huggingface.co>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475---license: apache-2.0tags:- visiondatasets:- imagenet-1k---
# Vision Transformer (base-sized model) pre-trained with MSN
Vision Transformer (ViT) model pre-trained using the MSN method. It was introduced in the paper [Masked Siamese Networks for Label-Efficient Learning](https://arxiv.org/abs/2204.07141) by Mahmoud Assran, Mathilde Caron, Ishan Misra, Piotr Bojanowski, Florian Bordes, Pascal Vincent, Armand Joulin, Michael Rabbat, Nicolas Ballas and first released in [this repository](https://github.com/facebookresearch/msn).
Disclaimer: The team releasing MSN did not write a model card for this model so this model card has been written by the Hugging Face team.
## Model description
The Vision Transformer (ViT) is a transformer encoder model (BERT-like). Images are presented to the model as a sequence of fixed-size patches.
MSN presents a joint-embedding architecture to match the prototypes of masked patches with that of the unmasked patches. With this setup, their method yields excellent performance in the low-shot and extreme low-shot regimes.
By pre-training the model, it learns an inner representation of images that can then be used to extract features useful for downstream tasks: if you have a dataset of labeled images for instance, you can train a standard classifier by placing a linear layer on top of the pre-trained encoder.
## Intended uses & limitations
You can use the raw model for downstream tasks like image classification. See the [model hub](https://huggingface.co/models?filter=vit_msn) to look for different versions of MSN pre-trained models that interest you. The model is particularly beneficial when you have a few labeled samples in your training set.
### How to use
Here is how to use this backbone encoder:
```pythonfrom transformers import AutoFeatureExtractor, ViTMSNModelimport torchfrom PIL import Imageimport requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg"image = Image.open(requests.get(url, stream=True).raw)
feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/vit-msn-base")model = ViTMSNModel.from_pretrained("facebook/vit-msn-base")inputs = feature_extractor(images=image, return_tensors="pt")with torch.no_grad(): outputs = model(**inputs)last_hidden_states = outputs.last_hidden_state```
For fine-tuning on image classification use the `ViTMSNForImageClassification` class:
```pythonfrom transformers import AutoFeatureExtractor, ViTMSNForImageClassificationimport torchfrom PIL import Imageimport requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg"image = Image.open(requests.get(url, stream=True).raw)
feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/vit-msn-base")model = ViTMSNForImageClassification.from_pretrained("facebook/vit-msn-base")
...```
### Citation
```bibtex@article{assran2022masked, title={Masked Siamese Networks for Label-Efficient Learning}, author={Assran, Mahmoud, and Caron, Mathilde, and Misra, Ishan, and Bojanowski, Piotr, and Bordes, Florian and Vincent, Pascal, and Joulin, Armand, and Rabbat, Michael, and Ballas, Nicolas}, journal={arXiv preprint arXiv:2204.07141}, year={2022}}```README.mdAdded+75