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

Function sam3_test_dump_phase6_impl

sam3.cpp:13493–13697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13491}
13492
13493static bool sam3_test_dump_phase6_impl(const sam3_model& model,
13494 struct ggml_tensor* state_neck0,
13495 struct ggml_tensor* state_neck1,
13496 struct ggml_tensor* state_neck2,
13497 const std::vector<float>* neck0_data,
13498 const std::vector<float>* neck1_data,
13499 const std::vector<float>* neck2_data,
13500 const sam3_pvs_params& params,
13501 const std::string& output_dir,
13502 int n_threads) {
13503 const auto& hp = model.hparams;
13504 const int D = hp.sam_embed_dim;
13505 const int H = hp.n_img_embd();
13506 const int H1 = H * 2;
13507 const int H0 = H * 4;
13508
13509 const size_t buf_size = ggml_tensor_overhead() * 32768 + ggml_graph_overhead() * 2;
13510 struct ggml_init_params gparams = {
13511 /*.mem_size =*/buf_size,
13512 /*.mem_buffer =*/nullptr,
13513 /*.no_alloc =*/true,
13514 };
13515 struct ggml_context* ctx0 = ggml_init(gparams);
13516 if (!ctx0) {
13517 fprintf(stderr, "%s: failed to init compute context\n", __func__);
13518 return false;
13519 }
13520
13521 struct ggml_tensor* neck0 = state_neck0;
13522 struct ggml_tensor* neck1 = state_neck1;
13523 struct ggml_tensor* neck2 = state_neck2;
13524 if (neck0_data && neck1_data && neck2_data) {
13525 neck0 = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, D, H0, H0, 1);
13526 ggml_set_name(neck0, "sam_dec_feat_s0_input");
13527 ggml_set_input(neck0);
13528
13529 neck1 = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, D, H1, H1, 1);
13530 ggml_set_name(neck1, "sam_dec_feat_s1_input");
13531 ggml_set_input(neck1);
13532
13533 neck2 = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, D, H, H, 1);
13534 ggml_set_name(neck2, "sam_dec_feat_s2_input");
13535 ggml_set_input(neck2);
13536 }
13537
13538 if (!neck0 || !neck1 || !neck2) {
13539 fprintf(stderr, "%s: missing tracker feature inputs\n", __func__);
13540 ggml_free(ctx0);
13541 return false;
13542 }
13543
13544 auto pe_out = sam3_build_sam_pe(ctx0, params, D, H);
13545
13546 auto* no_mem = ggml_reshape_4d(ctx0, model.tensors.at("no_mem_embed"), D, 1, 1, 1);
13547 auto* image_feats = ggml_add(ctx0, neck2, no_mem);
13548 ggml_set_name(image_feats, "sam_dec_image_feats");
13549
13550 auto dec_out = sam3_build_sam_dec_graph(ctx0, model, image_feats,

Callers 2

sam3_test_dump_phase6Function · 0.85

Calls 8

sam3_build_sam_peFunction · 0.85
sam3_build_sam_dec_graphFunction · 0.85
sam3_populate_pe_cacheFunction · 0.85
sam3_pe_encode_coordFunction · 0.85
sam3_graph_computeFunction · 0.85
sam3_dump_tensor_to_pathFunction · 0.85
n_img_embdMethod · 0.80

Tested by

no test coverage detected