I'm not sure if this is specific to ML.NET, but it does happen in the context of it.
I am using ML.NET to classify some images. I realized that it poses a severe difference whether I call .ToArray() on the resulting IEnumerable or not. The former results in all the array elements becoming identical to the last one.
IEnumerable<ImageData> dataCollection = imagePaths.Select(path => new ImageData(path));
IDataView targetDataView = _mlContext.Data.LoadFromEnumerable(dataCollection);
IDataView predictionView = _transformerModel.Transform(targetDataView);
return _mlContext.Data.CreateEnumerable<ImagePrediction>(predictionView, true).ToArray();
In the example shown above, the resulting predictions will all have their image path set to the last image path in imagePaths.
I don't believe that this is intended behaviour. What causes this and how can I safely prevent this? For the moment I decided to just not call .ToArray(), but I'd like to know more about this issue.