liveBook · Manning

Single-modal model

As explained in Hugging Face in Action

A single-modal model is a machine learning model that processes data from one modality, such as only images or only text.

A single-modal model processes data from one modality, such as text, images, audio, or numerical data. GPT and BERT process text, while ResNet processes images. section 6.2

Single-modal models support focused tasks:

  • Process only visual input for object detection and image segmentation. section 6.2.1
  • Contrast with multimodal models, which combine inputs such as images and text. section 6.2

Detecting objects with DETR

The facebook/detr-resnet-50 model processes an image containing a dog and cat, returning confidence scores, labels, and bounding boxes. Drawing those boxes produces a labeled visual result. section 6.2.1

Listing 6.10 Using the facebook/detr-resnet-50 model to detect objects in images
from transformers import DetrImageProcessor, DetrForObjectDetection
import torch

image_processor = DetrImageProcessor.from_pretrained(
    "facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")

inputs = image_processor(images = image,  #1
                         return_tensors = "pt")

model.eval()

with torch.no_grad():
    outputs = model(**inputs)  #2
target_sizes = torch.tensor([image.size[::-1]])  #3

results = image_processor.post_process_object_detection(  #4
              outputs,
              target_sizes = target_sizes,
              threshold = 0.9)[0]
print(results)

Load DETR through Hugging Face Transformers, preprocess the image, run inference with PyTorch, and post-process detections. section 6.2.1

How Hugging Face in Action covers it

How deep it goes
Defines the model and demonstrates image detection through preprocessing, inference, confidence filtering, and bounding-box visualization.
Examples
Demonstrates GPT, BERT, ResNet, and DETR, including dog-and-cat detection with labels, scores, and bounding boxes.
What you can do after
Apply it via Hugging Face Transformers and PyTorch to detect objects and visualize their locations in an image.
How it connects
Contrasts single-modal models with multimodal models and connects them to object detection, image segmentation, NLP, CNNs, and transformers.

Also explained in

Compare how 2 books explain single-modal model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.