dotnet / machinelearning-modelbuilder

Simple UI tool to build custom machine learning models.
Creative Commons Attribution 4.0 International
264 stars 56 forks source link

The given key was not present in the dictionary. #2742

Open aboudoux opened 1 year ago

aboudoux commented 1 year ago

Hello, I'm trying to train my custom model with the local Object detection scenario. everything go fine until Channel finished that crash with the following exception

at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionMetrics.ImageIoU(List1 objectLabel, List1 annotation, Dictionary2 iouDic, Dictionary2 groundTruthBoxes) at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionMetrics.GenerateIOUDic(List1 annotations, List1 objectLabelList, Dictionary2 iouDic, Dictionary`2 groundTruthBoxes) at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionMetrics.MeasureMetrics(IDataView dataView, Column labelCol, Column actualBoundingBoxColumn, Column predictedLabelCol, Column predictedBoundingBoxColumn, Column scoreCol) at Microsoft.ML.ModelBuilder.AutoMLService.LocalObjectDetectionMetricManager.Evaluate(MLContext context, IDataView eval) in //src/Microsoft.ML.ModelBuilder.AutoMLService/MetricManagers/LocalObjectDetectionMetricManager.cs:line 24 at Microsoft.ML.AutoML.SweepablePipelineRunner.Run(TrialSettings settings) at Microsoft.ML.AutoML.SweepablePipelineRunner.RunAsync(TrialSettings settings, CancellationToken ct) at Microsoft.ML.AutoML.AutoMLExperiment.d24.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ML.ModelBuilder.AutoMLService.LocalObjectDetectionExperiment.d13.MoveNext() in //src/Microsoft.ML.ModelBuilder.AutoMLService/Experiments/LocalObjectDetectionExperiment.cs:line 133 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ML.ModelBuilder.AutoMLEngine.d_21.MoveNext() in //src/Microsoft.ML.ModelBuilder.AutoMLService/AutoMLEngineService/AutoMLEngine.cs:line 169

LittleLittleCloud commented 1 year ago

@aboudoux Would you mind sharing your .mbconfig with us.

Nekiplay commented 1 year ago

I have the same problem, my mbconfig. This problem appears on both json data formats

{
  "Scenario": "ObjectDetection",
  "DataSource": {
    "Version": 0,
    "Type": "Coco",
    "FilePath": "C:\\Users\\Nekiplay\\Desktop\\CocoAnatator\\coco-annotator\\datasets\\LordsMobile\\.exports\\coco-1689492909.3708026.json"
  },
  "Environment": {
    "Type": "LocalCPU",
    "Version": 1
  },
  "Type": "TrainingConfig",
  "Version": 4,
  "TrainingOption": {
    "Version": 0,
    "Type": "ObjectDetectionTrainingOption",
    "TrainingTime": 2147483647,
    "Epoch": 5,
    "ScoreThreshold": 0.35,
    "IOUThreshold": 0.5,
    "ValidationOption": {
      "Version": 0,
      "Type": "TrainValidateSplitValidationOption",
      "SplitRatio": 0.2
    },
    "ResizeOption": {
      "Version": 0,
      "Type": "Resize",
      "Width": 800,
      "Height": 600
    }
  }
}

UPD: And Coco dataset not use path for image image

Nekiplay commented 1 year ago

Hello, I'm trying to train my custom model with the local Object detection scenario. everything go fine until Channel finished that crash with the following exception

at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionMetrics.ImageIoU(List1 objectLabel, List1 annotation, Dictionary2 iouDic, Dictionary2 groundTruthBoxes) at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionMetrics.GenerateIOUDic(List1 annotations, List1 objectLabelList, Dictionary2 iouDic, Dictionary`2 groundTruthBoxes) at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionMetrics.MeasureMetrics(IDataView dataView, Column labelCol, Column actualBoundingBoxColumn, Column predictedLabelCol, Column predictedBoundingBoxColumn, Column scoreCol) at Microsoft.ML.ModelBuilder.AutoMLService.LocalObjectDetectionMetricManager.Evaluate(MLContext context, IDataView eval) in //src/Microsoft.ML.ModelBuilder.AutoMLService/MetricManagers/LocalObjectDetectionMetricManager.cs:line 24 at Microsoft.ML.AutoML.SweepablePipelineRunner.Run(TrialSettings settings) at Microsoft.ML.AutoML.SweepablePipelineRunner.RunAsync(TrialSettings settings, CancellationToken ct) at Microsoft.ML.AutoML.AutoMLExperiment.d24.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ML.ModelBuilder.AutoMLService.LocalObjectDetectionExperiment.d13.MoveNext() in //src/Microsoft.ML.ModelBuilder.AutoMLService/Experiments/LocalObjectDetectionExperiment.cs:line 133 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ML.ModelBuilder.AutoMLEngine.d_21.MoveNext() in //src/Microsoft.ML.ModelBuilder.AutoMLService/AutoMLEngineService/AutoMLEngine.cs:line 169

I found the cause of the problem, don't export a model with unlabeled categories This error is due to the fact that ML.Net cannot find images that belong to categories that are not labeled

LittleLittleCloud commented 1 year ago

@aboudoux @Nekiplay May I ask how many different kind of labels does your dataset have? I'm suspecting that this issue is causes because some labels are classified into test dataset and not in train dataset during train-validation split.

I also have trouble in reproducing this issue on all testing dataset I have. Would be appreciated if anyone can guide me through how to reproducing this bug.

Nekiplay commented 1 year ago

@aboudoux @Nekiplay May I ask how many different kind of labels does your dataset have? I'm suspecting that this issue is causes because some labels are classified into test dataset and not in train dataset during train-validation split.

I also have trouble in reproducing this issue on all testing dataset I have. Would be appreciated if anyone can guide me through how to reproducing this bug.

There was one label for one category and 0 for the other. After removing them from the data export, the training went fine At least 8 images are enough for a successful training session image