dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.01k stars 1.88k forks source link

ML.Net deep-learning classification tutorial code hits InvalidOperationException error #7071

Open khteh opened 6 months ago

khteh commented 6 months ago

System Information (please complete the following information):

Describe the bug Following this tutorial https://learn.microsoft.com/en-us/dotnet/machine-learning/tutorials/image-classification-api-transfer-learning, the following code snippet:

ITransformer BuildAndTrainModel(IDataView trainingDataView, ImageClassificationTrainer.Options classifierOptions)
{
    WriteLine($"Build and train model...");
    var trainingPipeline = mlContext.MulticlassClassification.Trainers.ImageClassification(classifierOptions)
                                .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));
    return trainingPipeline.Fit(trainingDataView); <<- Error
}

hits a runtime error:

System.InvalidOperationException
  HResult=0x80131509
  Message=Error downloading resource from 'https://aka.ms/mlnet-resources/meta/resnet_v2_101_299.meta': DownloadFailed with exception One or more errors occurred. (Object synchronization method was called from an unsynchronized block of code.)\nDownloadFailed with exception One or more errors occurred. (The wait completed due to an abandoned mutex.)\nDownloadFailed with exception One or more errors occurred. (Object synchronization method was called from an unsynchronized block of code.)\nDownloadFailed with exception One or more errors occurred. (The wait completed due to an abandoned mutex.)\nDownloadFailed with exception One or more errors occurred. (The wait completed due to an abandoned mutex.)\n
Meta file could not be downloaded! Please copy the model file 'resnet_v2_101_299.meta' from 'meta\resnet_v2_101_299.meta' to 'C:\Users\me\AppData\Local\Temp\MLNET'.
  Source=Microsoft.ML.TensorFlow
  StackTrace:
   at Microsoft.ML.TensorFlow.TensorFlowUtils.DownloadIfNeeded(IHostEnvironment env, String url, String dir, String fileName, Int32 timeout)
   at Microsoft.ML.Vision.ImageClassificationTrainer.LoadTensorFlowSessionFromMetaGraph(IHostEnvironment env, Architecture arch)
   at Microsoft.ML.Vision.ImageClassificationTrainer.InitializeTrainingGraph(IDataView input)
   at Microsoft.ML.Vision.ImageClassificationTrainer.TrainModelCore(TrainContext trainContext)
   at Microsoft.ML.Trainers.TrainerEstimatorBase`2.TrainTransformer(IDataView trainSet, IDataView validationSet, IPredictor initPredictor)
   at Microsoft.ML.Trainers.TrainerEstimatorBase`2.Fit(IDataView input)
   at Microsoft.ML.Data.EstimatorChain`1.Fit(IDataView input)
   at Program.<<Main>$>g__BuildAndTrainModel|0_2(IDataView trainingDataView, Options classifierOptions, <>c__DisplayClass0_0& ) in C:\Projects\ML.Net\DeepLearning_ImageClassification_Binary\src\Program.cs:line 83
   at Program.<Main>$(String[] args) in C:\Projects\ML.Net\DeepLearning_ImageClassification_Binary\src\Program.cs:line 21

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior Runs successfully

Screenshots, Code, Sample Projects If applicable, add screenshots, code snippets, or sample projects to help explain your problem.

Additional context Add any other context about the problem here.