ML.Net System.TypeLoadException

  • Thread starter Thread starter T3rr0rByte13-Hobbyware.org
  • Start date Start date
T

T3rr0rByte13-Hobbyware.org

Guest
Hello, I'm getting this exception when running a release of ML.NET (Microsoft.ML.DNN v0.16.0-preview2)

1502929.png

This is the code in my main program

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();
}
}
The issue arises when the program compiles. Do you think it is related to a bug in the DLL or could it be something I have done. Thanks!

Continue reading...
 
Back
Top