samwell commited on
Commit
99bd982
·
verified ·
1 Parent(s): b32c7d0

Upload export_medsiglip.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. export_medsiglip.py +12 -16
export_medsiglip.py CHANGED
@@ -233,24 +233,20 @@ def export_to_onnx(model, config: Config, quantize: bool = True):
233
  onnx_path = config.output_dir / "laborview_medsiglip.onnx"
234
  onnx_quant_path = config.output_dir / "laborview_medsiglip_int8.onnx"
235
 
236
- print(f"Exporting to ONNX (legacy exporter): {onnx_path}")
237
 
238
- # Trace the model first
239
  with torch.no_grad():
240
- traced = torch.jit.trace(wrapper, dummy_input)
241
-
242
- # Export traced model to ONNX (fixed batch size for compatibility)
243
- torch.onnx.export(
244
- traced,
245
- dummy_input,
246
- str(onnx_path),
247
- export_params=True,
248
- opset_version=14, # Use stable opset version
249
- do_constant_folding=True,
250
- input_names=['pixel_values'],
251
- output_names=['seg_probs', 'plane_pred']
252
- # No dynamic_axes - use fixed batch size of 1 for mobile
253
- )
254
 
255
  # Verify ONNX model
256
  onnx_model = onnx.load(str(onnx_path))
 
233
  onnx_path = config.output_dir / "laborview_medsiglip.onnx"
234
  onnx_quant_path = config.output_dir / "laborview_medsiglip_int8.onnx"
235
 
236
+ print(f"Exporting to ONNX: {onnx_path}")
237
 
238
+ # Export directly without tracing (for new PyTorch exporter compatibility)
239
  with torch.no_grad():
240
+ torch.onnx.export(
241
+ wrapper,
242
+ (dummy_input,),
243
+ str(onnx_path),
244
+ export_params=True,
245
+ opset_version=14,
246
+ do_constant_folding=True,
247
+ input_names=['pixel_values'],
248
+ output_names=['seg_probs', 'plane_pred']
249
+ )
 
 
 
 
250
 
251
  # Verify ONNX model
252
  onnx_model = onnx.load(str(onnx_path))