none
ML.Net System.TypeLoadException RRS feed

  • Question

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

    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!

    Monday, November 11, 2019 7:16 PM

Answers

  • A issue post at Github has got me this quick response from codemzs:Microsoft.ML.DNN no longer exits as it was in preview. It has been replaced with Microsoft.ML.Vision please use that.

    Tuesday, November 12, 2019 5:30 PM

All replies

  • I know nothing about ML.Net but apparently it is preliminary. It might be a bug but probably is not a bug.

    It could be something such as a mismatch of versions. I probably cannot help but it will probably help anyone that can help if you describe how you created the project (what type of project) and what references you have added and things like that.



    Sam Hobbs
    SimpleSamples.Info


    Monday, November 11, 2019 8:14 PM
  • Thanks for the reply Sam!

    I added the references just from NuGet, the Microsoft.ML Package, the Microsoft.ML.DNN package. I created both a forms and a Console type program to try and get around the issue, to no avail. I'm trying the latest framework just in case that might be the issue (4.6.x -> 4.7.x). Lastly I am following this video: https://www.youtube.com/watch?v=bXTN-rnwDso to create the project as this is just a test project to see how things work.

    Do you think it would be worth posting on GitHub, where the project resides?


    Monday, November 11, 2019 8:41 PM
  • I added the references just from NuGet, the Microsoft.ML Package, the Microsoft.ML.DNN package.

    What versions? I do not know if that makes a difference but just in case...



    Sam Hobbs
    SimpleSamples.Info

    Monday, November 11, 2019 9:07 PM
  • Microsoft.ML v1.4.0

    Microsoft.ML.DNN v0.16.0 - preview 2

    Monday, November 11, 2019 10:37 PM
  • A issue post at Github has got me this quick response from codemzs:Microsoft.ML.DNN no longer exits as it was in preview. It has been replaced with Microsoft.ML.Vision please use that.

    Tuesday, November 12, 2019 5:30 PM