From dfadf49739f57dd93f866a1ef6815e753324eecd Mon Sep 17 00:00:00 2001 From: Danamir Date: Thu, 18 May 2023 00:31:47 +0200 Subject: [PATCH 1/2] Add ControlNet tile model handling to img2img and inpaint modes --- src/GenerateTab.vue | 61 +++++++++++++++++++++++++++++++++++++++ src/maskGeneratorMixin.js | 24 +++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/src/GenerateTab.vue b/src/GenerateTab.vue index e38e629..c79ffcd 100644 --- a/src/GenerateTab.vue +++ b/src/GenerateTab.vue @@ -197,6 +197,51 @@ +
+ ControlNet mode + + + {{ cnM }} + +
+ + + + Weight + {{ cnWeight/100 }} + + + + + + Guidance start + {{ cnGuidanceStart/100 }} + + + + + + Guidance end + {{ cnGuidanceEnd/100 }} + + +
Save generated images locally @@ -287,6 +332,13 @@ export default { imagesNumber: 4, styles: [], + cnModes: ['disabled', 'tile'], + cnMode: 'disabled', + cnWeight: 100, + cnGuidanceStart: 0, + cnGuidanceEnd: 100, + cnModel: 'control_v11f1e_sd15_tile_fp16', + generatedImages: [], currentGeneratedImageIndex: 0, currentLayerId: null, @@ -398,7 +450,11 @@ export default { this.currentSampler = storage.localStorage.getItem('currentSampler') || this.currentSampler; this.imagesNumber = storage.localStorage.getItem('imagesNumber') || this.imagesNumber; this.currentMode = storage.localStorage.getItem('currentMode') || this.currentMode; + this.denoisingStrength = storage.localStorage.getItem('denoisingStrength') || this.denoisingStrength; this.isSaveImagesLocally = storage.localStorage.getItem('isSaveImagesLocally') || this.isSaveImagesLocally; + this.cnWeight = storage.localStorage.getItem('cnWeight') || this.cnWeight; + this.cnGuidanceStart = storage.localStorage.getItem('cnGuidanceStart') || this.cnGuidanceStart; + this.cnGuidanceEnd = storage.localStorage.getItem('cnGuidanceEnd') || this.cnGuidanceEnd; this.getTempAndDataFolders(); @@ -596,6 +652,11 @@ export default { } let resDataImages = res.data.images; + + if (this.cnMode !== 'disabled') { + resDataImages.pop(); // last image is controlNet input image + } + if (this.isSaveImagesLocally) { await this.saveGeneratedImagesLocally(resDataImages, JSON.parse(res.data.info).all_seeds); } diff --git a/src/maskGeneratorMixin.js b/src/maskGeneratorMixin.js index 3112eea..a43a39f 100644 --- a/src/maskGeneratorMixin.js +++ b/src/maskGeneratorMixin.js @@ -139,6 +139,10 @@ export default { storage.localStorage.setItem('currentSampler', this.currentSampler); storage.localStorage.setItem('imagesNumber', this.imagesNumber); storage.localStorage.setItem('currentMode', this.currentMode); + storage.localStorage.setItem('denoisingStrength', this.denoisingStrength); + storage.localStorage.setItem('cnWeight', this.cnWeight); + storage.localStorage.setItem('cnGuidanceStart', this.cnGuidanceStart); + storage.localStorage.setItem('cnGuidanceEnd', this.cnGuidanceEnd); this.updateProgress(); @@ -180,8 +184,28 @@ export default { override_settings: {}, sampler_index: this.currentSampler, include_init_images: false, + alwayson_scripts: {}, }; + if (this.imagesNumber > 1 && img2imgData.prompt === '') { + img2imgData.prompt = 'prompt'; // fake prompt to avoid batch crash + } + + if (this.cnMode === 'tile') { + img2imgData.alwayson_scripts.controlnet = { + args: [ + { + weight: this.cnWeight / 100, + guidance_start: this.cnGuidanceStart / 100, + guidance_end: this.cnGuidanceEnd / 100, + module: undefined, + pixel_perfect: false, + model: this.cnModel, + }, + ], + }; + } + await this.sendData(img2imgData, 'img2img'); } From b20fa5574a058f03b9f9c0e452e4c3624dbcdab7 Mon Sep 17 00:00:00 2001 From: Danamir Date: Thu, 18 May 2023 02:11:04 +0200 Subject: [PATCH 2/2] Added support for ControlNet lineart, scribble, and openpose (face only or full) --- src/GenerateTab.vue | 25 ++++++++++++++++++++----- src/maskGeneratorMixin.js | 8 ++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/GenerateTab.vue b/src/GenerateTab.vue index c79ffcd..a04e6eb 100644 --- a/src/GenerateTab.vue +++ b/src/GenerateTab.vue @@ -332,12 +332,27 @@ export default { imagesNumber: 4, styles: [], - cnModes: ['disabled', 'tile'], + cnModes: ['disabled', 'tile', 'openface', 'openpose', 'lineart', 'scribble'], cnMode: 'disabled', cnWeight: 100, cnGuidanceStart: 0, cnGuidanceEnd: 100, - cnModel: 'control_v11f1e_sd15_tile_fp16', + cnModules: { + disabled: undefined, + tile: undefined, + lineart: 'lineart_coarse', + openpose: 'openpose_full', + openface: 'openpose_faceonly', + scribble: 'pidinet_sketch', + }, + cnModels: { + disabled: undefined, + tile: 'control_v11f1e_sd15_tile_fp16', + lineart: 'control_v11p_sd15_lineart_fp16', + openpose: 'control_v11p_sd15_openpose_fp16', + openface: 'control_v11p_sd15_openpose_fp16', + scribble: 'control_v11p_sd15_scribble_fp16', + }, generatedImages: [], currentGeneratedImageIndex: 0, @@ -653,9 +668,9 @@ export default { let resDataImages = res.data.images; - if (this.cnMode !== 'disabled') { - resDataImages.pop(); // last image is controlNet input image - } + // if (this.cnMode !== 'disabled') { + // resDataImages.pop(); // last image is controlNet input image + // } if (this.isSaveImagesLocally) { await this.saveGeneratedImagesLocally(resDataImages, JSON.parse(res.data.info).all_seeds); diff --git a/src/maskGeneratorMixin.js b/src/maskGeneratorMixin.js index a43a39f..a11bc41 100644 --- a/src/maskGeneratorMixin.js +++ b/src/maskGeneratorMixin.js @@ -191,16 +191,16 @@ export default { img2imgData.prompt = 'prompt'; // fake prompt to avoid batch crash } - if (this.cnMode === 'tile') { + if (this.cnMode !== 'disabled') { img2imgData.alwayson_scripts.controlnet = { args: [ { weight: this.cnWeight / 100, guidance_start: this.cnGuidanceStart / 100, guidance_end: this.cnGuidanceEnd / 100, - module: undefined, - pixel_perfect: false, - model: this.cnModel, + module: this.cnModules[this.cnMode], + pixel_perfect: true, + model: this.cnModels[this.cnMode], }, ], };