@@ -80,11 +80,13 @@ class ExportMixin:
8080 def to_torch (
8181 self ,
8282 export_root : Path | str ,
83+ model_file_name : str = "model" ,
8384 ) -> Path :
8485 """Export model to PyTorch format.
8586
8687 Args:
8788 export_root (Path | str): Path to the output folder
89+ model_file_name (str): Name of the exported model
8890
8991 Returns:
9092 Path: Path to the exported PyTorch model (.pt file)
@@ -99,7 +101,7 @@ def to_torch(
99101 PosixPath('./exports/weights/torch/model.pt')
100102 """
101103 export_root = _create_export_root (export_root , ExportType .TORCH )
102- pt_model_path = export_root / "model .pt"
104+ pt_model_path = export_root / ( model_file_name + " .pt")
103105 torch .save (
104106 obj = {"model" : self },
105107 f = pt_model_path ,
@@ -109,12 +111,14 @@ def to_torch(
109111 def to_onnx (
110112 self ,
111113 export_root : Path | str ,
114+ model_file_name : str = "model" ,
112115 input_size : tuple [int , int ] | None = None ,
113116 ) -> Path :
114117 """Export model to ONNX format.
115118
116119 Args:
117120 export_root (Path | str): Path to the output folder
121+ model_file_name (str): Name of the exported model.
118122 input_size (tuple[int, int] | None): Input image dimensions (height, width).
119123 If ``None``, uses dynamic input shape. Defaults to ``None``
120124
@@ -143,7 +147,7 @@ def to_onnx(
143147 if input_size
144148 else {"input" : {0 : "batch_size" , 2 : "height" , 3 : "weight" }, "output" : {0 : "batch_size" }}
145149 )
146- onnx_path = export_root / "model .onnx"
150+ onnx_path = export_root / ( model_file_name + " .onnx")
147151 # apply pass through the model to get the output names
148152 assert isinstance (self , LightningModule ) # mypy
149153 output_names = [name for name , value in self .eval ()(input_shape )._asdict ().items () if value is not None ]
@@ -162,6 +166,7 @@ def to_onnx(
162166 def to_openvino (
163167 self ,
164168 export_root : Path | str ,
169+ model_file_name : str = "model" ,
165170 input_size : tuple [int , int ] | None = None ,
166171 compression_type : CompressionType | None = None ,
167172 datamodule : AnomalibDataModule | None = None ,
@@ -173,6 +178,7 @@ def to_openvino(
173178
174179 Args:
175180 export_root (Path | str): Path to the output folder
181+ model_file_name (str): Name of the exported model
176182 input_size (tuple[int, int] | None): Input image dimensions (height, width).
177183 If ``None``, uses dynamic input shape. Defaults to ``None``
178184 compression_type (CompressionType | None): Type of compression to apply.
@@ -218,9 +224,9 @@ def to_openvino(
218224 import openvino as ov
219225
220226 with TemporaryDirectory () as onnx_directory :
221- model_path = self .to_onnx (onnx_directory , input_size )
227+ model_path = self .to_onnx (onnx_directory , model_file_name , input_size )
222228 export_root = _create_export_root (export_root , ExportType .OPENVINO )
223- ov_model_path = export_root / "model .xml"
229+ ov_model_path = export_root / ( model_file_name + " .xml")
224230 ov_args = {} if ov_args is None else ov_args
225231
226232 model = ov .convert_model (model_path , ** ov_args )
0 commit comments