This commit is contained in:
2025-06-10 18:10:41 -04:00
commit 914de08b49
4 changed files with 208 additions and 0 deletions

28
extract_onnx.py Normal file
View File

@@ -0,0 +1,28 @@
import open_clip
#model_name = 'ViT-SO400M-14-SigLIP-384'
model_name = 'ViT-L-16-SigLIP2-512'
pretrained_name = 'webli'
model, _, preprocess = open_clip.create_model_and_transforms(model_name, pretrained=pretrained_name)
model.visual
sz_temp = (1,3,*model.visual.image_size)
import torch
r_in = torch.randn(sz_temp)
model.visual.eval()
with torch.no_grad():
torch_out = model.visual(r_in)
onnx_file_path = 'siglip2_512.onnx'
torch.onnx.export(model.visual,
r_in,
onnx_file_path,
export_params=True,
do_constant_folding=True,
input_names = ['input'],
output_names = ['output'])
#dynamic_axes={'input': {2 : 'height', 3 : 'width'}}