Beispiel #1
0
        public void TestEstimatorSaveLoad()
        {
            using (var env = new ConsoleEnvironment())
            {
                var dataFile    = GetDataPath("images/images.tsv");
                var imageFolder = Path.GetDirectoryName(dataFile);
                var data        = env.CreateLoader("Text{col=ImagePath:TX:0 col=Name:TX:1}", new MultiFileSource(dataFile));

                var pipe = new ImageLoaderEstimator(env, imageFolder, ("ImagePath", "ImageReal"))
                           .Append(new ImageResizerEstimator(env, "ImageReal", "ImageReal", 100, 100))
                           .Append(new ImagePixelExtractorEstimator(env, "ImageReal", "ImagePixels"))
                           .Append(new ImageGrayscaleEstimator(env, ("ImageReal", "ImageGray")));

                pipe.GetOutputSchema(Core.Data.SchemaShape.Create(data.Schema));
                var model = pipe.Fit(data);

                using (var file = env.CreateTempFile())
                {
                    using (var fs = file.CreateWriteStream())
                        model.SaveTo(env, fs);
                    var model2 = TransformerChain.LoadFrom(env, file.OpenReadStream());

                    var newCols = ((ImageLoaderTransform)model2.First()).Columns;
                    var oldCols = ((ImageLoaderTransform)model.First()).Columns;
                    Assert.True(newCols
                                .Zip(oldCols, (x, y) => x == y)
                                .All(x => x));
                }
            }
            Done();
        }
        public void TestEstimatorChain()
        {
            using (var env = new ConsoleEnvironment())
            {
                var dataFile    = GetDataPath("images/images.tsv");
                var imageFolder = Path.GetDirectoryName(dataFile);
                var data        = TextLoader.Create(env, new TextLoader.Arguments()
                {
                    Column = new[]
                    {
                        new TextLoader.Column("ImagePath", DataKind.TX, 0),
                        new TextLoader.Column("Name", DataKind.TX, 1),
                    }
                }, new MultiFileSource(dataFile));
                var invalidData = TextLoader.Create(env, new TextLoader.Arguments()
                {
                    Column = new[]
                    {
                        new TextLoader.Column("ImagePath", DataKind.R4, 0),
                    }
                }, new MultiFileSource(dataFile));

                var pipe = new ImageLoaderEstimator(env, imageFolder, ("ImagePath", "ImageReal"))
                           .Append(new ImageResizerEstimator(env, "ImageReal", "ImageReal", 100, 100))
                           .Append(new ImagePixelExtractorEstimator(env, "ImageReal", "ImagePixels"))
                           .Append(new ImageGrayscaleEstimator(env, ("ImageReal", "ImageGray")));

                TestEstimatorCore(pipe, data, null, invalidData);
            }
            Done();
        }
Beispiel #3
0
        public void TestEstimatorChain()
        {
            using (var env = new ConsoleEnvironment())
            {
                var dataFile    = GetDataPath("images/images.tsv");
                var imageFolder = Path.GetDirectoryName(dataFile);
                var data        = env.CreateLoader("Text{col=ImagePath:TX:0 col=Name:TX:1}", new MultiFileSource(dataFile));
                var invalidData = env.CreateLoader("Text{col=ImagePath:R4:0}", new MultiFileSource(dataFile));

                var pipe = new ImageLoaderEstimator(env, imageFolder, ("ImagePath", "ImageReal"))
                           .Append(new ImageResizerEstimator(env, "ImageReal", "ImageReal", 100, 100))
                           .Append(new ImagePixelExtractorEstimator(env, "ImageReal", "ImagePixels"))
                           .Append(new ImageGrayscaleEstimator(env, ("ImageReal", "ImageGray")));

                TestEstimatorCore(pipe, data, null, invalidData);
            }
            Done();
        }