Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SAM decoder & output masks as png #418

Merged
merged 12 commits into from
Aug 17, 2023

Conversation

YavorGIvanov
Copy link
Collaborator

@YavorGIvanov YavorGIvanov commented Jul 26, 2023

With this additions, the SAM decoder and therefore the whole SAM ggml implementation for point input is almost finished. The things left are:

ЕDIT: Also there is a difference of part of the elements of some decoder results compared to the PyTorch model. The difference seems to be due to accumulating floating point error or due to the linear interpolation result numeric difference when preprocessing the image in the beggining.

@YavorGIvanov
Copy link
Collaborator Author

The initial version is finished as the GGML version outputs masks close to the ones the PyTorch model outputs for hardcoded point inputs. For the point harcoded in the code (414.375, 162.796875) and this image:

img

the PyTorch model outputs this mask:
0

and the GGML version outputs this:
mask_out_2

There are multiple things to be finished that I will begin doing now. Here are some with high priority:

  • Trace where the difference in output masks comes from. This will be done by going through the inference tensors step by step and comparing to the PyTorch version
  • Filter masks based on stability score and based on boxes, which touch crop boundaries
  • Optimize the GGML implementation by removing not needed ggml_cont operations/reshapes/transposes and so on
  • Add support for user input

@YavorGIvanov YavorGIvanov changed the title Add SAM decoder: model loading, transformer, hypernetwork & iou_prediction Add SAM decode & output masks as png Aug 17, 2023
@YavorGIvanov YavorGIvanov changed the title Add SAM decode & output masks as png Add SAM decoder & output masks as png Aug 17, 2023
Copy link
Owner

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦙

@ggerganov ggerganov merged commit d4b5295 into ggerganov:sam Aug 17, 2023
YavorGIvanov pushed a commit that referenced this pull request Aug 17, 2023
* 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
YavorGIvanov pushed a commit that referenced this pull request Aug 17, 2023
* 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
ggerganov added a commit that referenced this pull request Aug 18, 2023
* sam : image + prompt encoder, store embeddings

* sam : add the dense img pe in SAM state (#401)

* 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

* Multithread GGML_OP_ADD_REL_POS operation

* ggml : fix GGML_OP_NAME array

* Disable and comment out debug prints in SAM example

* Add README for the SAM example

* Calculate & filter based on stability score and calculate bounding box

ggml-ci

---------

Co-authored-by: Yavor Ivanov <[email protected]>
CCLDArjun pushed a commit to CCLDArjun/ggml that referenced this pull request Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants