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

Function main

tests/test_preprocess_match.cpp:14–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include <string>
13
14int main(int argc, char** argv) {
15 if (argc < 4) {
16 fprintf(stderr, "Usage: %s <model.ggml> <image.jpg> <output_dir>\n", argv[0]);
17 return 1;
18 }
19
20 const std::string model_path = argv[1];
21 const std::string image_path = argv[2];
22 const std::string out_dir = argv[3];
23 ensure_dir(out_dir);
24
25 sam3_params params;
26 params.model_path = model_path;
27 params.use_gpu = false;
28 params.n_threads = 4;
29
30 auto model = sam3_load_model(params);
31 if (!model) { fprintf(stderr, "Failed to load model\n"); return 1; }
32
33 auto state = sam3_create_state(*model, params);
34 if (!state) { fprintf(stderr, "Failed to create state\n"); return 1; }
35
36 auto img = sam3_load_image(image_path);
37 if (img.data.empty()) { fprintf(stderr, "Failed to load image\n"); return 1; }
38
39 fprintf(stderr, "Encoding with C++ preprocessing...\n");
40 if (!sam3_encode_image(*state, *model, img)) {
41 fprintf(stderr, "Encoding failed\n");
42 return 1;
43 }
44
45 // Dump outputs
46 sam3_dump_state_tensor(*state, "vit_output", out_dir + "/vit_output");
47 for (int i = 0; i < 4; ++i) {
48 char name[32];
49 snprintf(name, sizeof(name), "neck_det_%d", i);
50 sam3_dump_state_tensor(*state, name, out_dir + "/" + name);
51 }
52
53 fprintf(stderr, "Done. Outputs in %s\n", out_dir.c_str());
54 state.reset();
55 sam3_free_model(*model);
56 return 0;
57}

Callers

nothing calls this directly

Calls 7

ensure_dirFunction · 0.85
sam3_load_modelFunction · 0.85
sam3_create_stateFunction · 0.85
sam3_load_imageFunction · 0.85
sam3_encode_imageFunction · 0.85
sam3_dump_state_tensorFunction · 0.85
sam3_free_modelFunction · 0.85

Tested by

no test coverage detected