You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggestion: apply separate threshold for each class_name when run prediction #1626
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)
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
@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
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 ^^.
Activity
Borda commentedon Oct 13, 2026
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
LeMinhNgan commentedon Oct 13, 2026
@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.1Step 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
confof each bouding box.Step 4. Visualize in histogram charts (I use minitab) each pair of
true-positiveandfalse-positive: X-axis stands for conf, Y-axis stands for counting --> we can see 2 partially-overlapped bell curvesStep 5. Find the optimal border between 2 distributions based on: acceptable
recallandprecision. In my study: D1 threshold is 0.34; D3 threshold is 0.255; D13 threshold is 0.405Briefly, 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
lthphuw commentedon Oct 14, 2026
Thanks @LeMinhNgan for the example, that makes sense for your case.
Proposal: accept
threshold: float | list[float]inpredict. A list must have lengthlen(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 ^^.