MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / main

Function main

tests/test_visual_only.cpp:4–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <cstdio>
3
4int main(int argc, char** argv) {
5 if (argc < 2) {
6 fprintf(stderr, "Usage: %s <visual-only-model.ggml> [image.jpg]\n", argv[0]);
7 return 1;
8 }
9
10 sam3_params params;
11 params.model_path = argv[1];
12 params.n_threads = 4;
13
14 // 1. Load visual-only model
15 fprintf(stderr, "=== Test 1: Load visual-only model ===\n");
16 auto model = sam3_load_model(params);
17 if (!model) {
18 fprintf(stderr, "FAIL: failed to load model\n");
19 return 1;
20 }
21 fprintf(stderr, "PASS: model loaded\n");
22
23 // 2. Verify visual_only flag
24 fprintf(stderr, "\n=== Test 2: sam3_is_visual_only ===\n");
25 if (!sam3_is_visual_only(*model)) {
26 fprintf(stderr, "FAIL: expected visual_only=true\n");
27 return 1;
28 }
29 fprintf(stderr, "PASS: sam3_is_visual_only() = true\n");
30
31 // 3. PCS should return empty result (no crash)
32 fprintf(stderr, "\n=== Test 3: PCS guard ===\n");
33 auto state = sam3_create_state(*model, params);
34 if (!state) {
35 fprintf(stderr, "FAIL: create_state\n");
36 return 1;
37 }
38 sam3_pcs_params pcs;
39 pcs.text_prompt = "cat";
40 auto r = sam3_segment_pcs(*state, *model, pcs);
41 if (!r.detections.empty()) {
42 fprintf(stderr, "FAIL: PCS should return empty on visual-only\n");
43 return 1;
44 }
45 fprintf(stderr, "PASS: PCS returns empty on visual-only model\n");
46
47 // 4. If image provided, test PVS + visual tracking
48 if (argc >= 3) {
49 fprintf(stderr, "\n=== Test 4: PVS on visual-only model ===\n");
50 auto img = sam3_load_image(argv[2]);
51 if (img.data.empty()) {
52 fprintf(stderr, "FAIL: failed to load image '%s'\n", argv[2]);
53 return 1;
54 }
55 if (!sam3_encode_image(*state, *model, img)) {
56 fprintf(stderr, "FAIL: encode_image\n");
57 return 1;
58 }
59
60 // PVS with center point
61 sam3_pvs_params pvs;

Callers

nothing calls this directly

Calls 11

sam3_load_modelFunction · 0.85
sam3_is_visual_onlyFunction · 0.85
sam3_create_stateFunction · 0.85
sam3_segment_pcsFunction · 0.85
sam3_load_imageFunction · 0.85
sam3_encode_imageFunction · 0.85
sam3_segment_pvsFunction · 0.85
sam3_propagate_frameFunction · 0.85
sam3_track_frameFunction · 0.85

Tested by

no test coverage detected