Transformers image processing examples¶
Transformers provides APIs and tools to easily download and train state-of-the-art pretrained models. Credits: Huggingface documentation
Image classification¶
In [1]:
from transformers import pipeline
In [2]:
# Create the image classification pipeline with GPU
vision_classifier = pipeline(model="google/vit-base-patch16-224", device=0) # Specify the GPU device index
In [3]:
image_url="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
In [4]:
from IPython.display import Image
Image(url=image_url)
Out[4]:
In [5]:
preds = vision_classifier(image_url)
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
preds
Out[5]:
In [ ]: