Skip to content

Additional Fields & Internal Features

Where a ModelSpec declares how the model's output is read, the two options on this page add to what gets recorded. Both are independent of ModelSpec and are given when you initialize a Tracer / Logger / DataFilter.

Option What it adds
additional_fields / additional_label_fields Records arbitrary metadata on predictions and annotations
target_layers Records the outputs of the specific layers as additional internal features

additional_fields / additional_label_fields

Options for recording arbitrary additional information for predictions and annotations.

Parameter Target Description
additional_fields Predictions Record additional metadata for each prediction
additional_label_fields Annotations Record additional metadata for each ground-truth label

Specification at initialization

Specify additional fields in List[dict] format. Each dict can have the following keys.

Key Required Description
name Yes Field name
type No Python type (str, int, float, etc.)
nullable No Allow null values (default: True)
from ml_debugger.training import ClassificationTracer

tracer = ClassificationTracer(
    model=model,
    model_name="my_model",
    version_name="v1",
    # Fields to add to predictions
    additional_fields=[
        {"name": "camera_id", "type": str},
        {"name": "lighting_condition", "type": str},
        {"name": "temperature", "type": float, "nullable": True},
    ],
    # Fields to add to annotations
    additional_label_fields=[
        {"name": "annotator_id", "type": str},
        {"name": "confidence_level", "type": int},
    ],
)

Specifying values during tracing

Pass additional field values as lists in the **kwargs of the __call__ method. The list length must match the batch size.

# Batch processing (example with batch_size=4)
output = tracer(
    model_input=images,          # shape: (4, C, H, W)
    ground_truth=labels,         # shape: (4,)
    input_ids=input_ids,         # ["img_001", "img_002", "img_003", "img_004"]
    dataset_type="train",
    # Pass additional_fields / additional_label_fields values as lists
    camera_id=["CAM_001", "CAM_002", "CAM_001", "CAM_003"],
    lighting_condition=["daylight", "night", "daylight", "indoor"],
    temperature=[25.5, 18.0, 26.0, 22.5],
    annotator_id=["annotator_A", "annotator_A", "annotator_B", "annotator_A"],
    confidence_level=[3, 2, 3, 1],
)

Dynamic field addition

If you pass fields not defined at initialization, the schema is updated automatically. Specifying types in advance with additional_fields is still recommended.

How this differs from FromCall in a ModelSpec

By default, a kwarg passed to the Tracer is only recorded as metadata — it does not reach the model. To pass it as an inference argument, declare invoke=Invoke(kwargs={"name": FromCall()}).

Usage example

Additional fields let you analyze evaluation results by condition.

result = evaluator.get_result(result_name="my_result")

# Error distribution by lighting condition
lighting_view = result.get_view(
    groupby=["lighting_condition", "category"],
    adjustby="lighting_condition",
)

# Error distribution by camera
camera_view = result.get_view(
    groupby=["camera_id", "category"],
    adjustby="camera_id",
)

Use cases

  • Shooting conditions: camera ID, lighting, weather, time of day
  • Data source: collection location, device type
  • Annotation quality: annotator, confidence level, review status
  • Object Detection: object size, occlusion presence

target_layers — choosing the additional feature-extraction layers (Advanced)

If you want to collect additional internal features beyond the standard analysis configuration of MLdebugger, specify the layers from which to extract those internal features using a dict of alias names and paths to the layers.
Please consult the Adansons Team regarding analysis for additional internal features.

tracer = ClassificationTracer(
    model=model,
    model_name="my_model",
    version_name="v1",
    target_layers={
        # key:   alias name (used as the column name)
        # value: path to the layer (a path from model.named_modules())
        "fc_output": "fc",
        "conv_features": "backbone.layer4",
    },
)

Specify it on both the Tracer and the DataFilter

When you name feature layers explicitly for a model that is not auto-detected, pass the same target_layers to both the training-time Tracer and the selection-time DataFilter. Setting only one of them makes the collected and the selection-time features disagree.