From abd757fd3080da313888f6d5907886091104bd08 Mon Sep 17 00:00:00 2001 From: Diego Porres Date: Mon, 26 Jun 2023 14:12:31 +0200 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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() #---------------------------------------------------------------------------- From f6e94f9664f69816db05e9d57c58b65b7bfe06c7 Mon Sep 17 00:00:00 2001 From: Kelvin Clien <99217852+bulutthecat@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:47:46 -0400 Subject: [PATCH 6/8] added windows GUI bat file --- scripts/gui.bat | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 scripts/gui.bat diff --git a/scripts/gui.bat b/scripts/gui.bat new file mode 100644 index 0000000..d0ad247 --- /dev/null +++ b/scripts/gui.bat @@ -0,0 +1,12 @@ +@echo off +python visualizer_drag.py ^ + checkpoints/stylegan2_lions_512_pytorch.pkl ^ + checkpoints/stylegan2-ffhq-512x512.pkl ^ + checkpoints/stylegan2-afhqcat-512x512.pkl ^ + checkpoints/stylegan2-car-config-f.pkl ^ + checkpoints/stylegan2_dogs_1024_pytorch.pkl ^ + checkpoints/stylegan2_horses_256_pytorch.pkl ^ + checkpoints/stylegan2-cat-config-f.pkl ^ + checkpoints/stylegan2_elephants_512_pytorch.pkl ^ + checkpoints/stylegan_human_v2_512.pkl ^ + checkpoints/stylegan2-lhq-256x256.pkl From 9059a77f8e92eb477e2f80de9c61c060c9ae9140 Mon Sep 17 00:00:00 2001 From: Kelvin Clien <99217852+bulutthecat@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:49:00 -0400 Subject: [PATCH 7/8] Update requirements.txt added - imgui - glfw - pyopengl (all requirements for GUI) --- requirements.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 177fdde..e71044d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,7 @@ torchvision Ninja gradio huggingface_hub -hf_transfer \ No newline at end of file +hf_transfer +pyopengl +imgui +glfw From ed7586f73d4049951255439dfd1f2c39fbadb079 Mon Sep 17 00:00:00 2001 From: Ari <40615493+ariym@users.noreply.github.com> Date: Mon, 26 Jun 2023 15:43:03 -0400 Subject: [PATCH 8/8] Update README.md Made requirements link go directly to instructions section of README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5593ee4..dd054b6 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ ## Requirements -Please follow the requirements of [https://github.com/NVlabs/stylegan3](https://github.com/NVlabs/stylegan3). +Please follow the requirements of [NVlabs/stylegan3](https://github.com/NVlabs/stylegan3#requirements). ## Download pre-trained StyleGAN2 weights