MLP forward: N layers with ReLU (except last), optional sigmoid on last
| 10509 | |
| 10510 | // MLP forward: N layers with ReLU (except last), optional sigmoid on last |
| 10511 | static 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: |
no outgoing calls
no test coverage detected