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

Function sam_layer_norm_2d

external/ggml/examples/sam/sam.cpp:1167–1188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1165}
1166
1167struct ggml_tensor* sam_layer_norm_2d(
1168 struct ggml_context * ctx0,
1169 struct ggml_tensor * layer,
1170 int n_channels,
1171 struct ggml_tensor * w,
1172 struct ggml_tensor * b,
1173 float eps) {
1174 // LayerNorm2d
1175 // normalize along channel dimmension
1176 // TODO: better implementation
1177 layer = ggml_permute(ctx0,
1178 ggml_norm(ctx0, ggml_cont(ctx0, ggml_permute(ctx0, layer, 1, 2, 0, 3)), eps),
1179 2, 0, 1, 3);
1180
1181 layer = ggml_add(ctx0,
1182 ggml_mul(ctx0,
1183 ggml_repeat(ctx0, ggml_reshape_3d(ctx0, w, 1, 1, n_channels), layer),
1184 layer),
1185 ggml_repeat(ctx0, ggml_reshape_3d(ctx0, b, 1, 1, n_channels), layer));
1186
1187 return layer;
1188}
1189
1190struct ggml_cgraph * sam_encode_image(
1191 const sam_model & model,

Callers 2

sam_encode_imageFunction · 0.85
sam_decode_maskFunction · 0.85

Calls 7

ggml_permuteFunction · 0.85
ggml_normFunction · 0.85
ggml_contFunction · 0.85
ggml_addFunction · 0.85
ggml_mulFunction · 0.85
ggml_repeatFunction · 0.85
ggml_reshape_3dFunction · 0.85

Tested by

no test coverage detected