@@ -28,7 +28,7 @@ public sealed class SaveOnnxCommand : DataCommand.ImplBase<SaveOnnxCommand.Argum
28
28
29
29
public sealed class Arguments : DataCommand . ArgumentsBase
30
30
{
31
- [ Argument ( ArgumentType . AtMostOnce , HelpText = "The path to write the output ONNX to." , SortOrder = 1 ) ]
31
+ [ Argument ( ArgumentType . Required , HelpText = "The path to write the output ONNX to." , SortOrder = 1 ) ]
32
32
public string Onnx ;
33
33
34
34
[ Argument ( ArgumentType . AtMostOnce , HelpText = "The path to write the output JSON to." , SortOrder = 2 ) ]
@@ -74,13 +74,18 @@ public SaveOnnxCommand(IHostEnvironment env, Arguments args)
74
74
: base ( env , args , LoadName )
75
75
{
76
76
Host . CheckValue ( args , nameof ( args ) ) ;
77
+ Host . CheckNonWhiteSpace ( args . Onnx , nameof ( args . Onnx ) ) ;
78
+
77
79
Utils . CheckOptionalUserDirectory ( args . Onnx , nameof ( args . Onnx ) ) ;
78
- _outputModelPath = string . IsNullOrWhiteSpace ( args . Onnx ) ? null : args . Onnx ;
80
+ _outputModelPath = args . Onnx ;
79
81
_outputJsonModelPath = string . IsNullOrWhiteSpace ( args . Json ) ? null : args . Json ;
80
- if ( args . Name == null && _outputModelPath != null )
82
+ if ( args . Name == null )
81
83
_name = Path . GetFileNameWithoutExtension ( _outputModelPath ) ;
82
- else if ( ! string . IsNullOrWhiteSpace ( args . Name ) )
84
+ else
85
+ {
86
+ Host . CheckNonWhiteSpace ( args . Name , nameof ( args . Name ) ) ;
83
87
_name = args . Name ;
88
+ }
84
89
85
90
_loadPredictor = args . LoadPredictor ;
86
91
_inputsToDrop = CreateDropMap ( args . InputsToDropArray ?? args . InputsToDrop ? . Split ( ',' ) ) ;
@@ -237,12 +242,9 @@ private void Run(IChannel ch)
237
242
}
238
243
239
244
var model = ctx . MakeModel ( ) ;
240
- if ( _outputModelPath != null )
241
- {
242
- using ( var file = Host . CreateOutputFile ( _outputModelPath ) )
243
- using ( var stream = file . CreateWriteStream ( ) )
244
- model . WriteTo ( stream ) ;
245
- }
245
+ using ( var file = Host . CreateOutputFile ( _outputModelPath ) )
246
+ using ( var stream = file . CreateWriteStream ( ) )
247
+ model . WriteTo ( stream ) ;
246
248
247
249
if ( _outputJsonModelPath != null )
248
250
{
0 commit comments