Skip to content
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

Export to ONNX and cross-platform command-line tool to script ML.NET training and inference #248

Merged
merged 29 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1b78603
Export to ONNX and Maml cross-platform executable
codemzs May 28, 2018
1508cd4
misc.
codemzs May 29, 2018
c6763f3
PR feedback.
codemzs May 30, 2018
b04ef49
PR feedback.
codemzs May 30, 2018
eaa8e3a
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs May 30, 2018
de02e1e
resolve merge issues.
codemzs May 30, 2018
6f4434e
cleanup.
codemzs May 30, 2018
6c97416
cleanup.
codemzs May 30, 2018
534fcd1
PR feedback.
codemzs May 30, 2018
caebed0
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs May 30, 2018
692b526
update test baselines.
codemzs May 30, 2018
6c92033
cleanup.
codemzs May 30, 2018
e466157
cleanup.
codemzs May 30, 2018
5a04795
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs May 31, 2018
8ef9b3f
PR feedback.
codemzs May 31, 2018
64cdb80
PR feedback.
codemzs May 31, 2018
3276dd3
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs Jun 1, 2018
c6bc1c6
PR feedback.
codemzs Jun 1, 2018
17a738a
update baselines and regenerate csharp APIs.
codemzs Jun 1, 2018
5090d24
Add link to the commit in ONNX MD file.
codemzs Jun 1, 2018
4cfed38
PR feedback.
codemzs Jun 1, 2018
0a13ad7
cleanup.
codemzs Jun 1, 2018
5bea824
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs Jun 4, 2018
2ab729f
Add missing attributes to ONNX model.
codemzs Jun 4, 2018
faf528c
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs Jun 5, 2018
3dfd81f
cleanup.
codemzs Jun 5, 2018
1865825
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs Jun 6, 2018
3562331
add more commands.
codemzs Jun 6, 2018
d20f1a4
cleanup.
codemzs Jun 6, 2018
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
24 changes: 17 additions & 7 deletions Microsoft.ML.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Core", "src\Microsoft.ML.Core\Microsoft.ML.Core.csproj", "{A6CA6CC6-5D7C-4D7F-A0F5-35E14B383B0A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{09EADF06-BE25-4228-AB53-95AE3E15B530}"
ProjectSection(SolutionItems) = preProject
src\Microsoft.ML.Commands\Microsoft.ML.Commands.csproj = src\Microsoft.ML.Commands\Microsoft.ML.Commands.csproj
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{AED9C836-31E3-4F3F-8ABC-929555D3F3C4}"
EndProject
Expand All @@ -30,8 +33,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.KMeansClusteri
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.PCA", "src\Microsoft.ML.PCA\Microsoft.ML.PCA.csproj", "{58E06735-1129-4DD5-86E0-6BBFF049AAD9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Maml", "src\Microsoft.ML.Maml\Microsoft.ML.Maml.csproj", "{D956E291-F6E5-4474-9023-91793F45ABEB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Api", "src\Microsoft.ML.Api\Microsoft.ML.Api.csproj", "{2F636A2C-062C-49F4-85F3-60DCADAB6A43}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Tests", "test\Microsoft.ML.Tests\Microsoft.ML.Tests.csproj", "{64BC22D3-1E76-41EF-94D8-C79E471FF2DD}"
Expand Down Expand Up @@ -104,6 +105,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.ML.Parquet", "Mic
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Benchmarks", "test\Microsoft.ML.Benchmarks\Microsoft.ML.Benchmarks.csproj", "{7A9DB75F-2CA5-4184-9EF5-1F17EB39483F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Maml", "src\Microsoft.ML.Maml\Microsoft.ML.Maml.csproj", "{64F40A0D-D4C2-4AA7-8470-E9CC437827E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Console", "src\Microsoft.ML.Console\Microsoft.ML.Console.csproj", "{362A98CF-FBF7-4EBB-A11B-990BBF845B15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -158,10 +163,6 @@ Global
{58E06735-1129-4DD5-86E0-6BBFF049AAD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58E06735-1129-4DD5-86E0-6BBFF049AAD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58E06735-1129-4DD5-86E0-6BBFF049AAD9}.Release|Any CPU.Build.0 = Release|Any CPU
{D956E291-F6E5-4474-9023-91793F45ABEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D956E291-F6E5-4474-9023-91793F45ABEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D956E291-F6E5-4474-9023-91793F45ABEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D956E291-F6E5-4474-9023-91793F45ABEB}.Release|Any CPU.Build.0 = Release|Any CPU
{2F636A2C-062C-49F4-85F3-60DCADAB6A43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F636A2C-062C-49F4-85F3-60DCADAB6A43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F636A2C-062C-49F4-85F3-60DCADAB6A43}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -202,6 +203,14 @@ Global
{7A9DB75F-2CA5-4184-9EF5-1F17EB39483F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A9DB75F-2CA5-4184-9EF5-1F17EB39483F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A9DB75F-2CA5-4184-9EF5-1F17EB39483F}.Release|Any CPU.Build.0 = Release|Any CPU
{64F40A0D-D4C2-4AA7-8470-E9CC437827E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64F40A0D-D4C2-4AA7-8470-E9CC437827E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64F40A0D-D4C2-4AA7-8470-E9CC437827E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64F40A0D-D4C2-4AA7-8470-E9CC437827E4}.Release|Any CPU.Build.0 = Release|Any CPU
{362A98CF-FBF7-4EBB-A11B-990BBF845B15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{362A98CF-FBF7-4EBB-A11B-990BBF845B15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{362A98CF-FBF7-4EBB-A11B-990BBF845B15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{362A98CF-FBF7-4EBB-A11B-990BBF845B15}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -219,7 +228,6 @@ Global
{7288C084-11C0-43BE-AC7F-45DCFEAEEBF6} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{F1CAE3AB-4F86-4BC0-BBA8-C4A58E7E8A4A} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{58E06735-1129-4DD5-86E0-6BBFF049AAD9} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{D956E291-F6E5-4474-9023-91793F45ABEB} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{2F636A2C-062C-49F4-85F3-60DCADAB6A43} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{64BC22D3-1E76-41EF-94D8-C79E471FF2DD} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
{FDA2FD2C-A708-43AC-A941-4D941B0853BF} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
Expand All @@ -236,6 +244,8 @@ Global
{DEC8F776-49F7-4D87-836C-FE4DC057D08C} = {D3D38B03-B557-484D-8348-8BADEE4DF592}
{6C95FC87-F5F2-4EEF-BB97-567F2F5DD141} = {D3D38B03-B557-484D-8348-8BADEE4DF592}
{7A9DB75F-2CA5-4184-9EF5-1F17EB39483F} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
{64F40A0D-D4C2-4AA7-8470-E9CC437827E4} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{362A98CF-FBF7-4EBB-A11B-990BBF845B15} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {41165AF1-35BB-4832-A189-73060F82B01D}
Expand Down
21 changes: 21 additions & 0 deletions src/Microsoft.ML.Console/Console.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.ML.Runtime.Tools.Console
{
public static class Console
{
public static int Main(string[] args)
{
string all = string.Join(" ", args);
return Maml.MainAll(all);
}

public static unsafe int MainRaw(char* psz)
{
string args = new string(psz);
return Maml.MainAll(args);
}
Copy link
Contributor

@TomFinley TomFinley May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is MainRaw on char* a thing? I've not quite seen this pattern before. What is this for? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is present in MAML.cs at line 38. I'm not sure why it was written but I assume this is probably an entry point for some scenario. Should we remove it?


In reply to: 192227331 [](ancestors = 192227331)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, these came from MAML.cs. I see that now.

The sole purpose of this DLL is to enable invocations of dotnet to work. That's the only reason it exists. So drop the char*

Also: at the risk of stating the obvious, let's not copy functions of assemblies we are referencing, let's call them.

The only thing I'd like to see in this class is public static int Main(string[] args) => Maml.Main(args);, and that is it.


In reply to: 192462330 [](ancestors = 192462330,192227331)

}
}
17 changes: 17 additions & 0 deletions src/Microsoft.ML.Console/Microsoft.ML.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>CORECLR</DefineConstants>
<IncludeInPackage>Microsoft.ML</IncludeInPackage>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<StartupObject>Microsoft.ML.Runtime.Tools.Console.Console</StartupObject>
Copy link
Contributor

@TomFinley TomFinley May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Runtime.Tools.Console.Console [](start = 1, length = 73)

This would be the actual thing we'd do dotnet on, might be nice to name the build artifact something like mml.dll or something, just to keep usage here simple. #Closed

Copy link
Member Author

@codemzs codemzs May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Startup object contains the static entrypoint function for the standalone executable. You would do on Microsoft.ML.Runtime.Tools.Console.dll, are you saying we should generate mml.dll instead?


In reply to: 192227732 [](ancestors = 192227732)

Copy link
Contributor

@TomFinley TomFinley May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in things intended to be invoked from the command line I'd prefer something shorter. We're coming up with a replacement for maml, I might prefer either mml or msml or something, at least as preliminary names. Microsoft.ML.Runtime.Tools.Console.dll doesn't exactly roll off the tongue. :P


In reply to: 192240765 [](ancestors = 192240765,192227732)

</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
<ProjectReference Include="..\Microsoft.ML.Maml\Microsoft.ML.Maml.csproj" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/Microsoft.ML.Data/Commands/DataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static class DataCommand
{
public abstract class ArgumentsBase
{
[Argument(ArgumentType.Multiple, HelpText = "The data loader", ShortName = "loader", SortOrder = 1, NullName = "<Auto>")]
[Argument(ArgumentType.Multiple, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "The data loader", ShortName = "loader", SortOrder = 1, NullName = "<Auto>")]
public SubComponent<IDataLoader, SignatureDataLoader> Loader;

[Argument(ArgumentType.AtMostOnce, IsInputFileName = true, HelpText = "The data file", ShortName = "data", SortOrder = 0)]
public string DataFile;

[Argument(ArgumentType.AtMostOnce, HelpText = "Model file to save", ShortName = "out")]
[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "Model file to save", ShortName = "out")]
public string OutputModelFile;

[Argument(ArgumentType.AtMostOnce, IsInputFileName = true, HelpText = "Model file to load", ShortName = "in", SortOrder = 90)]
Expand All @@ -41,7 +41,7 @@ public abstract class ArgumentsBase
[Argument(ArgumentType.AtMostOnce, HelpText = "Verbose?", ShortName = "v", Hide = true)]
public bool? Verbose;

[Argument(ArgumentType.AtMostOnce, HelpText = "The web server to publish the RESTful API", Hide = true)]
[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "The web server to publish the RESTful API", Hide = true)]
public ServerChannel.IServerFactory Server;

// This is actually an advisory value. The implementations themselves are responsible for
Expand All @@ -51,7 +51,7 @@ public abstract class ArgumentsBase
HelpText = "Desired degree of parallelism in the data pipeline", ShortName = "n")]
public int? Parallel;

[Argument(ArgumentType.Multiple, HelpText = "Transform", ShortName = "xf")]
[Argument(ArgumentType.Multiple, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "Transform", ShortName = "xf")]
public KeyValuePair<string, SubComponent<IDataTransform, SignatureDataTransform>>[] Transform;
}

Expand Down
77 changes: 58 additions & 19 deletions src/Microsoft.ML.Data/Model/Onnx/SaveOnnxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
using Microsoft.ML.Runtime.Command;
using Microsoft.ML.Runtime.CommandLine;
using Microsoft.ML.Runtime.Data;
using Microsoft.ML.Runtime.EntryPoints;
using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model.Onnx;
using Microsoft.ML.Runtime.UniversalModelFormat.Onnx;
using Newtonsoft.Json;

[assembly: LoadableClass(SaveOnnxCommand.Summary, typeof(SaveOnnxCommand), typeof(SaveOnnxCommand.Arguments), typeof(SignatureCommand),
"Save ONNX", "SaveOnnx", DocName = "command/SaveOnnx.md")]

[assembly: LoadableClass(typeof(void), typeof(SaveOnnxCommand), null, typeof(SignatureEntryPointModule), "SaveOnnx")]

namespace Microsoft.ML.Runtime.Model.Onnx
{
public sealed class SaveOnnxCommand : DataCommand.ImplBase<SaveOnnxCommand.Arguments>
Expand All @@ -37,14 +41,24 @@ public sealed class Arguments : DataCommand.ArgumentsBase
[Argument(ArgumentType.AtMostOnce, HelpText = "The 'domain' property in the output ONNX.", NullName = "<Auto>", SortOrder = 4)]
public string Domain;

[Argument(ArgumentType.AtMostOnce, HelpText = "Comma delimited list of input column names to drop", ShortName = "idrop", SortOrder = 5)]
[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "Comma delimited list of input column names to drop", ShortName = "idrop", SortOrder = 5)]
public string InputsToDrop;
Copy link
Contributor

@TomFinley TomFinley May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set visibility on this. #Closed


[Argument(ArgumentType.AtMostOnce, HelpText = "Comma delimited list of output column names to drop", ShortName = "odrop", SortOrder = 6)]
[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly, HelpText = "Array of input column names to drop", Name = nameof(InputsToDrop), SortOrder = 6)]
public string[] InputsToDropArray;
Copy link
Contributor

@TomFinley TomFinley May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InputsToDropArray [](start = 28, length = 17)

Awkward name to use. Please use Name = nameof(InputsToDrop) instead. #Closed


[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "Comma delimited list of output column names to drop", ShortName = "odrop", SortOrder = 7)]
public string OutputsToDrop;

[Argument(ArgumentType.AtMostOnce, HelpText = "Whether we should attempt to load the predictor and attach the scorer to the pipeline if one is present.", ShortName = "pred", SortOrder = 7)]
[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly, HelpText = "Array of output column names to drop", Name = nameof(OutputsToDrop), SortOrder = 8)]
public string[] OutputsToDropArray;
Copy link
Contributor

@TomFinley TomFinley May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputsToDropArray [](start = 28, length = 18)

Same comments on inputs apply to outputs. #Closed


[Argument(ArgumentType.AtMostOnce, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly, HelpText = "Whether we should attempt to load the predictor and attach the scorer to the pipeline if one is present.", ShortName = "pred", SortOrder = 9)]
public bool? LoadPredictor;
Copy link
Contributor

@TomFinley TomFinley May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to have this in entry-point land? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if we are passing in ITransformModel that contains the predictor.


In reply to: 191819078 [](ancestors = 191819078)


[Argument(ArgumentType.Required, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly, HelpText = "Model that needs to be converted to ONNX format.", SortOrder = 10)]

public ITransformModel Model;
Copy link
Contributor

@TomFinley TomFinley May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a newline gap here. We tend to not put whitespace between the attribute and the field, as we see elsewhere here. #Closed

}

private readonly string _outputModelPath;
Expand All @@ -54,6 +68,7 @@ public sealed class Arguments : DataCommand.ArgumentsBase
private readonly bool? _loadPredictor;
private readonly HashSet<string> _inputsToDrop;
private readonly HashSet<string> _outputsToDrop;
private readonly ITransformModel _model;

public SaveOnnxCommand(IHostEnvironment env, Arguments args)
: base(env, args, LoadName)
Expand All @@ -68,16 +83,18 @@ public SaveOnnxCommand(IHostEnvironment env, Arguments args)
_name = args.Name;

_loadPredictor = args.LoadPredictor;
_inputsToDrop = CreateDropMap(args.InputsToDrop);
_outputsToDrop = CreateDropMap(args.OutputsToDrop);
_inputsToDrop = CreateDropMap(args.InputsToDropArray ?? args.InputsToDrop?.Split(','));
_outputsToDrop = CreateDropMap(args.OutputsToDropArray ?? args.OutputsToDrop?.Split(','));
_domain = args.Domain;
_model = args.Model;
}

private static HashSet<string> CreateDropMap(string toDrop)
private static HashSet<string> CreateDropMap(string[] toDrop)
{
if (string.IsNullOrWhiteSpace(toDrop))
if (toDrop == null)
return new HashSet<string>();
return new HashSet<string>(toDrop.Split(','));

return new HashSet<string>(toDrop);
}

public override void Run()
Expand Down Expand Up @@ -115,26 +132,34 @@ private void GetPipe(IChannel ch, IDataView end, out IDataView source, out IData

private void Run(IChannel ch)
{
IDataLoader loader;
IPredictor rawPred;
RoleMappedSchema trainSchema;
IDataLoader loader = null;
IPredictor rawPred = null;
IDataView view;
RoleMappedSchema trainSchema = null;

if (string.IsNullOrEmpty(Args.InputModelFile))
if (_model == null)
{
loader = CreateLoader();
rawPred = null;
trainSchema = null;
Host.CheckUserArg(Args.LoadPredictor != true, nameof(Args.LoadPredictor),
"Cannot be set to true unless " + nameof(Args.InputModelFile) + " is also specifified.");
if (string.IsNullOrEmpty(Args.InputModelFile))
{
loader = CreateLoader();
rawPred = null;
trainSchema = null;
Host.CheckUserArg(Args.LoadPredictor != true, nameof(Args.LoadPredictor),
"Cannot be set to true unless " + nameof(Args.InputModelFile) + " is also specifified.");
}
else
LoadModelObjects(ch, _loadPredictor, out rawPred, true, out trainSchema, out loader);

view = loader;
}
else
LoadModelObjects(ch, _loadPredictor, out rawPred, true, out trainSchema, out loader);
view = _model.Apply(Host, new EmptyDataView(Host, _model.InputSchema));

// Get the transform chain.
IDataView source;
IDataView end;
LinkedList<ITransformCanSaveOnnx> transforms;
GetPipe(ch, loader, out source, out end, out transforms);
GetPipe(ch, view, out source, out end, out transforms);
Host.Assert(transforms.Count == 0 || transforms.Last.Value == end);

var ctx = new OnnxContext(Host, _name, _domain);
Expand Down Expand Up @@ -228,10 +253,24 @@ private void Run(IChannel ch)

if (!string.IsNullOrWhiteSpace(Args.OutputModelFile))
Copy link
Contributor

@TomFinley TomFinley May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputModelFile [](start = 48, length = 15)

Did you set the visibility on these? I don't see the DataCommand.cs in this list here. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not exposed in the EP since I created the arguments class for EP input.


In reply to: 191821856 [](ancestors = 191821856)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I got the sense you didn't want to do that. It means a fair amount of duplication that I think is probably unnecessary.


In reply to: 191901052 [](ancestors = 191901052,191821856)

{
Contracts.Assert(loader != null);

ch.Trace("Saving the data pipe");
// Should probably include "end"?
SaveLoader(loader, Args.OutputModelFile);
}
}

public sealed class Output
{
}

[TlcModule.EntryPoint(Name = "Models.OnnxConverter", Desc = "Converts the model to ONNX format.", UserName = "ONNX Converter.")]
public static Output Apply(IHostEnvironment env, Arguments input)
{
new SaveOnnxCommand(env, input).Run();
return new Output();
}

}
}
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Maml/Microsoft.ML.Maml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>CORECLR</DefineConstants>
<TargetFramework>netstandard2.0</TargetFramework>
<IncludeInPackage>Microsoft.ML</IncludeInPackage>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.UniversalModelFormat/LotusIR/OnnxMl.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
2. Download protobuf C# compiler version 3.0 or greater from
https://github.com/google/protobuf/tree/master/csharp
3. Add `option csharp_namespace =
"Microsoft.MachineLearning.Runtime.UniversalModelFormat.Onnx";` to `onnx-ml.proto3` right below `package ONNX_NAMESPACE;`
"Microsoft.ML.Runtime.UniversalModelFormat.Onnx";` to `onnx-ml.proto3` right below `package ONNX_NAMESPACE;`
4. Assuming the compiler and proto file are saved at
`E:\protobuf-csharp-port\lib` then run the following in command line to get C# code from the proto file:
```
Expand Down
Loading