Как загрузить несколько папок с изображениями в конвейер? - PullRequest
0 голосов
/ 21 февраля 2020

Я довольно новичок в 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...