vietanhdev / samexporter

Export Segment Anything Models to ONNX
https://pypi.org/project/samexporter/
MIT License
239 stars 29 forks source link

Encoder only exports for vit_h #1

Open steven-cerebralfix opened 1 year ago

steven-cerebralfix commented 1 year ago

Great job on this, exactly what I was looking for!

However, when I attempt to export the encoder using:

python -m samexporter.export_encoder --checkpoint original_models/sam_vit_l_0b3195.pth --output output_models/sam_vit_l_0b3195.encoder/model.onnx --model-type vit_l --quantize-out output_models/sam_vit_l_0b3195.encoder.quant.onnx --use-preprocess

python -m samexporter.export_encoder --checkpoint original_models/sam_vit_b_01ec64.pth --output output_models/sam_vit_b_01ec64.encoder/model.onnx --model-type vit_b --quantize-out output_models/sam_vit_b_01ec64.encoder.quant.onnx --use-preprocess

Error Output: Loading model... Exporting onnx model to output_models/sam_vit_l_0b3195.encoder/model.onnx... Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Work\AR\samexporter\samexporter\export_encoder.py", line 178, in run_export( File "C:\Work\AR\samexporter\samexporter\export_encoder.py", line 157, in run_export with open(output, "wb") as f: FileNotFoundError: [Errno 2] No such file or directory: 'output_models/sam_vit_l_0b3195.encoder/model.onnx'

I see the flag on export_encoder.py, but I'm not sure how this should look for vit_l and vit_b?

Thanks, Steven.

cile98 commented 2 months ago

@steven-cerebralfix does this output_models/sam_vit_l_0b3195.encoder/ directory exist? It might be that you're just providing a path that doesn't exist, thus the exception. I had no problems exporting the vit_b encoder