Skip to content

Suggestion: apply separate threshold for each class_name when run prediction #1626

Open

Description

@LeMinhNgan

Search before asking

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

Description

Hi,
In fact, after training we don't get the same recall rate for all objects. Therefore in prediction, we logically don't apply the same threshold for all classes. At this stage we use a trick: use very low threshold to get all probability and filter them later with their conf values.
I'd like to do it directly when run model.predict by accepting threshold in list threshold: float | list[float]. If the threshold comes as a float, apply this threshold for all class IDs; else if threshold comes as a list and len(threshold)==len(class_names) we apply separate threshold to each class ID accordingly in order
Example:
Either
detections= model.predict(image, threshold= 0.45, device= device)
or
detections= model.predict(image, threshold=[0.40, 055, 0.45], device= device)

Use case

No response

Additional

No response

Are you willing to submit a PR?

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

Activity

  1. Borda commented on Oct 13, 2026

    @Borda
    Member

    That could solve. Could you share specific examples of how we could benefit from this multi-threshold schema? IN theory, I see the potential, but it would be better if we could solidify it and also later have a cookbook showcase the benefit

  2. LeMinhNgan commented on Oct 13, 2026

    @LeMinhNgan
    ContributorAuthor

    @Borda,
    I can share the way I analyze. You can repeat with hard dataset
    In my case that you can see in the attached histogram charts
    Step 1. Train dataset with objects D1, D3 and D13 --> get the best checkpoint
    Step 2. Run prediction on a number of test images with threshold=0.1
    Step 3. Manually check these images and returned labels and collect information of each detected: true-positive (D1, D3, D13), false-positive (D^1, D^3, D^13) and conf of each bouding box.
    Step 4. Visualize in histogram charts (I use minitab) each pair of true-positive and false-positive: X-axis stands for conf, Y-axis stands for counting --> we can see 2 partially-overlapped bell curves
    Step 5. Find the optimal border between 2 distributions based on: acceptable recall and precision. In my study: D1 threshold is 0.34; D3 threshold is 0.255; D13 threshold is 0.405

    Briefly, optimal thresholds of D1, D3 and D13 objects are different. Hope my explanation is clear enough. Let me know if you can not see the attache histogram charts

    Image Image Image
  3. lthphuw commented on Oct 14, 2026

    @lthphuw
    Contributor

    Thanks @LeMinhNgan for the example, that makes sense for your case.

    Proposal: accept threshold: float | list[float] in predict. A list must have length len(model.class_names), and each detection is kept when its score exceeds the threshold for its class. The float form is unchanged.

    @Borda, if this design works for you, could you please assign the issue to me ^^.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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