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

Function sam3_test_dump_phase7_from_ref_inputs

sam3.cpp:14054–14332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14052}
14053
14054bool sam3_test_dump_phase7_from_ref_inputs(const sam3_model& model,
14055 const std::string& case_ref_dir,
14056 const std::string& output_dir,
14057 int n_threads) {
14058 const auto& hp = model.hparams;
14059 const int D = hp.neck_dim;
14060 const int MD = hp.mem_out_dim;
14061 const int H = hp.feat_size();
14062 const int N = H * H;
14063 const int H1 = H * 2;
14064 const int H0 = H * 4;
14065 const int MASK_HW = H * 4;
14066 const int half_d = D / 2; // 128
14067
14068 std::map<std::string, std::string> meta;
14069 if (!sam3_load_kv_text_file(case_ref_dir + "/meta.txt", meta)) {
14070 return false;
14071 }
14072 const int num_slots = sam3_meta_get_int(meta, "num_slots", 0);
14073 if (num_slots <= 0) {
14074 fprintf(stderr, "%s: no memory slots in %s\n", __func__, case_ref_dir.c_str());
14075 return false;
14076 }
14077
14078 std::vector<float> neck_trk_0_nchw;
14079 std::vector<float> neck_trk_1_nchw;
14080 std::vector<float> neck_trk_2_nchw;
14081 if (!sam3_load_ref_f32_data(case_ref_dir + "/input_curr_neck_trk_0", neck_trk_0_nchw, D * H0 * H0) ||
14082 !sam3_load_ref_f32_data(case_ref_dir + "/input_curr_neck_trk_1", neck_trk_1_nchw, D * H1 * H1) ||
14083 !sam3_load_ref_f32_data(case_ref_dir + "/input_curr_neck_trk_2", neck_trk_2_nchw, D * H * H)) {
14084 return false;
14085 }
14086
14087 auto neck_trk_0 = sam3_reorder_nchw_to_ggml_dwh(neck_trk_0_nchw, D, H0, H0);
14088 auto neck_trk_1 = sam3_reorder_nchw_to_ggml_dwh(neck_trk_1_nchw, D, H1, H1);
14089 auto neck_trk_2 = sam3_reorder_nchw_to_ggml_dwh(neck_trk_2_nchw, D, H, H);
14090
14091 // ── Memory encoding per slot ────────────────────────────────────────
14092 std::vector<std::vector<float>> mem_slot_outputs(num_slots);
14093 std::vector<std::vector<float>> mem_slot_pes(num_slots);
14094 std::vector<std::vector<float>> obj_ptrs;
14095 std::vector<int> slot_spatial_tpos(num_slots);
14096 std::vector<int> slot_ptr_tpos(num_slots);
14097 bool ok = true;
14098
14099 for (int i = 0; i < num_slots; ++i) {
14100 std::vector<float> mask_logits_nchw;
14101 std::vector<float> sam_token;
14102 std::vector<float> obj_score;
14103 if (!sam3_load_ref_f32_data(case_ref_dir + "/input_mem_mask_logits_" + std::to_string(i),
14104 mask_logits_nchw, MASK_HW * MASK_HW) ||
14105 !sam3_load_ref_f32_data(case_ref_dir + "/input_mem_sam_token_" + std::to_string(i),
14106 sam_token, D) ||
14107 !sam3_load_ref_f32_data(case_ref_dir + "/input_mem_obj_score_" + std::to_string(i),
14108 obj_score, 1)) {
14109 return false;
14110 }
14111

Callers 1

mainFunction · 0.85

Calls 15

sam3_load_kv_text_fileFunction · 0.85
sam3_meta_get_intFunction · 0.85
sam3_load_ref_f32_dataFunction · 0.85
sam3_extract_obj_ptr_cpuFunction · 0.85
sam3_compute_axial_cisFunction · 0.85
sam3_build_sam_dec_graphFunction · 0.85
sam3_sinusoidal_pe_2dFunction · 0.85

Tested by 1

mainFunction · 0.68