From 0bb676ca048fcec00de0d79d6cee20ef1cb75087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ant=C3=B4nio=20de=20Ara=C3=BAjo?= Date: Sat, 6 May 2023 17:24:30 -0300 Subject: [PATCH] release pipeline when release the model (#38) --- python_stuff/models/models.py | 5 ++--- src/controls/image_panel.cpp | 16 ++++++++++++++++ src/controls/image_panel.h | 2 +- src/windows/diffusion_tool.cpp | 13 ++++++++----- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/python_stuff/models/models.py b/python_stuff/models/models.py index 3cd2617..6b846eb 100644 --- a/python_stuff/models/models.py +++ b/python_stuff/models/models.py @@ -22,14 +22,15 @@ CURRENT_MODEL_PARAMS = {} CURRENT_PIPELINE = {} -CURRENT_VAR_PIPELINE = {} # if the model does not load see: https://github.com/d8ahazard/sd_dreambooth_extension/discussions/794 def load_model(model_path: str): global CURRENT_MODEL_PARAMS + global CURRENT_PIPELINE if CURRENT_MODEL_PARAMS.get('path', '') != model_path: CURRENT_MODEL_PARAMS = {} + CURRENT_PIPELINE = {} gc.collect() params, in_painting = load_stable_diffusion_model(model_path) CURRENT_MODEL_PARAMS = { @@ -47,7 +48,6 @@ def load_model(model_path: str): def create_pipeline(mode: str, model_path: str, controlnets = None): global CURRENT_PIPELINE - global CURRENT_VAR_PIPELINE load_model(model_path) controlnet_modes = sorted([f["mode"] for f in (controlnets or [])]) if CURRENT_PIPELINE.get("model_path") != model_path or \ @@ -105,7 +105,6 @@ def create_pipeline(mode: str, model_path: str, controlnets = None): 'pipeline': pipe, 'contronet': controlnet_modes } - CURRENT_VAR_PIPELINE = {} gc.collect() return CURRENT_PIPELINE['pipeline'] diff --git a/src/controls/image_panel.cpp b/src/controls/image_panel.cpp index 19d0f49..a359132 100644 --- a/src/controls/image_panel.cpp +++ b/src/controls/image_panel.cpp @@ -671,6 +671,10 @@ namespace dexpert } void ImagePanel::resizeLeft(int value) { + if (images_[image_type_paste]) { + show_error("Can not resize with floating image"); + return; // wait the user to decide what he's going to do with the floating image + } for (int i = 0; i < image_type_count; i++) { if (images_[i]) { images_[i] = images_[i]->resizeLeft(value); @@ -688,6 +692,10 @@ namespace dexpert } void ImagePanel::resizeRight(int value) { + if (images_[image_type_paste]) { + show_error("Can not resize with floating image"); + return; // wait the user to decide what he's going to do with the floating image + } for (int i = 0; i < image_type_count; i++) { if (images_[i]) { images_[i] = images_[i]->resizeRight(value); @@ -705,6 +713,10 @@ namespace dexpert } void ImagePanel::resizeBottom(int value) { + if (images_[image_type_paste]) { + show_error("Can not resize with floating image"); + return; // wait the user to decide what he's going to do with the floating image + } for (int i = 0; i < image_type_count; i++) { if (images_[i]) { images_[i] = images_[i]->resizeBottom(value); @@ -722,6 +734,10 @@ namespace dexpert } void ImagePanel::resizeTop(int value) { + if (images_[image_type_paste]) { + show_error("Can not resize with floating image"); + return; // wait the user to decide what he's going to do with the floating image + } for (int i = 0; i < image_type_count; i++) { if (images_[i]) { images_[i] = images_[i]->resizeTop(value); diff --git a/src/controls/image_panel.h b/src/controls/image_panel.h index 3939443..d8b0bc9 100644 --- a/src/controls/image_panel.h +++ b/src/controls/image_panel.h @@ -20,6 +20,7 @@ typedef enum { image_tool_drag, image_tool_select, image_tool_brush, + // image_tool_smudge, // keep image_tool_count at the end image_tool_count } image_tool_t; @@ -40,7 +41,6 @@ typedef enum { edit_type_paste, edit_type_controlnet, // the user can change the controlnet image edit_type_mask, // the user can change the mask - // keep edit_type_count at the end. edit_type_count } edit_type_t; diff --git a/src/windows/diffusion_tool.cpp b/src/windows/diffusion_tool.cpp index c5ea377..9fa3d1c 100644 --- a/src/windows/diffusion_tool.cpp +++ b/src/windows/diffusion_tool.cpp @@ -3,6 +3,7 @@ #include "src/python/helpers.h" #include "src/config/config.h" #include "src/stable_diffusion/state.h" +#include "src/dialogs/common_dialogs.h" #include "src/windows/diffusion_tool.h" @@ -72,8 +73,12 @@ void DiffusionTool::initToolbar() { this->hide(); })); confirmBtn_.reset(new Button(xpm::image(xpm::button_ok_16x16), [this] { - confirmed_ = true; - this->hide(); + if (pages_->getInputImage()) { + confirmed_ = true; + this->hide(); + } else { + show_error("Generate an image and select it first!"); + } })); consoleBtn_.reset(new Button(xpm::image(xpm::lupe_16x16), [this] { showConsoles("Console windows", true); @@ -177,7 +182,7 @@ image_ptr_t DiffusionTool::run() { while (this->shown()) { Fl::wait(0.001); } - RawImage *img = pages_->getInputImage(); + RawImage *img = confirmed_ ? pages_->getInputImage() : NULL; if (img) { return img->duplicate(); } @@ -186,10 +191,8 @@ image_ptr_t DiffusionTool::run() { void DiffusionTool::setInitialImage(RawImage *image) { if (!image) { - confirmBtn_->hide(); return; } - confirmBtn_->show(); pages_->setInputImage(image); page_browser_->value(pages_->getIndexAtPage(pages_->activePage())); gotoSelectedPage();