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

Function sam3_mlp_forward

sam3.cpp:10511–10529  ·  view source on GitHub ↗

MLP forward: N layers with ReLU (except last), optional sigmoid on last

Source from the content-addressed store, hash-verified

10509
10510// MLP forward: N layers with ReLU (except last), optional sigmoid on last
10511static struct ggml_tensor* sam3_mlp_forward(
10512 struct ggml_context* ctx,
10513 struct ggml_tensor* x,
10514 struct ggml_tensor* const* weights,
10515 struct ggml_tensor* const* biases,
10516 int n_layers,
10517 bool sigmoid_output = false) {
10518 for (int i = 0; i < n_layers; ++i) {
10519 x = ggml_mul_mat(ctx, weights[i], x);
10520 x = ggml_add(ctx, x, biases[i]);
10521 if (i < n_layers - 1) {
10522 x = ggml_relu(ctx, x);
10523 }
10524 }
10525 if (sigmoid_output) {
10526 x = ggml_sigmoid(ctx, x);
10527 }
10528 return x;
10529}
10530
10531// Full SAM mask decoder graph
10532// Inputs:

Callers 1

sam3_build_sam_dec_graphFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected