コード例 #1
0
        public static void LoadModel(IHostEnvironment env, Stream modelStream, bool loadNames, out IPredictor predictor, out RoleMappedSchema schema)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(modelStream, nameof(modelStream));

            schema = null;
            using (var rep = RepositoryReader.Open(modelStream, env))
            {
                ModelLoadContext.LoadModel <IPredictor, SignatureLoadModel>(env, out predictor, rep, ModelFileUtils.DirPredictor);

                if (loadNames)
                {
                    var roles = ModelFileUtils.LoadRoleMappingsOrNull(env, rep);
                    if (roles != null)
                    {
                        var emptyView = ModelFileUtils.LoadPipeline(env, rep, new MultiFileSource(null));
                        schema = RoleMappedSchema.CreateOpt(emptyView.Schema, roles);
                    }
                    else
                    {
                        FeatureNameCollection names;
                        if (ModelFileUtils.TryLoadFeatureNames(out names, rep))
                        {
                            schema = names.Schema;
                        }
                    }
                }
            }
        }
コード例 #2
0
        public RoleMappedSchema GetTrainingSchema(IHostEnvironment env)
        {
            Contracts.CheckValue(env, nameof(env));
            var predInput = _transformModel.Apply(env, new EmptyDataView(env, _transformModel.InputSchema));
            var trainRms  = RoleMappedSchema.CreateOpt(predInput.Schema, _roleMappings);

            return(trainRms);
        }