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

Function main

tests/test_e2e_pvs.cpp:99–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99int main(int argc, char ** argv) {
100 if (argc < 3) {
101 fprintf(stderr, "Usage: %s <model.ggml> <ref_dir>\n", argv[0]);
102 fprintf(stderr, "\nref_dir: directory with Python reference tensors\n");
103 fprintf(stderr, " Should contain preprocessed.bin/.shape and phase6/cat_box/\n");
104 return 1;
105 }
106
107 const std::string model_path = argv[1];
108 const std::string ref_dir = argv[2];
109 const std::string cpp_out = ref_dir + "/cpp_out";
110 const std::string cpp_p6_out = ref_dir + "/cpp_out_phase6";
111 ensure_dir(cpp_out);
112 ensure_dir(cpp_p6_out);
113
114 // ═══ Load model ═══
115 fprintf(stderr, "\n═══ Loading model ═══\n");
116 sam3_params params;
117 params.model_path = model_path;
118 params.use_gpu = false;
119 params.n_threads = 4;
120
121 auto model = sam3_load_model(params);
122 if (!model) {
123 fprintf(stderr, "Failed to load model\n");
124 return 1;
125 }
126
127 auto state = sam3_create_state(*model, params);
128 if (!state) {
129 fprintf(stderr, "Failed to create state\n");
130 return 1;
131 }
132
133 // ═══ Stage 1: Load Python-preprocessed image ═══
134 fprintf(stderr, "\n═══ Stage 1: Loading Python-preprocessed image ═══\n");
135 auto ref_img = load_ref_f32(ref_dir + "/preprocessed");
136 if (ref_img.data.empty()) {
137 fprintf(stderr, "Failed to load %s/preprocessed.bin\n", ref_dir.c_str());
138 return 1;
139 }
140 fprintf(stderr, " Loaded preprocessed image: %d elements\n", ref_img.numel());
141
142 const int img_size = 1008;
143 bool ok = sam3_encode_image_from_preprocessed(*state, *model, ref_img.data.data(), img_size);
144 if (!ok) {
145 fprintf(stderr, "sam3_encode_image_from_preprocessed failed!\n");
146 return 1;
147 }
148 fprintf(stderr, " Image encoded successfully\n");
149
150 // ═══ Collect all metrics ═══
151 std::vector<metric_row> report;
152
153 // Helper: dump state tensor, compare with ref in NHWC layout
154 auto check_nhwc = [&](const char * stage, const char * tensor_name,
155 const char * ref_name, float atol) {
156 sam3_dump_state_tensor(*state, tensor_name, cpp_out + "/" + tensor_name);

Callers

nothing calls this directly

Calls 10

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
compute_full_metricsFunction · 0.70
numelMethod · 0.45

Tested by

no test coverage detected