Skip to content

Commit

Permalink
release pipeline when release the model (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjjo authored May 6, 2023
1 parent 0ee6546 commit 0bb676c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
5 changes: 2 additions & 3 deletions python_stuff/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 \
Expand Down Expand Up @@ -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']

Expand Down
16 changes: 16 additions & 0 deletions src/controls/image_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/controls/image_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions src/windows/diffusion_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down

0 comments on commit 0bb676c

Please sign in to comment.