Skip to content

Feature request: infer model size from checkpoint for easier loading #651

@pirnerjonas

Description

@pirnerjonas

Search before asking

  • I have searched the RF-DETR issues and found no similar feature requests.

Description

Problem

When loading a fine-tuned RF-DETR checkpoint, the user must know and specify the correct model size class (RFDETRLarge, RFDETRBase, etc.). This becomes inconvenient when you have old checkpoints on disk and don't remember which variant was used for training.

Currently you have to do:

from rfdetr import RFDETRLarge  # must know this upfront
model = RFDETRLarge(pretrain_weights="checkpoint_best_total.pth", num_classes=2)

Observation

The checkpoint already stores this information. The saved args namespace contains pretrain_weights which includes the model size in the filename (e.g. rf-detr-large-2026.pth), and encoder which differs by variant. For example:

import torch
ckpt = torch.load("checkpoint_best_total.pth", map_location="cpu", weights_only=False)
print(ckpt["args"].pretrain_weights)  # 'rf-detr-large-2026.pth'
print(ckpt["args"].encoder)           # 'dinov2_windowed_small'

Suggestion

It would be nice to have a convenience loader that infers the model class from the checkpoint, e.g.:

import rfdetr
model = rfdetr.from_checkpoint("checkpoint_best_total.pth")

This could read args from the checkpoint, determine the correct model class, and instantiate it — without the user needing to remember or specify the variant.

Alternatively, storing an explicit model_size or model_class field in args at training time would make this even more robust than relying on filename parsing.

Use case

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions