0

我是 ML 的新手。

我开始使用示例来了解它是如何工作的。

我正在尝试加载多个图像文件夹。例如,包含学习数据的汽车、猫文件夹。我知道我需要将新文件夹加载到管道中,现在我看不到如何实现

你有什么建议吗?

   // <SnippetImageTransforms>
    IEstimator<ITransformer> pipeline = mlContext.Transforms.LoadImages(outputColumnName: "input", imageFolder: _imagesFolder, inputColumnName: nameof(ImageData.ImagePath))
                    // The image transforms transform the images into the model's expected format.
                    .Append(mlContext.Transforms.ResizeImages(outputColumnName: "input", imageWidth: InceptionSettings.ImageWidth, imageHeight: InceptionSettings.ImageHeight, inputColumnName: "input"))
                    .Append(mlContext.Transforms.ExtractPixels(outputColumnName: "input", interleavePixelColors: InceptionSettings.ChannelsLast, offsetImage: InceptionSettings.Mean))
                    // </SnippetImageTransforms>
                    // The ScoreTensorFlowModel transform scores the TensorFlow model and allows communication 
                    // <SnippetScoreTensorFlowModel>
                    .Append(mlContext.Model.LoadTensorFlowModel(_inceptionTensorFlowModel).
                        ScoreTensorFlowModel(outputColumnNames: new[] { "softmax2_pre_activation" }, inputColumnNames: new[] { "input" }, addBatchDimensionInput: true))
                    // </SnippetScoreTensorFlowModel>
                    // <SnippetMapValueToKey>
                    .Append(mlContext.Transforms.Conversion.MapValueToKey(outputColumnName: "LabelKey", inputColumnName: "Label"))
                    // </SnippetMapValueToKey>
                    // <SnippetAddTrainer>
                    .Append(mlContext.MulticlassClassification.Trainers.LbfgsMaximumEntropy(labelColumnName: "LabelKey", featureColumnName: "softmax2_pre_activation"))
                    // </SnippetAddTrainer>
                    // <SnippetMapKeyToValue>
                    .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabelValue", "PredictedLabel"))
                    .AppendCacheCheckpoint(mlContext);
    // </SnippetMapKeyToValue>

    // <SnippetLoadData>
    IDataView trainingData = mlContext.Data.LoadFromTextFile<ImageData>(path:  _trainTagsTsv, hasHeader: false);
    // </SnippetLoadData>

    // Train the model
    Console.WriteLine("=============== Training classification model ===============");
    // Create and train the model
    // <SnippetTrainModel>
    ITransformer model = pipeline.Fit(trainingData);
    // </SnippetTrainModel>

    // Generate predictions from the test data, to be evaluated
    // <SnippetLoadAndTransformTestData>
    IDataView testData = mlContext.Data.LoadFromTextFile<ImageData>(path: _testTagsTsv, hasHeader: false);
    IDataView predictions = model.Transform(testData);

    // Create an IEnumerable for the predictions for displaying results
    IEnumerable<ImagePrediction> imagePredictionData = mlContext.Data.CreateEnumerable<ImagePrediction>(predictions, true);
    DisplayResults(imagePredictionData);
    // </SnippetLoadAndTransformTestData>
4

0 回答 0