From abd757fd3080da313888f6d5907886091104bd08 Mon Sep 17 00:00:00 2001 From: Diego Porres Date: Mon, 26 Jun 2023 14:12:31 +0200 Subject: [PATCH 1/5] Ignore the fourth channel/mask when saving an image The renderer returns a RGBA image, just save the first 3 channels to correctly save the image of the resulting edits. --- viz/capture_widget.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/viz/capture_widget.py b/viz/capture_widget.py index 48e1373..a63be95 100644 --- a/viz/capture_widget.py +++ b/viz/capture_widget.py @@ -31,7 +31,6 @@ def dump_png(self, image): viz = self.viz try: _height, _width, channels = image.shape - assert channels in [1, 3] assert image.dtype == np.uint8 os.makedirs(self.path, exist_ok=True) file_id = 0 @@ -43,7 +42,7 @@ def dump_png(self, image): if channels == 1: pil_image = PIL.Image.fromarray(image[:, :, 0], 'L') else: - pil_image = PIL.Image.fromarray(image, 'RGB') + pil_image = PIL.Image.fromarray(image[:, :, :3], 'RGB') pil_image.save(os.path.join(self.path, f'{file_id:05d}.png')) except: viz.result.error = renderer.CapturedException() From 948327cbf0698c0a3c53b9f8f7a4975d9bf8d11c Mon Sep 17 00:00:00 2001 From: Diego Porres Date: Mon, 26 Jun 2023 14:17:06 +0200 Subject: [PATCH 2/5] Remove code Removing these lines of code lets the GUI run and so far no bugs have been detected. --- visualizer_drag.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/visualizer_drag.py b/visualizer_drag.py index 9120906..e63ff62 100644 --- a/visualizer_drag.py +++ b/visualizer_drag.py @@ -177,9 +177,9 @@ def draw_frame(self): if self.result.init_net: self.drag_widget.reset_point() - if self.check_update_mask(**self.args): - h, w, _ = self.result.image.shape - self.drag_widget.init_mask(w, h) + # if self.check_update_mask(**self.args): + # h, w, _ = self.result.image.shape + # self.drag_widget.init_mask(w, h) # Display. max_w = self.content_width - self.pane_w From 9b7e474f26ddf34d58d45e430bf6c66bae153d19 Mon Sep 17 00:00:00 2001 From: Diego Porres Date: Mon, 26 Jun 2023 14:49:40 +0200 Subject: [PATCH 3/5] Save resulting latent After editing, when saving the image, you also save the resulting latent for continuing working on it later on (or e.g. generate interpolations) --- viz/capture_widget.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/viz/capture_widget.py b/viz/capture_widget.py index a63be95..72bf3cf 100644 --- a/viz/capture_widget.py +++ b/viz/capture_widget.py @@ -31,6 +31,7 @@ def dump_png(self, image): viz = self.viz try: _height, _width, channels = image.shape + print(viz.result) assert image.dtype == np.uint8 os.makedirs(self.path, exist_ok=True) file_id = 0 @@ -44,6 +45,7 @@ def dump_png(self, image): else: pil_image = PIL.Image.fromarray(image[:, :, :3], 'RGB') pil_image.save(os.path.join(self.path, f'{file_id:05d}.png')) + np.save(os.path.join(self.path, f'{file_id:05d}.npy'), viz.result.w) except: viz.result.error = renderer.CapturedException() From b76c49a2241c53c06ef385431b55485dbf8a5a42 Mon Sep 17 00:00:00 2001 From: Diego Porres Date: Mon, 26 Jun 2023 14:50:22 +0200 Subject: [PATCH 4/5] Save resulting latent After editing, when saving the image, you also save the resulting latent for continuing working on it later on (or e.g. generate interpolations) --- viz/renderer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/viz/renderer.py b/viz/renderer.py index ed81697..1d2ad6c 100644 --- a/viz/renderer.py +++ b/viz/renderer.py @@ -382,5 +382,6 @@ def _render_drag_impl(self, res, img = img.cpu().numpy() img = Image.fromarray(img) res.image = img + res.w = ws.cpu().numpy() #---------------------------------------------------------------------------- From 28a3e171a872794f4ee101d10c24f16461e1bd61 Mon Sep 17 00:00:00 2001 From: Diego Porres Date: Mon, 26 Jun 2023 17:30:44 +0000 Subject: [PATCH 5/5] Actual fixes for resetting mask and saving w. --- visualizer_drag.py | 9 +++++---- viz/renderer.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/visualizer_drag.py b/visualizer_drag.py index e63ff62..b016bcc 100644 --- a/visualizer_drag.py +++ b/visualizer_drag.py @@ -177,15 +177,16 @@ def draw_frame(self): if self.result.init_net: self.drag_widget.reset_point() - # if self.check_update_mask(**self.args): - # h, w, _ = self.result.image.shape - # self.drag_widget.init_mask(w, h) - # Display. max_w = self.content_width - self.pane_w max_h = self.content_height pos = np.array([self.pane_w + max_w / 2, max_h / 2]) if 'image' in self.result: + # Reset mask after loading a new pickle or changing seed. + if self.check_update_mask(**self.args): + h, w, _ = self.result.image.shape + self.drag_widget.init_mask(w, h) + if self._tex_img is not self.result.image: self._tex_img = self.result.image if self._tex_obj is None or not self._tex_obj.is_compatible(image=self._tex_img): diff --git a/viz/renderer.py b/viz/renderer.py index 1d2ad6c..aa43bf9 100644 --- a/viz/renderer.py +++ b/viz/renderer.py @@ -382,6 +382,6 @@ def _render_drag_impl(self, res, img = img.cpu().numpy() img = Image.fromarray(img) res.image = img - res.w = ws.cpu().numpy() + res.w = ws.detach().cpu().numpy() #----------------------------------------------------------------------------