dotnet / machinelearning

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

[Image Classification DNN Transfer Learning] - Support training and scoring with in-memory images #4153

Closed CESARDELATORRE closed 5 years ago

CESARDELATORRE commented 5 years ago

The new DNN-Transfer-Learning is very nicely simplified (and it'll be even more simplified), however, the way it is now doesn't support to train and score with in-memory images, therefore, if you train with image filepaths, the model for scoring also requires image paths...

That's limiting in-memory images scenarios that we really need to support.

For instance, in the code below, the API ImageClassification() is expecting image filepaths, only.

    public class ImageData
    {
        [LoadColumn(0)]
        public string ImagePath;

        [LoadColumn(1)]
        public string Label;
    }

//...
var pipeline = mlContext.Transforms.Conversion.MapValueToKey(outputColumnName: "LabelAsKey", 
                                                                inputColumnName: "Label",
                                                                keyOrdinality: ValueToKeyMappingEstimator.KeyOrdinality.ByValue)
            .Append(mlContext.Model.ImageClassification("ImagePath", "LabelAsKey",
                            arch: ImageClassificationEstimator.Architecture.ResnetV2101,
                            epoch: 100,     //An epoch is one learning cycle where the learner sees the whole training data set.
                            batchSize: 100, // batchSize sets the number of images to feed the model at a time. It needs to divide the training set evenly or the remaining part won't be used for training. Use 10 for hundreds of images, 100 for thousands of images                             
                            metricsCallback: (metrics) => Console.WriteLine(metrics),
                            reuseTrainSetBottleneckCachedValues: false,
                            reuseValidationSetBottleneckCachedValues: false,
                            validationSet: transformedValidationDataView));
codemzs commented 5 years ago

@harshithapv is working on this.

masgh021 commented 3 years ago

Hello @CESARDELATORRE , @harshithapv i want use bitmap file from memory (not filepath) for classification . but i have this problem. when this fix and i can load bitmap image from memory ??