Skip to content

Commit f02c216

Browse files
merveenoyanosansevieropcuenca
authored
Update tasks and 🛳️ mask-generation and zero-shot-object-detection (#462)
This is a follow-up to my previous PR to add resources to various tasks and ship mask-generation and zero-shot-object-detection --------- Co-authored-by: Omar Sanseviero <osanseviero@gmail.com> Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
1 parent b70ac6c commit f02c216

File tree

8 files changed

+88
-24
lines changed

8 files changed

+88
-24
lines changed

packages/tasks/src/tasks/automatic-speech-recognition/about.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ These events help democratize ASR for all languages, including low-resource lang
8383
- [Massively Multilingual ASR: 50 Languages, 1 Model, 1 Billion Parameters](https://arxiv.org/pdf/2007.03001.pdf)
8484
- An ASR toolkit made by [NVIDIA: NeMo](https://github.com/NVIDIA/NeMo) with code and pretrained models useful for new ASR models. Watch the [introductory video](https://www.youtube.com/embed/wBgpMf_KQVw) for an overview.
8585
- [An introduction to SpeechT5, a multi-purpose speech recognition and synthesis model](https://huggingface.co/blog/speecht5)
86-
- [A guide on Fine-tuning Whisper For Multilingual ASR with 🤗Transformers](https://huggingface.co/blog/fine-tune-whisper)
86+
- [Fine-tune Whisper For Multilingual ASR with 🤗Transformers](https://huggingface.co/blog/fine-tune-whisper)
8787
- [Automatic speech recognition task guide](https://huggingface.co/docs/transformers/tasks/asr)
8888
- [Speech Synthesis, Recognition, and More With SpeechT5](https://huggingface.co/blog/speecht5)
89+
- [Fine-Tune W2V2-Bert for low-resource ASR with 🤗 Transformers](https://huggingface.co/blog/fine-tune-w2v2-bert)
90+
- [Speculative Decoding for 2x Faster Whisper Inference](https://huggingface.co/blog/whisper-speculative-decoding)

packages/tasks/src/tasks/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import imageClassification from "./image-classification/data";
1111
import imageToImage from "./image-to-image/data";
1212
import imageToText from "./image-to-text/data";
1313
import imageSegmentation from "./image-segmentation/data";
14+
import maskGeneration from "./mask-generation/data";
1415
import objectDetection from "./object-detection/data";
1516
import depthEstimation from "./depth-estimation/data";
1617
import placeholder from "./placeholder/data";
@@ -33,6 +34,7 @@ import videoClassification from "./video-classification/data";
3334
import visualQuestionAnswering from "./visual-question-answering/data";
3435
import zeroShotClassification from "./zero-shot-classification/data";
3536
import zeroShotImageClassification from "./zero-shot-image-classification/data";
37+
import zeroShotObjectDetection from "./zero-shot-object-detection/data";
3638

3739
import type { ModelLibraryKey } from "../model-libraries";
3840

@@ -131,7 +133,7 @@ export const TASKS_DATA: Record<PipelineType, TaskData | undefined> = {
131133
"image-to-image": getData("image-to-image", imageToImage),
132134
"image-to-text": getData("image-to-text", imageToText),
133135
"image-to-video": undefined,
134-
"mask-generation": getData("mask-generation", placeholder),
136+
"mask-generation": getData("mask-generation", maskGeneration),
135137
"multiple-choice": undefined,
136138
"object-detection": getData("object-detection", objectDetection),
137139
"video-classification": getData("video-classification", videoClassification),
@@ -162,7 +164,7 @@ export const TASKS_DATA: Record<PipelineType, TaskData | undefined> = {
162164
"voice-activity-detection": undefined,
163165
"zero-shot-classification": getData("zero-shot-classification", zeroShotClassification),
164166
"zero-shot-image-classification": getData("zero-shot-image-classification", zeroShotImageClassification),
165-
"zero-shot-object-detection": getData("zero-shot-object-detection", placeholder),
167+
"zero-shot-object-detection": getData("zero-shot-object-detection", zeroShotObjectDetection),
166168
"text-to-3d": getData("text-to-3d", placeholder),
167169
"image-to-3d": getData("image-to-3d", placeholder),
168170
} as const;

packages/tasks/src/tasks/mask-generation/about.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,56 @@ When filtering for an image, the generated masks might serve as an initial filte
66

77
### Masked Image Modelling
88

9-
Generating masks can be done to facilitate learning, especially in semi- or unsupervised learning. For example, the [BEiT model](https://huggingface.co/docs/transformers/model_doc/beit) uses image-masked patches in the pre-training.
9+
Generating masks can facilitate learning, especially in semi or unsupervised learning. For example, the [BEiT model](https://huggingface.co/docs/transformers/model_doc/beit) uses image-mask patches in the pre-training.
1010

11-
### Human-in-the-loop
11+
### Human-in-the-loop Computer Vision Applications
1212

13-
For applications where humans are in the loop, masks highlight certain region of images for humans to validate.
13+
For applications where humans are in the loop, masks highlight certain regions of images for humans to validate.
1414

1515
## Task Variants
1616

1717
### Segmentation
1818

19-
Image Segmentation divides an image into segments where each pixel in the image is mapped to an object. This task has multiple variants such as instance segmentation, panoptic segmentation and semantic segmentation. You can learn more about segmentation on its [task page](https://huggingface.co/tasks/image-segmentation).
19+
Image Segmentation divides an image into segments where each pixel is mapped to an object. This task has multiple variants, such as instance segmentation, panoptic segmentation, and semantic segmentation. You can learn more about segmentation on its [task page](https://huggingface.co/tasks/image-segmentation).
2020

2121
## Inference
2222

23+
Mask generation models often work in two modes: segment everything or prompt mode.
24+
The example below works in segment-everything-mode, where many masks will be returned.
25+
2326
```python
2427
from transformers import pipeline
25-
generator = pipeline("mask-generation", device = 0, points_per_batch = 256)
28+
29+
generator = pipeline("mask-generation", model="Zigeng/SlimSAM-uniform-50", points_per_batch=64, device="cuda")
2630
image_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
27-
outputs = generator(image_url, points_per_batch = 256)
31+
outputs = generator(image_url)
32+
outputs["masks"]
33+
# array of multiple binary masks returned for each generated mask
34+
```
35+
36+
Prompt mode takes in three types of prompts:
37+
38+
- **Point prompt:** The user can select a point on the image, and a meaningful segment around the point will be returned.
39+
- **Box prompt:** The user can draw a box on the image, and a meaningful segment within the box will be returned.
40+
- **Text prompt:** The user can input a text, and the objects of that type will be segmented. Note that this capability has not yet been released and has only been explored in research.
41+
42+
Below you can see how to use an input-point prompt. It also demonstrates direct model inference without the `pipeline` abstraction. The input prompt here is a nested list where the outermost list is the batch size (`1`), then the number of points (also `1` in this example), and the innermost list contains the actual coordinates of the point (`[450, 600]`).
43+
44+
```python
45+
from transformers import SamModel, SamProcessor
46+
from PIL import Image
47+
import requests
48+
49+
model = SamModel.from_pretrained("Zigeng/SlimSAM-uniform-50").to("cuda")
50+
processor = SamProcessor.from_pretrained("Zigeng/SlimSAM-uniform-50")
51+
52+
raw_image = Image.open(requests.get(image_url, stream=True).raw).convert("RGB")
53+
# pointing to the car window
54+
input_points = [[[450, 600]]]
55+
inputs = processor(raw_image, input_points=input_points, return_tensors="pt").to("cuda")
56+
outputs = model(**inputs)
57+
masks = processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
58+
scores = outputs.iou_scores
2859
```
2960

3061
## Useful Resources

packages/tasks/src/tasks/text-classification/about.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ classifier("I will walk to home when I went through the bus.")
150150

151151
Would you like to learn more about the topic? Awesome! Here you can find some curated resources that you may find helpful!
152152

153+
- [SetFitABSA: Few-Shot Aspect Based Sentiment Analysis using SetFit](https://huggingface.co/blog/setfit-absa)
153154
- [Course Chapter on Fine-tuning a Text Classification Model](https://huggingface.co/course/chapter3/1?fw=pt)
154155
- [Getting Started with Sentiment Analysis using Python](https://huggingface.co/blog/sentiment-analysis-python)
155156
- [Sentiment Analysis on Encrypted Data with Homomorphic Encryption](https://huggingface.co/blog/sentiment-analysis-fhe)

packages/tasks/src/tasks/text-generation/about.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,36 @@ Would you like to learn more about the topic? Awesome! Here you can find some cu
110110
- [ChatUI Docker Spaces](https://huggingface.co/docs/hub/spaces-sdks-docker-chatui)
111111
- [Causal language modeling task guide](https://huggingface.co/docs/transformers/tasks/language_modeling)
112112
- [Text generation strategies](https://huggingface.co/docs/transformers/generation_strategies)
113+
- [Course chapter on training a causal language model from scratch](https://huggingface.co/course/chapter7/6?fw=pt)
113114

114-
### Course and Blogs
115+
### Model Inference & Deployment
115116

116-
- [Course Chapter on Training a causal language model from scratch](https://huggingface.co/course/chapter7/6?fw=pt)
117-
- [TO Discussion with Victor Sanh](https://www.youtube.com/watch?v=Oy49SCW_Xpw&ab_channel=HuggingFace)
118-
- [Hugging Face Course Workshops: Pretraining Language Models & CodeParrot](https://www.youtube.com/watch?v=ExUR7w6xe94&ab_channel=HuggingFace)
119-
- [Training CodeParrot 🦜 from Scratch](https://huggingface.co/blog/codeparrot)
120-
- [How to generate text: using different decoding methods for language generation with Transformers](https://huggingface.co/blog/how-to-generate)
117+
- [Optimizing your LLM in production](https://huggingface.co/blog/optimize-llm)
118+
- [Open-Source Text Generation & LLM Ecosystem at Hugging Face](https://huggingface.co/blog/os-llms)
119+
- [Introducing RWKV - An RNN with the advantages of a transformer](https://huggingface.co/blog/rwkv)
120+
- [Llama 2 is at Hugging Face](https://huggingface.co/blog/llama2)
121121
- [Guiding Text Generation with Constrained Beam Search in 🤗 Transformers](https://huggingface.co/blog/constrained-beam-search)
122122
- [Code generation with Hugging Face](https://huggingface.co/spaces/codeparrot/code-generation-models)
123-
- [🌸 Introducing The World's Largest Open Multilingual Language Model: BLOOM 🌸](https://huggingface.co/blog/bloom)
124-
- [The Technology Behind BLOOM Training](https://huggingface.co/blog/bloom-megatron-deepspeed)
125-
- [Faster Text Generation with TensorFlow and XLA](https://huggingface.co/blog/tf-xla-generate)
126123
- [Assisted Generation: a new direction toward low-latency text generation](https://huggingface.co/blog/assisted-generation)
127-
- [Introducing RWKV - An RNN with the advantages of a transformer](https://huggingface.co/blog/rwkv)
124+
- [How to generate text: using different decoding methods for language generation with Transformers](https://huggingface.co/blog/how-to-generate)
125+
- [Faster Text Generation with TensorFlow and XLA](https://huggingface.co/blog/tf-xla-generate)
126+
127+
### Model Fine-tuning/Training
128+
129+
- [Non-engineers guide: Train a LLaMA 2 chatbot](https://huggingface.co/blog/Llama2-for-non-engineers)
130+
- [Training CodeParrot 🦜 from Scratch](https://huggingface.co/blog/codeparrot)
128131
- [Creating a Coding Assistant with StarCoder](https://huggingface.co/blog/starchat-alpha)
129-
- [StarCoder: A State-of-the-Art LLM for Code](https://huggingface.co/blog/starcoder)
130-
- [Open-Source Text Generation & LLM Ecosystem at Hugging Face](https://huggingface.co/blog/os-llms)
131-
- [Llama 2 is at Hugging Face](https://huggingface.co/blog/llama2)
132+
133+
### Advanced Concepts Explained Simply
134+
135+
- [Mixture of Experts Explained](https://huggingface.co/blog/moe)
136+
137+
### Advanced Fine-tuning/Training Recipes
138+
139+
- [Fine-tuning Llama 2 70B using PyTorch FSDP](https://huggingface.co/blog/ram-efficient-pytorch-fsdp)
140+
- [The N Implementation Details of RLHF with PPO](https://huggingface.co/blog/the_n_implementation_details_of_rlhf_with_ppo)
141+
- [Preference Tuning LLMs with Direct Preference Optimization Methods](https://huggingface.co/blog/pref-tuning)
142+
- [Fine-tune Llama 2 with DPO](https://huggingface.co/blog/dpo-trl)
132143

133144
### Notebooks
134145

packages/tasks/src/tasks/text-to-image/about.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,23 @@ await inference.textToImage({
5353

5454
## Useful Resources
5555

56+
### Model Inference
57+
5658
- [Hugging Face Diffusion Models Course](https://github.com/huggingface/diffusion-models-class)
5759
- [Getting Started with Diffusers](https://huggingface.co/docs/diffusers/index)
5860
- [Text-to-Image Generation](https://huggingface.co/docs/diffusers/using-diffusers/conditional_image_generation)
59-
- [MinImagen - Build Your Own Imagen Text-to-Image Model](https://www.assemblyai.com/blog/minimagen-build-your-own-imagen-text-to-image-model/)
60-
- [Using LoRA for Efficient Stable Diffusion Fine-Tuning](https://huggingface.co/blog/lora)
6161
- [Using Stable Diffusion with Core ML on Apple Silicon](https://huggingface.co/blog/diffusers-coreml)
6262
- [A guide on Vector Quantized Diffusion](https://huggingface.co/blog/vq-diffusion)
6363
- [🧨 Stable Diffusion in JAX/Flax](https://huggingface.co/blog/stable_diffusion_jax)
6464
- [Running IF with 🧨 diffusers on a Free Tier Google Colab](https://huggingface.co/blog/if)
65+
- [Introducing Würstchen: Fast Diffusion for Image Generation](https://huggingface.co/blog/wuerstchen)
66+
- [Efficient Controllable Generation for SDXL with T2I-Adapters](https://huggingface.co/blog/t2i-sdxl-adapters)
67+
- [Welcome aMUSEd: Efficient Text-to-Image Generation](https://huggingface.co/blog/amused)
68+
69+
### Model Fine-tuning
70+
71+
- [Finetune Stable Diffusion Models with DDPO via TRL](https://huggingface.co/blog/pref-tuning)
72+
- [LoRA training scripts of the world, unite!](https://huggingface.co/blog/sdxl_lora_advanced_script)
73+
- [Using LoRA for Efficient Stable Diffusion Fine-Tuning](https://huggingface.co/blog/lora)
6574

6675
This page was made possible thanks to the efforts of [Ishan Dutta](https://huggingface.co/ishandutta), [Enrique Elias Ubaldo](https://huggingface.co/herrius) and [Oğuz Akif](https://huggingface.co/oguzakif).

packages/tasks/src/tasks/text-to-speech/about.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ await inference.textToSpeech({
6161
- [An introduction to SpeechT5, a multi-purpose speech recognition and synthesis model](https://huggingface.co/blog/speecht5).
6262
- [A guide on Fine-tuning Whisper For Multilingual ASR with 🤗Transformers](https://huggingface.co/blog/fine-tune-whisper)
6363
- [Speech Synthesis, Recognition, and More With SpeechT5](https://huggingface.co/blog/speecht5)
64+
- [Optimizing a Text-To-Speech model using 🤗 Transformers](https://huggingface.co/blog/optimizing-bark)
65+
-

packages/tasks/src/tasks/zero-shot-object-detection/about.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Use Cases
22

3+
Zero-shot object detection models can be used in any object detection application where the detection involves text queries for objects of interest.
4+
35
### Object Search
46

57
Zero-shot object detection models can be used in image search. Smartphones, for example, use zero-shot object detection models to detect entities (such as specific places or objects) and allow the user to search for the entity on the internet.
@@ -8,6 +10,10 @@ Zero-shot object detection models can be used in image search. Smartphones, for
810

911
Zero-shot object detection models are used to count instances of objects in a given image. This can include counting the objects in warehouses or stores or the number of visitors in a store. They are also used to manage crowds at events to prevent disasters.
1012

13+
### Object Tracking
14+
15+
Zero-shot object detectors can track objects in videos.
16+
1117
## Inference
1218

1319
You can infer with zero-shot object detection models through the `zero-shot-object-detection` pipeline. When calling the pipeline, you just need to specify a path or HTTP link to an image and the candidate labels.

0 commit comments

Comments
 (0)