Пример #1
0
        /// <summary>
        /// Render the effect to the target surface - we render everything here and ignore tiling
        /// </summary>
        /// <param name="renderRects">Tiles to render (ignored here)</param>
        /// <param name="startIndex">Start index into rects (ignored here)</param>
        /// <param name="length">Number of rects to render (ignored here)</param>
        protected override void OnRender(Rectangle[] renderRects, int startIndex, int length)
        {
            if (graph.CanRun && Token.Properties.IsValid && IsRenderingEnabled)
            {
                var progressInfo = GetProgressInfo();

                if (tileSize > 0)
                {
                    var tileFormat = StringResources.Get("TileInfoFormat");
                    var renderer   = new TiledRenderer(SrcArgs.Surface, DstArgs.Surface, tileSize, MARGIN);
                    renderer.Update += UpdateTiled;
                    renderer.Process(graph);

                    void UpdateTiled(object sender, TileEventArgs e)
                    {
                        var info = StringResources.Get("GraphEvent." + e.What.ToString());
                        var tile = string.Format(CultureInfo.InvariantCulture, tileFormat, e.TileNumber, e.TileCount);

                        progressInfo(tile + " " + info);
                    }
                }
                else
                {
                    graph.Update += UpdateGraph;
                    var result = graph.Run();
                    graph.Update -= UpdateGraph;
                    result.ToSurface(DstArgs.Surface);

                    void UpdateGraph(object sender, EffectGraphEventArgs e)
                    {
                        progressInfo(StringResources.Get("GraphEvent." + e.What.ToString()));
                    }
                }

                mustCallOnRender = false;
            }
        }
Пример #2
0
        public void CanRunCompatibleModel()
        {
            using (var provider = new ModelProvider(load: true))
            {
                var graph    = new EffectGraph(provider);
                var assembly = typeof(EffectGraphTest).Assembly;

                using (var bitmap = new Bitmap(assembly.GetManifestResourceStream(GetType(), "resources.style.png")))
                {
                    graph.Params.Style = bitmap.ToTensor();
                }

                using (var bitmap = new Bitmap(assembly.GetManifestResourceStream(GetType(), "resources.content.png")))
                {
                    graph.Params.Content = bitmap.ToTensor();
                }

                var result = graph.Run();
                Assert.IsNotNull(result);
                Assert.AreEqual(graph.Params.Content.Length, result.Length);
                CollectionAssert.AreEqual(graph.Params.Content.Dimensions.ToArray(),
                                          result.Dimensions.ToArray());
            }
        }
Пример #3
0
        public void CanRunCompatibleModel()
        {
            using (var graph = new EffectGraph())
            {
                var assembly = typeof(EffectGraphTest).Assembly;
                using (var stream = assembly.GetManifestResourceStream(GetType(), "resources.style_mobilenet.onnx"))
                {
                    var model = new byte[stream.Length];
                    stream.Read(model, 0, model.Length);
                    graph.Style.Load(model);
                }

                using (var stream = assembly.GetManifestResourceStream(GetType(), "resources.transformer_separable.onnx"))
                {
                    var model = new byte[stream.Length];
                    stream.Read(model, 0, model.Length);
                    graph.Transformer.Load(model);
                }

                using (var bitmap = new Bitmap(assembly.GetManifestResourceStream(GetType(), "resources.style.png")))
                {
                    graph.Params.Style = bitmap.ToTensor();
                }

                using (var bitmap = new Bitmap(assembly.GetManifestResourceStream(GetType(), "resources.content.png")))
                {
                    graph.Params.Content = bitmap.ToTensor();
                }

                var result = graph.Run();
                Assert.IsNotNull(result);
                Assert.AreEqual(graph.Params.Content.Length, result.Length);
                CollectionAssert.AreEqual(graph.Params.Content.Dimensions.ToArray(),
                                          result.Dimensions.ToArray());
            }
        }