Skip to content

feat: support rfdetr-keypoint-preview custom weights upload#507

Closed
mkaic wants to merge 1 commit into
mainfrom
kai/rfdetr-keypoint-upload
Closed

feat: support rfdetr-keypoint-preview custom weights upload#507
mkaic wants to merge 1 commit into
mainfrom
kai/rfdetr-keypoint-upload

Conversation

@mkaic

@mkaic mkaic commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Note

Code and PR description are LLM-written. Code has been reviewed and tested in staging by Kai

What

Enables uploading RF-DETR Keypoint Preview (rfdetr-keypoint-preview) models to the Roboflow platform through the existing custom-weights flows: version.deploy(), workspace.deploy_model(), and the roboflow upload_model CLI.

The platform side already supports this model type: the model registry (packages/shared/models/modelRegistry/rfdetrModels.js in roboflow) registers rfdetr-keypoint-preview as a keypoint-detection model, and the export job (train/export/rfdetr/export.py in roboflow-train, PR in flight) converts uploaded keypoint checkpoints — deriving keypoints_metadata.json from the checkpoint's args.num_keypoints_per_class, so the existing bundle format (weights.pt + class_names.txt) needs no changes. This PR removes the client-side gate that rejected the model type.

Changes (all in roboflow/util/model_processor.py)

  • Register the type: rfdetr-keypoint-previewRFDETRKeypointPreview in _RFDETR_MODEL_TYPE_TO_CLASS. The class ships in public rfdetr>=1.8.0, which is already the required minimum (RFDETR_MIN_VERSION) for the raw PyTorch-Lightning checkpoint path, so no dependency bump is needed.
  • Task mapping: task_of_model_type now maps model types containing keypoint to TASK_POSE (the type string spells the task out instead of using the -pose suffix token). This makes project-type validation accept keypoint-detection projects and reject others.
  • Checkpoint task detection: keypoint training checkpoints from rf-detr-internal carry args but no model_name, and their config sets segmentation_head=False alongside keypoint_head=True_detect_rfdetr_task previously misdetected them as detection. It now checks args.keypoint_head first. Checkpoints with model_name (RFDETRKeypointPreview) were already classified as pose; they are now accepted rather than rejected.
  • Variant grid check: added the keypoint-preview position-encoding grid (576 // 12 = 48, mirroring RFDETRKeypointPreviewConfig in rf-detr-internal/public rfdetr) to RFDETR_POSITIONAL_ENCODING_SIZE.

Cross-task mislabels stay rejected in both directions: a keypoint checkpoint uploaded as rfdetr-base and a detection checkpoint uploaded as rfdetr-keypoint-preview both raise TaskMismatchError before anything is uploaded.

Testing

  • New unit tests: task mapping, keypoint_head args fallback (dict + namespace), project-type validation accept/reject, PE-grid match, full packaging flow, and both cross-task rejection directions.
  • Full suite: 871 passed, 1 skipped locally.
  • Manually exercised packaging with a real torch.saved keypoint-style checkpoint (args including keypoint_head, num_keypoints_per_class, class_names): produces roboflow_deploy.zip with weights.pt + background-prefixed class_names.txt, no warnings; uploading the same checkpoint as rfdetr-nano is rejected with an actionable TaskMismatchError.

How to test an upload

roboflow upload_model -p <keypoint-project> -v <version> -t rfdetr-keypoint-preview -m <dir-with-checkpoint> -f checkpoint_best_total.pth

🤖 Generated with Claude Code

Enables uploading RF-DETR Keypoint Preview models through version.deploy(),
workspace.deploy_model(), and the upload_model CLI:

- register rfdetr-keypoint-preview in _RFDETR_MODEL_TYPE_TO_CLASS
  (RFDETRKeypointPreview ships in rfdetr>=1.8.0, the already-required
  minimum for the PTL-checkpoint path)
- map keypoint model types to TASK_POSE in task_of_model_type so project
  type validation accepts keypoint-detection projects
- detect keypoint checkpoints lacking model_name via args.keypoint_head
  (keypoint configs also carry segmentation_head=False, which previously
  misdetected them as detection)
- add the keypoint-preview position-encoding grid (576 // 12 = 48,
  mirroring RFDETRKeypointPreviewConfig) for the variant mislabel check

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mkaic

mkaic commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Note

This comment was NOT written by Kai. It was written by Kai's Claude and posted through Kai's GitHub account on this PR.

Closing as a duplicate of #496, which predates this PR and uses a more robust keypoint-checkpoint detection signal: args.num_keypoints_per_class works for checkpoints from both the public rfdetr package and rf-detr-internal, whereas this PR's args.keypoint_head only exists in rf-detr-internal's config — a keypoint checkpoint trained with the public package would have been misdetected as detection and rejected.

@mkaic mkaic closed this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant