Disclaimer: The team releasing FocalNet did not write a model card for this model so this model card has been written by the Hugging Face team.
Model description
Focul Modulation Networks are an alternative to Vision Transformers, where self-attention (SA) is completely replaced by a focal modulation mechanism for modeling token interactions in vision.
Focal modulation comprises three components: (i) hierarchical contextualization, implemented using a stack of depth-wise convolutional layers, to encode visual contexts from short to long ranges, (ii) gated aggregation to selectively gather contexts for each query token based on its
content, and (iii) element-wise modulation or affine transformation to inject the aggregated context into the query. Extensive experiments show FocalNets outperform the state-of-the-art SA counterparts (e.g., Vision Transformers, Swin and Focal Transformers) with similar computational costs on the tasks of image classification, object detection, and segmentation.
Intended uses & limitations
You can use the raw model for image classification. See the
model hub
to look for
fine-tuned versions on a task that interests you.
How to use
Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
from transformers import FocalNetImageProcessor, FocalNetForImageClassification
import torch
from datasets import load_dataset
dataset = load_dataset("huggingface/cats-image")
image = dataset["test"]["image"][0]
preprocessor = FocalNetImageProcessor.from_pretrained("microsoft/focalnet-tiny")
model = FocalNetForImageClassification.from_pretrained("microsoft/focalnet-tiny")
inputs = preprocessor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
# model predicts one of the 1000 ImageNet classes
predicted_label = logits.argmax(-1).item()
print(model.config.id2label[predicted_label]),
focalnet-tiny huggingface.co is an AI model on huggingface.co that provides focalnet-tiny's model effect (), which can be used instantly with this microsoft focalnet-tiny model. huggingface.co supports a free trial of the focalnet-tiny model, and also provides paid use of the focalnet-tiny. Support call focalnet-tiny model through api, including Node.js, Python, http.
focalnet-tiny huggingface.co is an online trial and call api platform, which integrates focalnet-tiny's modeling effects, including api services, and provides a free online trial of focalnet-tiny, you can try focalnet-tiny online for free by clicking the link below.
microsoft focalnet-tiny online free url in huggingface.co:
focalnet-tiny is an open source model from GitHub that offers a free installation service, and any user can find focalnet-tiny on GitHub to install. At the same time, huggingface.co provides the effect of focalnet-tiny install, users can directly use focalnet-tiny installed effect in huggingface.co for debugging and trial. It also supports api for free installation.