/// <summary> /// Create the write stream from the file, if not null. /// </summary> private Stream CreateStrm(IFileHandle file) { if (file == null) { return(null); } return(file.CreateWriteStream()); }
/// <summary> /// Saves <paramref name="loader"/> to the specified <paramref name="file"/>. /// </summary> public static void SaveLoader(ILegacyDataLoader loader, IFileHandle file) { Contracts.CheckValue(loader, nameof(loader)); Contracts.CheckValue(file, nameof(file)); Contracts.CheckParam(file.CanWrite, nameof(file), "Must be writable"); using (var stream = file.CreateWriteStream()) { SaveLoader(loader, stream); } }
public static void SaveDataView(IChannel ch, IDataSaver saver, IDataView view, IFileHandle file, bool keepHidden = false) { Contracts.CheckValue(ch, nameof(ch)); ch.CheckValue(saver, nameof(saver)); ch.CheckValue(view, nameof(view)); ch.CheckValue(file, nameof(file)); ch.CheckParam(file.CanWrite, nameof(file), "Cannot write to file"); using (var stream = file.CreateWriteStream()) SaveDataView(ch, saver, view, stream, keepHidden); }
/// <summary> /// Save the model to the output path. /// The method saves the loader and the transformations of dataPipe and saves optionally predictor /// and command. It also uses featureColumn, if provided, to extract feature names. /// </summary> /// <param name="env">The host environment to use.</param> /// <param name="ch">The communication channel to use.</param> /// <param name="output">The output file handle.</param> /// <param name="predictor">The predictor.</param> /// <param name="data">The training examples.</param> /// <param name="command">The command string.</param> public static void SaveModel(IHostEnvironment env, IChannel ch, IFileHandle output, IPredictor predictor, RoleMappedData data, string command = null) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(ch, nameof(ch)); ch.CheckParam(output != null && output.CanWrite, nameof(output)); ch.CheckValueOrNull(predictor); ch.CheckValue(data, nameof(data)); ch.CheckValueOrNull(command); using (var stream = output.CreateWriteStream()) SaveModel(env, ch, stream, predictor, data, command); }
/// <summary> /// Saves <paramref name="loader"/> to the specified <paramref name="file"/>. /// </summary> public static void SaveLoader(IDataLoader loader, IFileHandle file) { Contracts.CheckValue(loader, nameof(loader)); Contracts.CheckValue(file, nameof(file)); Contracts.CheckParam(file.CanWrite, nameof(file), "Must be writable"); using (var stream = file.CreateWriteStream()) using (var rep = RepositoryWriter.CreateNew(stream)) { ModelSaveContext.SaveModel(rep, loader, ModelFileUtils.DirDataLoaderModel); rep.Commit(); } }