System.TypeLoadException: 'Method 'MakeRowMapper' on type 'Microsoft.ML.Transforms.ImageClassificationTransformer' from assembly 'Microsoft.ML.DNN, version 1.0.0.0, culture=neutral, Public Key Token=cc7b13ffcd2ddd51' is overriding a method that is not visible from that assembly.
This occurs when using either a forms application or a console application, I have tried removing and re-adding the various NuGet packages and different verisons to try and get around this issue. It occurs on startup of the application.
Source code / logs
class Program
{
static void Main(string[] args)
{
var imagesFolder = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "images");
var file = Directory.GetFiles(imagesFolder, "*", SearchOption.AllDirectories);
var images = file.Select(f => new ImageData
{
ImagePath = f,
Label = Directory.GetParent(f).Name
});
var context = new MLContext();
var imageData = context.Data.LoadFromEnumerable(images);
var imageDataShuffle = context.Data.ShuffleRows(imageData);
var testTrainData = context.Data.TrainTestSplit(imageDataShuffle, testFraction: 0.2);
var validateData = context.Transforms.Conversion.MapValueToKey("LabelKey", "Label", keyOrdinality: Microsoft.ML.Transforms.ValueToKeyMappingEstimator.KeyOrdinality.ByValue).Fit(testTrainData.TestSet).Transform(testTrainData.TestSet);
var pipeline = context.Transforms.Conversion.MapValueToKey("LabelKey", "Label", keyOrdinality: Microsoft.ML.Transforms.ValueToKeyMappingEstimator.KeyOrdinality.ByValue).Append(context.Model.ImageClassification("ImagePath", "LabelKey", arch: Microsoft.ML.Transforms.ImageClassificationEstimator.Architecture.ResnetV2101, epoch: 100, metricsCallback: Console.WriteLine, batchSize: 10, validationSet: validateData));
var model = pipeline.Fit(testTrainData.TestSet);
var predictions = model.Transform(testTrainData.TestSet);
var metrics = context.MulticlassClassification.Evaluate(predictions, labelColumnName: "LabelKey", predictedLabelColumnName: "PredictedLabel");
Console.WriteLine($"Log Loss - {metrics.LogLoss}");
var predictionEngine = context.Model.CreatePredictionEngine<ImageData, Image_Prediction>(model);
var testImagesFolder = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "test");
var testFiles = Directory.GetFiles(testImagesFolder, "*", SearchOption.AllDirectories);
var testImages = testFiles.Select(f => new ImageData
{
ImagePath = f
});
VBuffer<ReadOnlyMemory<char>> keys = default;
predictionEngine.OutputSchema["LabelKey"].GetKeyValues(ref keys);
var originalLabels = keys.DenseValues().ToArray();
foreach (var image in testImages)
{
var prediction = predictionEngine.Predict(image);
var labelIndex = prediction.PredictedLabel;
Console.WriteLine($"Image: {Path.GetFileName(image.ImagePath)}, Score: {prediction.score.Max()}" + $"$Predicted Label: {originalLabels[labelIndex]}");
Console.ReadLine();
}
}
System information
-Windows 10 1903 -.Net Framework 4.7.x -Microsoft.ML v1.4.0 -Microsoft.ML.DNN v0.16.0 - preview 2
Issue
I was using the code found in this video: https://www.youtube.com/watch?v=bXTN-rnwDso to get a test project up and running and ran into this error:
System.TypeLoadException: 'Method 'MakeRowMapper' on type 'Microsoft.ML.Transforms.ImageClassificationTransformer' from assembly 'Microsoft.ML.DNN, version 1.0.0.0, culture=neutral, Public Key Token=cc7b13ffcd2ddd51' is overriding a method that is not visible from that assembly.
This occurs when using either a forms application or a console application, I have tried removing and re-adding the various NuGet packages and different verisons to try and get around this issue. It occurs on startup of the application.
Source code / logs
class Program { static void Main(string[] args) { var imagesFolder = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "images"); var file = Directory.GetFiles(imagesFolder, "*", SearchOption.AllDirectories); var images = file.Select(f => new ImageData { ImagePath = f, Label = Directory.GetParent(f).Name });