Skip to content

Commit ae59b03

Browse files
committed
batch size option added
1 parent ae3e284 commit ae59b03

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

backends/stable_diffusion_tf/diffusionbee_backend.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from downloader import ProgressBarDownloader
88
import sys
99
import copy
10+
import math
1011

1112
class Unbuffered(object):
1213
def __init__(self, stream):
@@ -29,8 +30,12 @@ def __getattr__(self, attr):
2930

3031

3132
def process_opt(d, generator):
33+
34+
batch_size = int(d['batch_size'])
35+
n_imgs = math.ceil(d['num_imgs'] / batch_size)
36+
3237

33-
for i in range(d['num_imgs']):
38+
for i in range(n_imgs):
3439
if 'seed' in d:
3540
seed = d['seed']
3641
else:
@@ -41,15 +46,17 @@ def process_opt(d, generator):
4146
num_steps=d['ddim_steps'],
4247
unconditional_guidance_scale=d['scale'],
4348
temperature=1,
44-
batch_size=1,
49+
batch_size=batch_size,
4550
seed=seed,
4651
img_id=i,
4752
)
4853
if img is None:
4954
return
50-
fpath = "/tmp/%d.png"%(random.randint(0 ,100000000))
51-
Image.fromarray(img[0]).save(fpath)
52-
print("sdbk nwim %s"%(fpath) )
55+
56+
for i in range(len(img)):
57+
fpath = "/tmp/%d.png"%(random.randint(0 ,100000000))
58+
Image.fromarray(img[i]).save(fpath)
59+
print("sdbk nwim %s"%(fpath) )
5360

5461

5562
def main():
@@ -88,7 +95,7 @@ def main():
8895
generator.diffusion_model.load_weights(p1)
8996
generator.decoder.load_weights(p3)
9097

91-
default_d = { "W" : 512 , "H" : 512, "num_imgs":1 , "ddim_steps" : 25 , "scale" : 7.5 }
98+
default_d = { "W" : 512 , "H" : 512, "num_imgs":1 , "ddim_steps" : 25 , "scale" : 7.5, "batch_size":1 }
9299

93100

94101
print("sdbk mdld")

electron_app/src/components/ImgGenerate.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@
7272
></b-form-select>
7373
</b-form-group>
7474

75+
<b-form-group inline label="" style="margin-bottom: 6px;">
76+
<label class="mr-sm-2" style="margin-right: 8px ;" for="inline-form-custom-select-pref">Batch size: </label>
77+
<b-form-select
78+
style="border-color:rgba(0,0,0,0.1)"
79+
v-model="batch_size"
80+
:options="[1, 2, 3, 4, 5, 6, 7, 8]"
81+
required
82+
></b-form-select>
83+
</b-form-group>
84+
7585
<b-form-group inline label="" style="margin-bottom: 6px;" >
7686
<label class="mr-sm-2" style="margin-right: 8px ;" for="inline-form-custom-select-pref">Guidance Scale: </label>
7787
<b-form-select
@@ -82,6 +92,9 @@
8292
></b-form-select>
8393
</b-form-group>
8494

95+
96+
97+
8598
<b-form-group inline label="" style="margin-bottom: 6px;" >
8699
<label class="mr-sm-2" style="margin-right: 8px ;" for="inline-form-custom-select-pref">Seed: </label>
87100

@@ -211,6 +224,7 @@ export default {
211224
seed : "" ,
212225
prompt : "",
213226
num_imgs : 1,
227+
batch_size : 1 ,
214228
generated_images : [],
215229
backend_error : "",
216230
done_percentage : -1,
@@ -229,6 +243,7 @@ export default {
229243
scale : this.guidence_scale ,
230244
ddim_steps : this.dif_steps,
231245
num_imgs : this.num_imgs ,
246+
batch_size : this.batch_size ,
232247
233248
}
234249
let that = this;

0 commit comments

Comments
 (0)