public StylizePage() : base() { _stylizeGraph = new StylizeGraph(); _stylizeGraph.OnDownloadProgressChanged += onDownloadProgressChanged; _stylizeGraph.OnDownloadCompleted += onDownloadCompleted; OnImagesLoaded += (sender, image) => { try { SetMessage("Please wait..."); SetImage(); Stopwatch watch = Stopwatch.StartNew(); byte[] jpeg = _stylizeGraph.StylizeToJpeg(image[0], 1); watch.Stop(); SetImage(jpeg); #if __MACOS__ NSImage img = new NSImage(image[0]); var displayImage = this.GetImage(); displayImage.WidthRequest = img.Size.Width; displayImage.HeightRequest = img.Size.Height; #endif SetMessage(String.Format("Stylized in {0} milliseconds.", watch.ElapsedMilliseconds)); } catch (Exception excpt) { String msg = excpt.Message.Replace(System.Environment.NewLine, " "); SetMessage(msg); } }; }
public StylizePage() : base() { Title = "Stylize"; if (_stylizeGraph == null) { SessionOptions so = new SessionOptions(); if (TfInvoke.IsGoogleCudaEnabled) { Tensorflow.ConfigProto config = new Tensorflow.ConfigProto(); config.GpuOptions = new Tensorflow.GPUOptions(); config.GpuOptions.AllowGrowth = true; so.SetConfig(config.ToProtobuf()); } _stylizeGraph = new StylizeGraph(null, so); _stylizeGraph.OnDownloadProgressChanged += onDownloadProgressChanged; _stylizeGraph.OnDownloadCompleted += onDownloadCompleted; _stylizeGraph.OnDownloadCompleted += (sender, e) => { OnButtonClicked(sender, e); }; } OnImagesLoaded += (sender, image) => { try { SetMessage("Please wait..."); SetImage(); Stopwatch watch = Stopwatch.StartNew(); byte[] jpeg = _stylizeGraph.StylizeToJpeg(image[0], 1); watch.Stop(); SetImage(jpeg); #if __MACOS__ NSImage img = new NSImage(image[0]); var displayImage = this.GetImage(); displayImage.WidthRequest = img.Size.Width; displayImage.HeightRequest = img.Size.Height; #endif SetMessage(String.Format("Stylized in {0} milliseconds.", watch.ElapsedMilliseconds)); } catch (Exception excpt) { String msg = excpt.Message.Replace(System.Environment.NewLine, " "); SetMessage(msg); } }; }
async void stylizeClicked(NSObject sender) { SetMessage("Please wait while we download Stylize model from internet..."); SetImage(null); if (_stylizeGraph == null) { _stylizeGraph = new StylizeGraph(); _stylizeGraph.OnDownloadProgressChanged += OnDownloadProgressChanged; //_stylizeGraph.OnDownloadCompleted += stylizeGraph_OnDownloadCompleted; } await _stylizeGraph.Init(); SetMessage(""); byte[] jpeg = _stylizeGraph.StylizeToJpeg("surfers.jpg", 0); using (System.IO.Stream s = new System.IO.MemoryStream(jpeg)) { NSImage newImg = NSImage.FromStream(s); SetImage(newImg); } }