Have been playing around with machine learning as of late, made a basic machine learning algorithm. It was working perfectly and then I broke something and now it refuses to save the model.
here's the code:
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));
}
}
this code was automatically generated, I just removed the comment, added the try catch and specified the model path.
here's the exception:
> 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
and this is the file which is supposed to contain the model(it is empty)