/// <summary> /// Loads data view (loader and transforms) from <paramref name="rep"/> if <paramref name="loadTransforms"/> is set to true, /// otherwise loads loader only. /// </summary> public static ILegacyDataLoader LoadLoader(IHostEnvironment env, RepositoryReader rep, IMultiStreamSource files, bool loadTransforms) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(rep, nameof(rep)); env.CheckValue(files, nameof(files)); ILegacyDataLoader loader; // If loadTransforms is false, load the loader only, not the transforms. Repository.Entry ent = null; string dir = ""; if (!loadTransforms) { ent = rep.OpenEntryOrNull(dir = Path.Combine(DirDataLoaderModel, "Loader"), ModelLoadContext.ModelStreamName); } if (ent == null) // either loadTransforms is true, or it's not a composite loader { ent = rep.OpenEntry(dir = DirDataLoaderModel, ModelLoadContext.ModelStreamName); } env.CheckDecode(ent != null, "Loader is not found."); env.AssertNonEmpty(dir); using (ent) { env.Assert(ent.Stream.Position == 0); ModelLoadContext.LoadModel <ILegacyDataLoader, SignatureLoadDataLoader>(env, out loader, rep, ent, dir, files); } return(loader); }
/// <summary> /// Loads and returns the loader and transforms from the specified repository reader. /// </summary> /// <param name="env">The host environment to use.</param> /// <param name="rep">The repository reader.</param> /// <param name="files">The data source to initialize the loader with.</param> /// <param name="extractInnerPipe">Whether to extract the transforms and loader from the wrapped CompositeDataLoader.</param> /// <returns>The created data view.</returns> public static IDataView LoadPipeline(IHostEnvironment env, RepositoryReader rep, IMultiStreamSource files, bool extractInnerPipe = false) { // REVIEW: Should not duplicate loading loader/transforms code. This method should call LoadLoader. Contracts.CheckValue(env, nameof(env)); env.CheckValue(rep, nameof(rep)); env.CheckValue(files, nameof(files)); var entry = rep.OpenEntryOrNull(SchemaEntryName); if (entry != null) { var loader = new BinaryLoader(env, new BinaryLoader.Arguments(), entry.Stream); ModelLoadContext.LoadModel <ITransformer, SignatureLoadModel>(env, out var transformerChain, rep, DirTransformerChain); return(transformerChain.Transform(loader)); } using (var ent = rep.OpenEntry(DirDataLoaderModel, ModelLoadContext.ModelStreamName)) { ILegacyDataLoader loader; env.Assert(ent.Stream.Position == 0); ModelLoadContext.LoadModel <ILegacyDataLoader, SignatureLoadDataLoader>(env, out loader, rep, ent, DirDataLoaderModel, files); IDataView result = loader; if (extractInnerPipe) { var cdl = loader as LegacyCompositeDataLoader; result = cdl == null ? loader : cdl.View; } return(result); } }
/// <summary> /// Loads and returns the loader and transforms from the specified repository reader. /// </summary> /// <param name="env">The host environment to use.</param> /// <param name="rep">The repository reader.</param> /// <param name="files">The data source to initialize the loader with.</param> /// <param name="extractInnerPipe">Whether to extract the transforms and loader from the wrapped CompositeDataLoader.</param> /// <returns>The created data view.</returns> public static IDataView LoadPipeline(IHostEnvironment env, RepositoryReader rep, IMultiStreamSource files, bool extractInnerPipe = false) { // REVIEW: Should not duplicate loading loader/transforms code. This method should call LoadLoader. Contracts.CheckValue(env, nameof(env)); env.CheckValue(rep, nameof(rep)); env.CheckValue(files, nameof(files)); using (var ent = rep.OpenEntry(DirDataLoaderModel, ModelLoadContext.ModelStreamName)) { IDataLoader loader; env.Assert(ent.Stream.Position == 0); ModelLoadContext.LoadModel <IDataLoader, SignatureLoadDataLoader>(env, out loader, rep, ent, DirDataLoaderModel, files); IDataView result = loader; if (extractInnerPipe) { var cdl = loader as CompositeDataLoader; result = cdl == null ? loader : cdl.View; } return(result); } }