YOLO Vision 2026:
Back to Ultralytics Glossary

Multiple Instance Learning

Learn how Multiple Instance Learning uses bag-level labels, instance aggregation, and weak supervision for medical imaging, inspection, and classification.

Multiple Instance Learning (MIL) is a machine learning approach in which training examples are organized into groups called bags, while the elements inside each bag are called instances. The model receives a label for the whole bag but not for each instance. For example, a pathology slide may be labeled “cancer present” without identifying which image regions contain cancer cells. MIL is useful when detailed annotation is expensive, ambiguous, or unavailable.

How Multiple Instance Learning Works#

In conventional supervised learning, every training example has its own label. MIL changes the unit of supervision: the label belongs to a set of related examples.

A bag might be a video containing many frames, a document containing many passages, or a large image divided into patches. Each frame, passage, or patch is an instance. A typical MIL model has three components:

  1. An instance encoder converts each instance into a numerical feature representation.
  2. An aggregation function combines the instance representations into one bag representation.
  3. A bag classifier predicts the bag label from that combined representation.

For binary classification, the traditional MIL assumption says that a positive bag contains at least one positive instance, while every instance in a negative bag is negative. This assumption fits tasks where one small region can determine the overall result. Other problems require collective assumptions, such as predicting a positive label only when several instances show supporting evidence.

Because MIL learns from bag labels, it is considered a form of weak supervision. Unlike ordinary image classification, it does not assume that the complete image or every region expresses the assigned class. This avoids incorrectly copying a bag label onto all instances.

Aggregation and Instance Importance#

Aggregation must handle different bag sizes and should usually be independent of instance order. Common strategies include:

  • Max pooling: Uses the strongest instance signal. It matches the “at least one positive instance” assumption but can be sensitive to outliers.
  • Mean pooling: Averages evidence across the bag. It works better when many instances contribute but can dilute rare positive evidence.
  • Attention pooling: Learns how strongly each instance should influence the result. The resulting weights can indicate important regions, although they are not guaranteed explanations.

The pooled output is converted into a bag score, often using a probability function such as Softmax. Training compares this score with the bag label and uses backpropagation to update the encoder and aggregator together.

MIL primarily optimizes bag-level predictions. Even when a model assigns high importance to particular instances, those scores are not automatically reliable instance labels or precise localizations.

Real-World Applications#

  • Medical image analysis: A digitized tissue slide can contain thousands of patches, while the available diagnosis applies only to the patient or slide. MIL can process the patches as instances and predict whether the complete slide contains evidence of disease. This is valuable for medical image analysis because drawing detailed boundaries around every abnormal region requires specialist time. The NCI Genomic Data Commons AI resources describe whole-slide images as inputs for cancer classification, feature detection, and outcome prediction. (gdc.cancer.gov)

  • Industrial visual inspection: A manufactured component may be photographed from several angles or recorded as a short sequence. Quality inspectors may label the complete inspection as “defective” without identifying the exact view containing a crack or missing part. MIL can treat the views as one bag and learn which visual evidence predicts failure. If precise defect locations later become necessary, selected instances can be annotated for object detection or instance segmentation.

MIL differs from several closely related approaches:

  • Weak supervision is the broader category covering incomplete, noisy, or indirect labels. MIL specifically uses labels attached to bags of instances.
  • Semi-supervised learning combines labeled and unlabeled examples. MIL bags are labeled, but their individual instances are usually unlabeled.
  • Multi-label learning predicts several classes for one example. MIL describes how examples are grouped, so a system can be both multi-instance and multi-label.
  • Attention mechanisms determine how information is weighted or combined. They can implement MIL aggregation but do not define MIL by themselves.
  • Object detection requires localized annotations such as bounding boxes. MIL can sometimes highlight likely regions, but bag-level training alone does not provide verified object locations.

Practical Workflow and Evaluation#

The following inference sketch uses an Ultralytics YOLO26 classification model to score two image instances and applies max aggregation. It demonstrates the bag decision concept rather than a jointly trained MIL model.

from ultralytics import YOLO

# Treat related images as instances within one bag
sources = [
    "https://ultralytics.com/images/bus.jpg",
    "https://ultralytics.com/images/zidane.jpg",
]

model = YOLO("yolo26n-cls.pt")
results = model(sources)

# Aggregate evidence for one target class across the bag
target_name = "minibus"
target_id = next(i for i, name in results[0].names.items() if name == target_name)
instance_scores = [float(result.probs.data[target_id]) for result in results]
bag_score = max(instance_scores)

print(f"{target_name} bag probability: {bag_score:.3f}")

A complete MIL implementation trains a bag-aware aggregator using bag labels. Ultralytics YOLO supports standard classification workflows, while custom MIL logic is needed to group instances and optimize bag-level loss.

Practitioners should preserve bag boundaries during batching, test multiple aggregation rules, and prevent related instances from crossing dataset splits. Tools such as GroupKFold cross-validation can keep patches from the same patient, video, or product together. Evaluate bag-level precision and recall, and add instance-level evaluation if localization matters. Ultralytics Platform can support dataset management, annotation, standard model training, and deployment when an MIL pipeline is combined with detection, segmentation, or classification components.

Explore solutions

Let's build the future of AI together!

Begin your journey with the future of machine learning