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

Function main

tests/test_mem_enc.cpp:13–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <string>
12
13int main(int argc, char ** argv) {
14 if (argc < 3) {
15 fprintf(stderr, "Usage: %s <model.ggml> <ref_dir> [x y]\n", argv[0]);
16 return 1;
17 }
18
19 const std::string model_path = argv[1];
20 const std::string ref_dir = std::string(argv[2]) + "/video_ref";
21 float px = argc > 4 ? atof(argv[3]) : 315.0f;
22 float py = argc > 4 ? atof(argv[4]) : 250.0f;
23
24 sam3_params params;
25 params.model_path = model_path;
26 params.use_gpu = false;
27 params.n_threads = 4;
28
29 auto model = sam3_load_model(params);
30 if (!model) { fprintf(stderr, "Failed to load model\n"); return 1; }
31
32 auto state = sam3_create_state(*model, params);
33 if (!state) { fprintf(stderr, "Failed to create state\n"); return 1; }
34
35 // Load llama image
36 auto image = sam3_load_image("../ggml/examples/sam/example.jpg");
37 if (image.data.empty()) { fprintf(stderr, "Failed to load image\n"); return 1; }
38
39 // Encode image
40 if (!sam3_encode_image(*state, *model, image)) {
41 fprintf(stderr, "Failed to encode image\n"); return 1;
42 }
43
44 // Create tracker
45 sam3_video_params vp;
46 vp.hotstart_delay = 0;
47 auto tracker = sam3_create_tracker(*model, vp);
48
49 // Add instance with point prompt → triggers PVS + memory encoding
50 sam3_pvs_params pvs;
51 pvs.pos_points.push_back({px, py});
52 pvs.multimask = false;
53
54 int inst_id = sam3_tracker_add_instance(*tracker, *state, *model, pvs);
55 fprintf(stderr, "Added instance %d\n", inst_id);
56
57 if (inst_id < 0) {
58 fprintf(stderr, "Failed to add instance\n");
59 return 1;
60 }
61
62 // ── Compare memory encoder outputs against Python reference ──────
63 fprintf(stderr, "\n═══ Memory Encoder Comparison ═══\n");
64
65 // Note: We're comparing C++ (stb_image decoded) vs Python (PIL decoded).
66 // The images differ slightly, so we expect some divergence.
67 // We check that the outputs are in the same range and structure.
68
69 // Check that Python reference exists
70 auto py_mem_feat = load_ref_f32(ref_dir + "/mem_enc_output_features");

Callers

nothing calls this directly

Calls 10

sam3_load_modelFunction · 0.85
sam3_create_stateFunction · 0.85
sam3_load_imageFunction · 0.85
sam3_encode_imageFunction · 0.85
sam3_create_trackerFunction · 0.85
load_ref_f32Function · 0.85
sam3_tracker_frame_indexFunction · 0.85
sam3_free_modelFunction · 0.85
numelMethod · 0.45

Tested by

no test coverage detected