Upload export_medsiglip.py with huggingface_hub
Browse files- 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
|
| 237 |
|
| 238 |
-
#
|
| 239 |
with torch.no_grad():
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 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))
|