| 1165 | } |
| 1166 | |
| 1167 | struct 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 | |
| 1190 | struct ggml_cgraph * sam_encode_image( |
| 1191 | const sam_model & model, |
no test coverage detected