MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / sam_prompt_encode_pe_encoding

Function sam_prompt_encode_pe_encoding

external/ggml/examples/sam/sam.cpp:1417–1440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1415};
1416
1417struct ggml_tensor * sam_prompt_encode_pe_encoding(
1418 const sam_encoder_prompt & enc,
1419 struct ggml_context * ctx0,
1420 struct ggml_cgraph * gf,
1421 struct ggml_tensor * coords) {
1422
1423 auto * cur = ggml_mul_mat(ctx0, ggml_cont(ctx0, ggml_transpose(ctx0, enc.pe)), coords);
1424 cur = ggml_scale(ctx0, cur, float(2.0*M_PI));
1425
1426 // concat
1427 // ref: https://github.com/facebookresearch/segment-anything/blob/main/segment_anything/modeling/prompt_encoder.py#L192
1428 {
1429 struct ggml_tensor * t_sin = ggml_map_custom1(ctx0, cur, ggml_sam_sin, GGML_N_TASKS_MAX, NULL);
1430 struct ggml_tensor * t_cos = ggml_map_custom1(ctx0, cur, ggml_sam_cos, GGML_N_TASKS_MAX, NULL);
1431
1432 cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, t_sin->ne[0] + t_cos->ne[0], cur->ne[1]);
1433
1434 ggml_build_forward_expand(gf, ggml_cpy(ctx0, t_sin, ggml_view_2d(ctx0, cur, t_sin->ne[0], t_sin->ne[1], cur->nb[1], 0)));
1435 ggml_build_forward_expand(gf, ggml_cpy(ctx0, t_cos, ggml_view_2d(ctx0, cur, t_sin->ne[0], t_sin->ne[1], cur->nb[1], t_sin->nb[1])));
1436
1437 }
1438 return cur;
1439
1440}
1441// encode a prompt
1442//
1443// - points

Callers 1

sam_encode_promptFunction · 0.85

Calls 9

ggml_mul_matFunction · 0.85
ggml_contFunction · 0.85
ggml_transposeFunction · 0.85
ggml_scaleFunction · 0.85
ggml_map_custom1Function · 0.85
ggml_new_tensor_2dFunction · 0.85
ggml_cpyFunction · 0.85
ggml_view_2dFunction · 0.85

Tested by

no test coverage detected