Skip to content

Image classification training convert to onnx file format #1048

Description

@Marat1905

I've been doing experiments with the C# image classification examples, and I've been struggling trying to modify the sample to save an ONNX file without success, since it gives me the usual "The targeted pipeline can not be fully converted into a well-defined ONNX model" exception.

So which would be the steps required to be able to save an onnx file?

I am aware some pipeline might contain ML transformers that are not available in ONNX, but maybe the ConvertToOnnx method could have a "best effort" option that would automatically convert what can be converted.

In other words, I would like to save the raw ONNX model that's in between the transformers that cannot be converted to ONNX.

var trainTestSplit = _mlContext.Data.TrainTestSplit(data, testFraction: 0.2);
var trainData = trainTestSplit.TrainSet;
var testData = trainTestSplit.TestSet;

var pipeline = _mlContext.Transforms.Conversion.MapValueToKey(
outputColumnName: "LabelKey",
inputColumnName: "Label")

.Append(_mlContext.Transforms.LoadRawImageBytes(
outputColumnName: "Image",
imageFolder: null,
inputColumnName: "ImagePath"))
.Append(_mlContext.MulticlassClassification.Trainers.ImageClassification(
new ImageClassificationTrainer.Options()
{
LabelColumnName = "LabelKey",
FeatureColumnName = "Image",
Arch = ImageClassificationTrainer.Architecture.InceptionV3,
Epoch = _settings.Epochs,
BatchSize = _settings.BatchSize,
LearningRate = 0.001f,
MetricsCallback = (metrics) => _logger.LogInformation($"Epoch: {metrics.Train?.Epoch}, Top1Accuracy: {metrics.Train?.Accuracy}")
}))
.Append(_mlContext.Transforms.Conversion.MapKeyToValue(
outputColumnName: "PredictedLabel",
inputColumnName: "PredictedLabel"));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions