Loading…
Glossary term
Assigning a label to an entire image, such as cat or dog.
Image classification assigns one label to a whole picture, such as 'cat' or 'tumor present'. A network turns the pixels into features and outputs a probability for each possible class.
It was the task that sparked the deep learning boom through the ImageNet competition.
Classify an image
import torch
from torchvision import models, transforms
from PIL import Image
weights = models.ResNet18_Weights.DEFAULT
model = models.resnet18(weights=weights).eval()
img = weights.transforms()(Image.open("cat.jpg")).unsqueeze(0)
probs = model(img).softmax(dim=1)
print(weights.meta["categories"][probs.argmax()])It is the simplest vision task and the base for many others.