Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tasks/src/tasks/depth-estimation/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ With the `transformers` library, you can use the `depth-estimation` pipeline to
```python
from transformers import pipeline

estimator = pipeline(task="depth-estimation", model="Intel/dpt-large")
estimator = pipeline(task="depth-estimation", model="Intel/dpt-large", device=0)
result = estimator(images="http://images.cocodataset.org/val2017/000000039769.jpg")
result

Expand Down
10 changes: 5 additions & 5 deletions packages/tasks/src/tasks/image-classification/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ With the `transformers` library, you can use the `image-classification` pipeline

```python
from transformers import pipeline
clf = pipeline("image-classification")
clf("path_to_a_cat_image")
image_classifier = pipeline(task="image-classification", model="microsoft/resnet-50", device=0)
result = image_classifier(IMAGE_PATH)
result

[{'label': 'tabby cat', 'score': 0.731},
...
]
# [{'label': 'Egyptian cat', 'score': 0.7005051970481873},
# {'label': 'tabby, tabby cat', 'score': 0.16163259744644165}]
```

You can use [huggingface.js](https://github.com/huggingface/huggingface.js) to classify images using models on Hugging Face Hub.
Expand Down
13 changes: 10 additions & 3 deletions packages/tasks/src/tasks/image-segmentation/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ Panoptic Segmentation is the Image Segmentation task that segments the image bot

You can infer with Image Segmentation models using the `image-segmentation` pipeline. You need to install [timm](https://github.com/rwightman/pytorch-image-models) first.

```python
```bash
!pip install timm
model = pipeline("image-segmentation")
model("cat.png")
```

```python
from transformers import pipeline

model = pipeline(task="image-segmentation", model="facebook/detr-resnet-50-panoptic", device=0)
result = model(IMAGE_PATH)
result

#[{'label': 'cat',
# 'mask': mask_code,
# 'score': 0.999}
Expand Down
6 changes: 3 additions & 3 deletions packages/tasks/src/tasks/object-detection/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Object Detection models are used to count instances of objects in a given image,
You can infer with Object Detection models through the `object-detection` pipeline. When calling the pipeline you just need to specify a path or http link to an image.

```python
model = pipeline("object-detection")

model("path_to_cat_image")
model = pipeline(task="object-detection", model="facebook/detr-resnet-50", device=0)
result = model(IMAGE_PATH)
result

# [{'label': 'blanket',
# 'mask': mask_string,
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/src/tasks/video-classification/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below you can find code for inferring with a pre-trained video classification mo
```python
from transformers import pipeline

pipe = pipeline(task = "video-classification", model="nateraw/videomae-base-finetuned-ucf101-subset")
pipe = pipeline(task="video-classification", model="nateraw/videomae-base-finetuned-ucf101-subset", device=0)
pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/basketball.avi?download=true")

#[{'score': 0.90, 'label': 'BasketballDunk'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can use the 🤗 Transformers library zero-shot-classification pipeline to i
```python
from transformers import pipeline

pipe = pipeline(model="facebook/bart-large-mnli")
pipe = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
pipe("I have a problem with my iphone that needs to be resolved asap!",
candidate_labels=["urgent", "not urgent", "phone", "tablet", "computer"],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ The model can be loaded with the zero-shot-image-classification pipeline like so
from transformers import pipeline
# More models in the model hub.
model_name = "openai/clip-vit-large-patch14-336"
classifier = pipeline("zero-shot-image-classification", model = model_name)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
classifier = pipeline(task="zero-shot-image-classification", model=model_name, device=device)
```

You can then use this pipeline to classify images into any of the class names you specify. You can specify more than two class labels too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from PIL import Image

image = Image.open("my-image.png").convert("RGB")

detector = pipeline(model="google/owlvit-base-patch32", task="zero-shot-object-detection")
detector = pipeline(task="zero-shot-object-detection", model="google/owlvit-base-patch32")

predictions = detector(
image,
Expand Down