internal PredictorModelImpl(IHostEnvironment env, RoleMappedData trainingData, IDataView startingData, IPredictor predictor) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(trainingData, nameof(trainingData)); env.CheckValue(predictor, nameof(predictor)); TransformModel = new TransformModelImpl(env, trainingData.Data, startingData); _roleMappings = trainingData.Schema.GetColumnRoleNames().ToArray(); Predictor = predictor; }
internal PredictorModelImpl(IHostEnvironment env, Stream stream) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(stream, nameof(stream)); using (var ch = env.Start("Loading predictor model")) { // REVIEW: address the asymmetry in the way we're loading and saving the model. TransformModel = new TransformModelImpl(env, stream); var roles = ModelFileUtils.LoadRoleMappingsOrNull(env, stream); env.CheckDecode(roles != null, "Predictor model must contain role mappings"); _roleMappings = roles.ToArray(); Predictor = ModelFileUtils.LoadPredictorOrNull(env, stream); env.CheckDecode(Predictor != null, "Predictor model must contain a predictor"); } }
public void SetInputFromPath(GraphRunner runner, string varName, string path, TlcModule.DataKind kind) { _host.CheckUserArg(runner != null, nameof(runner), "Provide a GraphRunner instance."); _host.CheckUserArg(!string.IsNullOrWhiteSpace(varName), nameof(varName), "Specify a graph variable name."); _host.CheckUserArg(!string.IsNullOrWhiteSpace(path), nameof(path), "Specify a valid file path."); switch (kind) { case TlcModule.DataKind.FileHandle: var fh = new SimpleFileHandle(_host, path, false, false); runner.SetInput(varName, fh); break; case TlcModule.DataKind.DataView: IDataView loader = new BinaryLoader(_host, new BinaryLoader.Arguments(), path); runner.SetInput(varName, loader); break; case TlcModule.DataKind.PredictorModel: PredictorModelImpl pm; using (var fs = File.OpenRead(path)) pm = new PredictorModelImpl(_host, fs); runner.SetInput(varName, pm); break; case TlcModule.DataKind.TransformModel: TransformModelImpl tm; using (var fs = File.OpenRead(path)) tm = new TransformModelImpl(_host, fs); runner.SetInput(varName, tm); break; default: throw _host.Except("Port type {0} not supported", kind); } }