@@ -70,14 +70,19 @@ def test_model(
70
70
model_rdf : str = typer .Argument (
71
71
..., help = "Path or URL to the model resource description file (rdf.yaml) or zipped model."
72
72
),
73
- weight_format : Optional [WeightFormatEnum ] = typer .Argument (None , help = "The weight format to use." ),
74
- devices : Optional [List [str ]] = typer .Argument (None , help = "Devices for running the model." ),
75
- decimal : int = typer .Argument (4 , help = "The test precision." ),
73
+ weight_format : Optional [WeightFormatEnum ] = typer .Option (None , help = "The weight format to use." ),
74
+ devices : Optional [List [str ]] = typer .Option (None , help = "Devices for running the model." ),
75
+ decimal : int = typer .Option (4 , help = "The test precision." ),
76
76
) -> int :
77
77
# this is a weird typer bug: default devices are empty tuple although they should be None
78
78
if len (devices ) == 0 :
79
79
devices = None
80
- summary = resource_tests .test_model (model_rdf , weight_format = weight_format , devices = devices , decimal = decimal )
80
+ summary = resource_tests .test_model (
81
+ model_rdf ,
82
+ weight_format = None if weight_format is None else weight_format .value ,
83
+ devices = devices ,
84
+ decimal = decimal ,
85
+ )
81
86
if summary ["error" ] is None :
82
87
print (f"Model test for { model_rdf } has passed." )
83
88
return 0
@@ -95,14 +100,16 @@ def test_resource(
95
100
rdf : str = typer .Argument (
96
101
..., help = "Path or URL to the resource description file (rdf.yaml) or zipped resource package."
97
102
),
98
- weight_format : Optional [WeightFormatEnum ] = typer .Argument (None , help = "(for model only) The weight format to use." ),
99
- devices : Optional [List [str ]] = typer .Argument (None , help = "(for model only) Devices for running the model." ),
100
- decimal : int = typer .Argument (4 , help = "(for model only) The test precision." ),
103
+ weight_format : Optional [WeightFormatEnum ] = typer .Option (None , help = "(for model only) The weight format to use." ),
104
+ devices : Optional [List [str ]] = typer .Option (None , help = "(for model only) Devices for running the model." ),
105
+ decimal : int = typer .Option (4 , help = "(for model only) The test precision." ),
101
106
) -> int :
102
107
# this is a weird typer bug: default devices are empty tuple although they should be None
103
108
if len (devices ) == 0 :
104
109
devices = None
105
- summary = resource_tests .test_resource (rdf , weight_format = weight_format , devices = devices , decimal = decimal )
110
+ summary = resource_tests .test_resource (
111
+ rdf , weight_format = None if weight_format is None else weight_format .value , devices = devices , decimal = decimal
112
+ )
106
113
if summary ["error" ] is None :
107
114
print (f"Resource test for { rdf } has passed." )
108
115
return 0
@@ -129,10 +136,10 @@ def predict_image(
129
136
# tiling: Optional[Union[str, bool]] = typer.Argument(
130
137
# None, help="Padding to apply in each dimension passed as json encoded string."
131
138
# ),
132
- padding : Optional [bool ] = typer .Argument (None , help = "Whether to pad the image to a size suited for the model." ),
133
- tiling : Optional [bool ] = typer .Argument (None , help = "Whether to run prediction in tiling mode." ),
134
- weight_format : Optional [str ] = typer .Argument (None , help = "The weight format to use." ),
135
- devices : Optional [List [str ]] = typer .Argument (None , help = "Devices for running the model." ),
139
+ padding : Optional [bool ] = typer .Option (None , help = "Whether to pad the image to a size suited for the model." ),
140
+ tiling : Optional [bool ] = typer .Option (None , help = "Whether to run prediction in tiling mode." ),
141
+ weight_format : Optional [WeightFormatEnum ] = typer .Option (None , help = "The weight format to use." ),
142
+ devices : Optional [List [str ]] = typer .Option (None , help = "Devices for running the model." ),
136
143
) -> int :
137
144
138
145
if isinstance (padding , str ):
@@ -145,7 +152,9 @@ def predict_image(
145
152
# this is a weird typer bug: default devices are empty tuple although they should be None
146
153
if len (devices ) == 0 :
147
154
devices = None
148
- prediction .predict_image (model_rdf , inputs , outputs , padding , tiling , weight_format , devices )
155
+ prediction .predict_image (
156
+ model_rdf , inputs , outputs , padding , tiling , None if weight_format is None else weight_format .value , devices
157
+ )
149
158
return 0
150
159
151
160
@@ -167,10 +176,10 @@ def predict_images(
167
176
# tiling: Optional[Union[str, bool]] = typer.Argument(
168
177
# None, help="Padding to apply in each dimension passed as json encoded string."
169
178
# ),
170
- padding : Optional [bool ] = typer .Argument (None , help = "Whether to pad the image to a size suited for the model." ),
171
- tiling : Optional [bool ] = typer .Argument (None , help = "Whether to run prediction in tiling mode." ),
172
- weight_format : Optional [str ] = typer .Argument (None , help = "The weight format to use." ),
173
- devices : Optional [List [str ]] = typer .Argument (None , help = "Devices for running the model." ),
179
+ padding : Optional [bool ] = typer .Option (None , help = "Whether to pad the image to a size suited for the model." ),
180
+ tiling : Optional [bool ] = typer .Option (None , help = "Whether to run prediction in tiling mode." ),
181
+ weight_format : Optional [WeightFormatEnum ] = typer .Option (None , help = "The weight format to use." ),
182
+ devices : Optional [List [str ]] = typer .Option (None , help = "Devices for running the model." ),
174
183
) -> int :
175
184
input_files = glob (input_pattern )
176
185
input_names = [os .path .split (infile )[1 ] for infile in input_files ]
@@ -194,7 +203,7 @@ def predict_images(
194
203
output_files ,
195
204
padding = padding ,
196
205
tiling = tiling ,
197
- weight_format = weight_format ,
206
+ weight_format = None if weight_format is None else weight_format . value ,
198
207
devices = devices ,
199
208
verbose = True ,
200
209
)
@@ -213,8 +222,8 @@ def convert_torch_weights_to_onnx(
213
222
),
214
223
output_path : Path = typer .Argument (..., help = "Where to save the onnx weights." ),
215
224
opset_version : Optional [int ] = typer .Argument (12 , help = "Onnx opset version." ),
216
- use_tracing : bool = typer .Argument (True , help = "Whether to use torch.jit tracing or scripting." ),
217
- verbose : bool = typer .Argument (True , help = "Verbosity" ),
225
+ use_tracing : bool = typer .Option (True , help = "Whether to use torch.jit tracing or scripting." ),
226
+ verbose : bool = typer .Option (True , help = "Verbosity" ),
218
227
) -> int :
219
228
return torch_converter .convert_weights_to_onnx (model_rdf , output_path , opset_version , use_tracing , verbose )
220
229
@@ -226,7 +235,7 @@ def convert_torch_weights_to_torchscript(
226
235
..., help = "Path to the model resource description file (rdf.yaml) or zipped model."
227
236
),
228
237
output_path : Path = typer .Argument (..., help = "Where to save the torchscript weights." ),
229
- use_tracing : bool = typer .Argument (True , help = "Whether to use torch.jit tracing or scripting." ),
238
+ use_tracing : bool = typer .Option (True , help = "Whether to use torch.jit tracing or scripting." ),
230
239
) -> int :
231
240
return torch_converter .convert_weights_to_pytorch_script (model_rdf , output_path , use_tracing )
232
241
0 commit comments