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

Function main

tests/test_debug_encoder.cpp:64–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64int main(int argc, char** argv) {
65 if (argc < 4) {
66 fprintf(stderr, "Usage: %s <model.ggml> <ref_dir> <output_dir>\n", argv[0]);
67 fprintf(stderr, "\nref_dir: directory with Python reference tensors\n");
68 fprintf(stderr, "output_dir: where to dump C++ tensors\n");
69 return 1;
70 }
71
72 const std::string model_path = argv[1];
73 const std::string ref_dir = argv[2];
74 const std::string out_dir = argv[3];
75 ensure_dir(out_dir);
76
77 // ═══ Load model ═══
78 fprintf(stderr, "\n═══ Loading model ═══\n");
79 sam3_params params;
80 params.model_path = model_path;
81 params.use_gpu = false; // CPU for determinism
82 params.n_threads = 4;
83
84 auto model = sam3_load_model(params);
85 if (!model) {
86 fprintf(stderr, "Failed to load model\n");
87 return 1;
88 }
89
90 auto state = sam3_create_state(*model, params);
91 if (!state) {
92 fprintf(stderr, "Failed to create state\n");
93 return 1;
94 }
95
96 // ═══ Stage 1: Load Python-preprocessed image ═══
97 fprintf(stderr, "\n═══ Stage 1: Loading Python-preprocessed image ═══\n");
98 auto ref_img = load_ref_f32(ref_dir + "/preprocessed");
99 if (ref_img.data.empty()) {
100 fprintf(stderr, "Failed to load %s/preprocessed.bin\n", ref_dir.c_str());
101 return 1;
102 }
103 fprintf(stderr, " Loaded preprocessed image: shape=[");
104 for (size_t i = 0; i < ref_img.shape.size(); ++i) {
105 if (i > 0) fprintf(stderr, ",");
106 fprintf(stderr, "%d", ref_img.shape[i]);
107 }
108 fprintf(stderr, "] (%d elements)\n", ref_img.numel());
109
110 const int img_size = 1008;
111 const int expected_elems = 3 * img_size * img_size;
112 if (ref_img.numel() != expected_elems) {
113 fprintf(stderr, " ERROR: expected %d elements, got %d\n", expected_elems, ref_img.numel());
114 return 1;
115 }
116
117 // ═══ Encode image using Python-preprocessed data ═══
118 fprintf(stderr, "\n═══ Encoding image (from Python preprocessed data) ═══\n");
119 bool ok = sam3_encode_image_from_preprocessed(*state, *model, ref_img.data.data(), img_size);
120 if (!ok) {
121 fprintf(stderr, "sam3_encode_image_from_preprocessed failed!\n");

Callers

nothing calls this directly

Calls 11

ensure_dirFunction · 0.85
sam3_load_modelFunction · 0.85
sam3_create_stateFunction · 0.85
load_ref_f32Function · 0.85
sam3_dump_state_tensorFunction · 0.85
sam3_free_modelFunction · 0.85
compare_ggml_vs_nhwcFunction · 0.70
print_resultFunction · 0.70
compare_ggml_vs_nchwFunction · 0.70
numelMethod · 0.45

Tested by

no test coverage detected