| 106 | } |
| 107 | |
| 108 | int main(int argc, char ** argv) { |
| 109 | if (argc < 3) { |
| 110 | fprintf(stderr, "Usage: %s <model.ggml> <ref_dir>\n", argv[0]); |
| 111 | fprintf(stderr, "\nref_dir should contain pcs_ref/ from dump_e2e_pcs.py\n"); |
| 112 | return 1; |
| 113 | } |
| 114 | |
| 115 | const std::string model_path = argv[1]; |
| 116 | const std::string ref_dir = std::string(argv[2]) + "/pcs_ref"; |
| 117 | const std::string cpp_out = std::string(argv[2]) + "/pcs_cpp"; |
| 118 | ensure_dir(cpp_out); |
| 119 | |
| 120 | // ═══ Load model ═══ |
| 121 | fprintf(stderr, "\n═══ Loading model ═══\n"); |
| 122 | sam3_params params; |
| 123 | params.model_path = model_path; |
| 124 | params.use_gpu = false; |
| 125 | params.n_threads = 4; |
| 126 | |
| 127 | auto model = sam3_load_model(params); |
| 128 | if (!model) { |
| 129 | fprintf(stderr, "Failed to load model\n"); |
| 130 | return 1; |
| 131 | } |
| 132 | |
| 133 | auto state = sam3_create_state(*model, params); |
| 134 | if (!state) { |
| 135 | fprintf(stderr, "Failed to create state\n"); |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | // ═══ Stage 1: Load Python-preprocessed image ═══ |
| 140 | fprintf(stderr, "\n═══ Stage 1: Loading Python-preprocessed image ═══\n"); |
| 141 | auto ref_img = load_ref_f32(ref_dir + "/preprocessed_chw"); |
| 142 | if (ref_img.data.empty()) { |
| 143 | fprintf(stderr, "Failed to load %s/preprocessed_chw.bin\n", ref_dir.c_str()); |
| 144 | return 1; |
| 145 | } |
| 146 | fprintf(stderr, " Loaded preprocessed image: %d elements\n", ref_img.numel()); |
| 147 | |
| 148 | const int img_size = 1008; |
| 149 | bool ok = sam3_encode_image_from_preprocessed(*state, *model, ref_img.data.data(), img_size); |
| 150 | if (!ok) { |
| 151 | fprintf(stderr, "sam3_encode_image_from_preprocessed failed!\n"); |
| 152 | return 1; |
| 153 | } |
| 154 | fprintf(stderr, " Image encoded successfully\n"); |
| 155 | |
| 156 | // ═══ Stage 2: Dump ViT block outputs (from state debug tensors) ═══ |
| 157 | fprintf(stderr, "\n═══ Stage 2: ViT Backbone ═══\n"); |
| 158 | std::vector<metric_row> report; |
| 159 | |
| 160 | // ViT block outputs are stored in state during encoding |
| 161 | for (int i : {0, 7, 15, 23, 31}) { |
| 162 | char cpp_name[64], ref_name[64]; |
| 163 | snprintf(cpp_name, sizeof(cpp_name), "dbg_block_%d_out", i); |
| 164 | snprintf(ref_name, sizeof(ref_name), "vit_block_%02d_out", i); |
| 165 |
nothing calls this directly
no test coverage detected