Skip to content

Make model path mandatory in export to ONNX. #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Microsoft.ML.Onnx/SaveOnnxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class SaveOnnxCommand : DataCommand.ImplBase<SaveOnnxCommand.Argum

public sealed class Arguments : DataCommand.ArgumentsBase
{
[Argument(ArgumentType.AtMostOnce, HelpText = "The path to write the output ONNX to.", SortOrder = 1)]
[Argument(ArgumentType.Required, HelpText = "The path to write the output ONNX to.", SortOrder = 1)]
public string Onnx;

[Argument(ArgumentType.AtMostOnce, HelpText = "The path to write the output JSON to.", SortOrder = 2)]
Expand Down Expand Up @@ -74,13 +74,18 @@ public SaveOnnxCommand(IHostEnvironment env, Arguments args)
: base(env, args, LoadName)
{
Host.CheckValue(args, nameof(args));
Host.CheckNonWhiteSpace(args.Onnx, nameof(args.Onnx));

Utils.CheckOptionalUserDirectory(args.Onnx, nameof(args.Onnx));
_outputModelPath = string.IsNullOrWhiteSpace(args.Onnx) ? null : args.Onnx;
_outputModelPath = args.Onnx;
_outputJsonModelPath = string.IsNullOrWhiteSpace(args.Json) ? null : args.Json;
if (args.Name == null && _outputModelPath != null)
if (args.Name == null)
_name = Path.GetFileNameWithoutExtension(_outputModelPath);
else if (!string.IsNullOrWhiteSpace(args.Name))
else
{
Host.CheckNonWhiteSpace(args.Name, nameof(args.Name));
_name = args.Name;
}

_loadPredictor = args.LoadPredictor;
_inputsToDrop = CreateDropMap(args.InputsToDropArray ?? args.InputsToDrop?.Split(','));
Expand Down Expand Up @@ -237,12 +242,9 @@ private void Run(IChannel ch)
}

var model = ctx.MakeModel();
if (_outputModelPath != null)
{
using (var file = Host.CreateOutputFile(_outputModelPath))
using (var stream = file.CreateWriteStream())
model.WriteTo(stream);
}
using (var file = Host.CreateOutputFile(_outputModelPath))
using (var stream = file.CreateWriteStream())
model.WriteTo(stream);

if (_outputJsonModelPath != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML/Models/OnnxConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed partial class OnnxConverter
/// path defined through the Json option.
///
/// This API supports the following arguments:
/// <see cref="Onnx"/> indicates the file to write the ONNX protocol buffer file to. This is optional.
/// <see cref="Onnx"/> indicates the file to write the ONNX protocol buffer file to. This is required.
/// <see cref="Json"/> indicates the file to write the JSON representation of the ONNX model. This is optional.
/// <see cref="Name"/> indicates the name property in the ONNX model. If left unspecified, it will
/// be the extension-less name of the file specified in the onnx indicates the protocol buffer file
Expand Down
5 changes: 2 additions & 3 deletions test/BaselineOutput/Common/EntryPoints/core_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2417,10 +2417,9 @@
"Name": "Onnx",
"Type": "String",
"Desc": "The path to write the output ONNX to.",
"Required": false,
"Required": true,
"SortOrder": 1.0,
"IsNullable": false,
"Default": null
"IsNullable": false
},
{
"Name": "Json",
Expand Down