Skip to content

Commit 03b4917

Browse files
author
Yavor Ivanov
committed
Add SAM decoder & output masks as png (#418)
* Add loading of decoder layers in Model * Multiply by hypernet_layer_cnt for ctx_size on model load * Add decoder layers to py conversion script * Fix wrong and reversed tensor sizes for decoder * Add decoder transformer implementation * Add decoder hypernet and iou prediction mlps * Add transpose convolution operation and unit test * Finish mask decoder and write the decoder output in the model state * Output masks to png after removing padding and upsampling to original size - Also filter based on the iou treshold - Additionally filtering based on the stability score and crop boxes should be done * Add stb image write in order to output masks from SAM * Add transpose convolution 2d name and symbol to ggml ops static arrays * Comment out debug print in transpose convolution test to fix compilation ggml-ci
1 parent ee26ea7 commit 03b4917

File tree

7 files changed

+3144
-151
lines changed

7 files changed

+3144
-151
lines changed

examples/sam/convert-pth-to-ggml.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@
7171
name = k
7272
shape = v.shape
7373

74-
# TODO: export only the Encoder -- after it works we will export the other stuff
75-
if name[:13] != "image_encoder" and \
76-
name[:14] != "prompt_encoder":
77-
continue
78-
7974
if name[:19] == "prompt_encoder.mask":
8075
continue
8176

@@ -104,7 +99,9 @@
10499
ftype_cur = 1
105100
if ftype == 0 or n_dims == 1 or \
106101
name == "image_encoder.pos_embed" or \
107-
name.startswith("prompt_encoder"):
102+
name.startswith("prompt_encoder") or \
103+
name.startswith("mask_decoder.iou_token") or \
104+
name.startswith("mask_decoder.mask_tokens"):
108105
print(" Converting to float32")
109106
data = data.astype(np.float32)
110107
ftype_cur = 0

examples/sam/main.cpp

Lines changed: 1031 additions & 143 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)