facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.87k stars 5.66k forks source link

vit_b and vit_h models have same size when quantized exported to onnx #756

Closed kevinshen1101 closed 5 months ago

kevinshen1101 commented 5 months ago

Hello, I followed the scripts to quantize and export the various type SAM models into onnx. One thing I noticed was that after exporting, both the quantized vit_b and quantized vit_h onnx models have the same size (8.3M). Is this expected or do I have some error on my end? My (limited) understanding is that the larger parameter vit_h model should take up more storage space.

heyoeyo commented 5 months ago

Only the prompt encoder + mask decoder are exported in this case, and all variants of the SAM model have the same sized decoding model (though the weights have different values). But your intuition is correct, it's the image encoder (vit) that varies in size between the models, it just isn't part of the onnx export. If they were exported in a quantized format, they'd be on the order of 150MB-1000MB depending on the model size.

kevinshen1101 commented 5 months ago

Got it, that makes sense, thanks!