Skip to content

Instantly share code, notes, and snippets.

@CESARDELATORRE
Last active July 8, 2018 21:08
Show Gist options
  • Save CESARDELATORRE/080f9a9e89bff1f9634f281f97729cab to your computer and use it in GitHub Desktop.
Save CESARDELATORRE/080f9a9e89bff1f9634f281f97729cab to your computer and use it in GitHub Desktop.

Revisions

  1. CESARDELATORRE revised this gist Jul 8, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions export-onnx-model-from-mlnet-model.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    var onnxPath = GetOutputPath(subDir, "SaveModelToOnnxTest.pb");
    var onnxPath = GetOutputPath(subDir, "SaveModelToOnnxTest.onnx");
    var onnxAsJsonPath = GetOutputPath(subDir, "SaveModelToOnnxTest.json");

    OnnxConverter converter = new OnnxConverter()
    @@ -7,7 +7,7 @@
    OutputsToDrop = new[] { "Label", "Features" },
    Onnx = onnxPath,
    Json = onnxAsJsonPath,
    Domain = "Onnx"
    Domain = "com.mydomain"
    };

    converter.Convert(model);
  2. CESARDELATORRE created this gist Jul 6, 2018.
    18 changes: 18 additions & 0 deletions export-onnx-model-from-mlnet-model.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    var onnxPath = GetOutputPath(subDir, "SaveModelToOnnxTest.pb");
    var onnxAsJsonPath = GetOutputPath(subDir, "SaveModelToOnnxTest.json");

    OnnxConverter converter = new OnnxConverter()
    {
    InputsToDrop = new[] { "Label" },
    OutputsToDrop = new[] { "Label", "Features" },
    Onnx = onnxPath,
    Json = onnxAsJsonPath,
    Domain = "Onnx"
    };

    converter.Convert(model);

    // Strip the version.
    var fileText = File.ReadAllText(onnxAsJsonPath);
    fileText = Regex.Replace(fileText, "\"producerVersion\": \"([^\"]+)\"", "\"producerVersion\": \"##VERSION##\"");
    File.WriteAllText(onnxAsJsonPath, fileText);