| 15 | #include <vector> |
| 16 | |
| 17 | static float mask_iou(const sam3_mask& a, const sam3_mask& b) { |
| 18 | if (a.width != b.width || a.height != b.height) return 0.0f; |
| 19 | int inter = 0, uni = 0; |
| 20 | for (int i = 0; i < (int)a.data.size(); ++i) { |
| 21 | bool fa = a.data[i] > 127; |
| 22 | bool fb = b.data[i] > 127; |
| 23 | if (fa && fb) inter++; |
| 24 | if (fa || fb) uni++; |
| 25 | } |
| 26 | return uni > 0 ? (float)inter / uni : 1.0f; |
| 27 | } |
| 28 | |
| 29 | static int count_fg(const sam3_mask& m) { |
| 30 | int n = 0; |