Select memory frames for propagation (most recent + evenly spaced).
| 9425 | |
| 9426 | // Select memory frames for propagation (most recent + evenly spaced). |
| 9427 | static std::vector<int> sam3_select_memory_frames( |
| 9428 | const std::vector<sam3_memory_slot>& bank, |
| 9429 | int max_slots) { |
| 9430 | if ((int)bank.size() <= max_slots) { |
| 9431 | std::vector<int> all(bank.size()); |
| 9432 | for (int i = 0; i < (int)bank.size(); ++i) all[i] = i; |
| 9433 | return all; |
| 9434 | } |
| 9435 | std::vector<int> selected; |
| 9436 | selected.push_back(0); |
| 9437 | selected.push_back((int)bank.size() - 1); |
| 9438 | int remaining = max_slots - 2; |
| 9439 | if (remaining > 0) { |
| 9440 | float step = (float)(bank.size() - 2) / (remaining + 1); |
| 9441 | for (int i = 0; i < remaining; ++i) { |
| 9442 | int idx = 1 + (int)((i + 1) * step); |
| 9443 | idx = std::min(idx, (int)bank.size() - 2); |
| 9444 | selected.push_back(idx); |
| 9445 | } |
| 9446 | } |
| 9447 | std::sort(selected.begin(), selected.end()); |
| 9448 | selected.erase(std::unique(selected.begin(), selected.end()), selected.end()); |
| 9449 | return selected; |
| 9450 | } |
| 9451 | |
| 9452 | // Compute mask IoU between two binary masks. |
| 9453 | static float sam3_mask_iou(const uint8_t* a, const uint8_t* b, int n) { |
no outgoing calls
no test coverage detected