Skip to content

Commit 6d62a39

Browse files
authored
Merge pull request #9 from neph1/update-v1.8.0
add batch size
2 parents 0ee29a6 + 5eedb70 commit 6d62a39

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

sd_render/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ class StableDiffusionProperties(PropertyGroup):
150150
description="Height of the reference image (depth map)",
151151
default=512
152152
)
153+
number_batches: IntProperty(
154+
name="Batch size",
155+
description="How many images to render in a batch",
156+
default=1
157+
)
153158
bake_texture: BoolProperty(
154159
name="Bake texture to object",
155160
description="Bake the generated image to the selected object",
@@ -306,6 +311,7 @@ def draw_generation_settings(layout, generate_image_properties):
306311
layout.prop(generate_image_properties, "cn_end")
307312
layout.prop(generate_image_properties, "ref_image_width")
308313
layout.prop(generate_image_properties, "ref_image_height")
314+
layout.prop(generate_image_properties, "number_batches")
309315
layout.separator()
310316
layout.label(text="Backend settings")
311317
layout.prop(generate_image_properties, "sd_address")

sd_render/generate_texture.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def render(props):
3535
cn_guidance=props.cn_guidance,
3636
depth_map=depth_map,
3737
scheduler=scheduler,
38-
model=props.model)
38+
model=props.model,
39+
cn_start=props.cn_start,
40+
cn_end=props.cn_end,
41+
number_batches=props.number_batches)
3942
if props.return_image:
4043
generator.convert_image(image_data, props.output_image_name)
4144
try:

sd_render/image_gen/automatic1111.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ class Automatic1111(ImageGeneratorBase):
1212
def __init__(self, output_folder: str, address: str = '127.0.0.1', port: int = 7860) -> None:
1313
super().__init__("/sdapi/v1/txt2img", output_folder, address, port)
1414

15-
def generate_image(self, prompt: str, depth_map: str, negative_prompt: str = "text, watermark", seed: int = 0, sampler: str = "Euler a", steps: int = 30, cfg_scale: int = 7, width: int = 512, height: int = 512, cn_weight: float = 0.7, cn_guidance: float = 1, scheduler: str = None, model: str = '') -> str:
15+
def generate_image(self, prompt: str, depth_map: str, negative_prompt: str = "text, watermark", seed: int = 0, sampler: str = "Euler a", steps: int = 30, cfg_scale: int = 7, width: int = 512, height: int = 512, cn_weight: float = 0.7, cn_guidance: float = 1, scheduler: str = None, model: str = '', cn_start: float = 0.0, cn_end: float = 1.0, number_batches: int = 1) -> str:
1616
if model:
1717
self.set_model(model)
18-
image_data = self.send_request(prompt, depth_map, negative_prompt, seed, sampler, steps, cfg_scale, width, height, cn_weight, cn_guidance)
18+
image_data = self.send_request(prompt, depth_map, negative_prompt, seed, sampler, steps, cfg_scale, width, height, cn_weight, cn_guidance, number_batches=number_batches)
1919
return image_data
2020

2121

22-
def send_request(self, prompt, depth_map, negative_prompt: str, seed: int, sampler: str, steps: int, cfg_scale: int, width: int, height: int, cn_weight: float, cn_guidance: float) -> bytes:
22+
def send_request(self, prompt, depth_map, negative_prompt: str, seed: int, sampler: str, steps: int, cfg_scale: int, width: int, height: int, cn_weight: float, cn_guidance: float, number_batches: int) -> bytes:
2323

2424
data = {
2525
"prompt": prompt,
2626
"negative_prompt": negative_prompt,
2727
"alwayson_scripts": {},
2828
"seed": seed,
2929
"sampler_index": sampler,
30-
"batch_size": 1,
30+
"batch_size": number_batches,
3131
"n_iter": 1,
3232
"steps": steps,
3333
"cfg_scale": cfg_scale,

sd_render/image_gen/base_gen.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def __init__(self, endpoint: str, output_folder:str, address: str = 'localhost',
1313
self.url = f"http://{self.address}:{self.port}"
1414
self.output_folder = output_folder
1515

16+
def generate_image(self, prompt: str, depth_map: str, negative_prompt: str = "text, watermark", seed: int = 0, sampler: str = "Euler a", steps: int = 30, cfg_scale: int = 7, width: int = 512, height: int = 512, cn_weight: float = 0.7, cn_guidance: float = 1, scheduler: str = None, model: str = '', cn_start: float = 0.0, cn_end: float = 1.0, number_batches: int = 1) -> str:
17+
pass
18+
1619
def convert_image(self, image_data: bytes, image_name):
1720
try:
1821
decoded_data = base64.b64decode(image_data)

sd_render/image_gen/comfy_ui.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ def __init__(self, output_folder: str, address: str = '127.0.0.1', port: int = 8
1717
super().__init__("/prompt", output_folder, address, port)
1818
self.workflow = workflow
1919

20-
def generate_image(self, prompt: str, depth_map: str, negative_prompt: str = "text, watermark", seed: int = -1, sampler: str = "euler", steps: int = 30, cfg_scale: float = 7, width: int = 512, height: int = 512, cn_weight: float = 0.7, cn_guidance: float = 1, scheduler: str = '', model: str = '', cn_start: float = 0.0, cn_end: float = 1.0) -> str:
20+
def generate_image(self, prompt: str, depth_map: str, negative_prompt: str = "text, watermark", seed: int = -1, sampler: str = "euler", steps: int = 30, cfg_scale: float = 7, width: int = 512, height: int = 512, cn_weight: float = 0.7, cn_guidance: float = 1, scheduler: str = '', model: str = '', cn_start: float = 0.0, cn_end: float = 1.0, number_batches: int = 1) -> str:
2121
"""Generate an image from text."""
22-
image_data = self.send_request(prompt, depth_map, negative_prompt, seed, sampler, steps, cfg_scale, width, height, cn_weight, cn_guidance, scheduler, model, cn_start, cn_end)
22+
image_data = self.send_request(prompt, depth_map, negative_prompt, seed, sampler, steps, cfg_scale, width, height, cn_weight, cn_guidance, scheduler, model, cn_start, cn_end, number_batches)
2323
if not image_data:
2424
return None
2525
return image_data[0]
2626

2727

28-
def send_request(self, prompt, depth_map, negative_prompt: str, seed: int, sampler: str, steps: int, cfg_scale: int, width: int, height: int, cn_weight: float, cn_guidance: float, scheduler: str = '', model: str = '', cn_start: float = 1.0, cn_end: float = 1.0) -> bytes:
28+
def send_request(self, prompt, depth_map, negative_prompt: str, seed: int, sampler: str, steps: int, cfg_scale: int, width: int, height: int, cn_weight: float, cn_guidance: float, scheduler: str = '', model: str = '', cn_start: float = 1.0, cn_end: float = 1.0, number_batches: int = 1) -> bytes:
2929

3030
path = self._load_workflow(self.workflow)
3131
with open(path) as f:
@@ -44,7 +44,7 @@ def send_request(self, prompt, depth_map, negative_prompt: str, seed: int, sampl
4444
workflow = self._set_text_prompts(workflow, prompt, negative_prompt)
4545

4646
workflow = self._set_sampler(workflow, sampler, cfg_scale, seed, steps, scheduler)
47-
workflow = self._set_image_size(workflow, width, height)
47+
workflow = self._set_image_size(workflow, width, height, number_batches)
4848

4949
p = {"prompt": workflow}
5050
data = json.dumps(p)
@@ -126,9 +126,10 @@ def _set_sampler(self, data: dict, sampler: str, cfg: float, seed: int, steps: i
126126
data["3"]["inputs"]["scheduler"] = scheduler
127127
return data
128128

129-
def _set_image_size(self, data: dict, width: int = 512, height: int = 512) -> dict:
129+
def _set_image_size(self, data: dict, width: int = 512, height: int = 512, batch_size: int = 1) -> dict:
130130
data["5"]["inputs"]["width"] = width
131131
data["5"]["inputs"]["height"] = height
132+
data["5"]["inputs"]["batch_size"] = batch_size
132133
return data
133134

134135
def _set_control_net(self, data:dict, depth_map: str, weight: float, guidance: float, start: float, end: float) -> dict:

0 commit comments

Comments
 (0)