Microsoft.ML не может сохранить модель из-за неправильного пути? - PullRequest
0 голосов
/ 15 апреля 2020

В последнее время занимаюсь машинным обучением, создал базовый c алгоритм машинного обучения. Он работал отлично, а потом я что-то сломал и теперь отказывается сохранять модель.

вот код:

        private static string MODEL_FILEPATH = @"MLModel.zip";
    // Create MLContext to be shared across the model creation workflow objects 
    // Set a random seed for repeatable/deterministic results across multiple trainings.
    private static MLContext mlContext = new MLContext(seed: 1);

    public static void CreateModel()
    {
        // Load Data
        IDataView trainingDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
                                        path: TRAIN_DATA_FILEPATH,
                                        hasHeader: true,
                                        separatorChar: ',',
                                        allowQuoting: true,
                                        allowSparse: false);

        // Build training pipeline
        IEstimator<ITransformer> trainingPipeline = BuildTrainingPipeline(mlContext);

        // Evaluate quality of Model
        //Evaluate(mlContext, trainingDataView, trainingPipeline);

        // Train Model
        ITransformer mlModel = TrainModel(mlContext, trainingDataView, trainingPipeline);

        // Save model
        SaveModel(mlContext, mlModel, MODEL_FILEPATH, trainingDataView.Schema);
    }
    private static void SaveModel(MLContext mlContext, ITransformer mlModel, string 
modelRelativePath, DataViewSchema modelInputSchema)
    {

        try
        {
            mlContext.Model.Save(mlModel, null, (GetAbsolutePath(modelRelativePath)));
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString() + "\n" + e.Message + ": " + GetAbsolutePath(modelRelativePath));
        }

    }

этот код был сгенерирован автоматически, я просто удалил комментарий, добавил try catch и указал путь к модели.

вот исключение:

  > Exception thrown: 'System.ArgumentException' in mscorlib.dll
   System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean 
   expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at Microsoft.ML.RepositoryWriter.CreateNew(Stream stream, IExceptionContext ectx, Boolean 
   useFileSystem)
   at Microsoft.ML.ModelOperationsCatalog.Save(ITransformer model, DataViewSchema inputSchema, Stream 
   stream)
   at Microsoft.ML.ModelOperationsCatalog.Save(ITransformer model, DataViewSchema inputSchema, String 
   filePath)
   at MachineLearningTest.ModelBuilder.SaveModel(MLContext mlContext, ITransformer mlModel, String 
   modelRelativePath, DataViewSchema modelInputSchema) in 
   C:\Users\Michael\Source\Repos\new\MachineLearingTest\ModelBuilder.cs:line 83
   The path is not of a legal form.: 
   C:\Users\Michael\Source\Repos\new\MachineLearingTest\bin\x64\Debug\MLModel.zip

, и это файл, который должен содержать модель (она пуста)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...