diff options
author | dan <guaneec@gmail.com> | 2023-01-19 09:36:23 +0000 |
---|---|---|
committer | dan <guaneec@gmail.com> | 2023-01-19 09:36:23 +0000 |
commit | 18a09c7e0032e2e655269e8e2b4f1ca6ed0cc7d3 (patch) | |
tree | 2d7d800364de1cbaec95fba24dd81c8a8a1a9588 /modules/textual_inversion/preprocess.py | |
parent | 4688bfff55dd6607e6608524fb219f97dc6fe8bb (diff) | |
download | stable-diffusion-webui-gfx803-18a09c7e0032e2e655269e8e2b4f1ca6ed0cc7d3.tar.gz stable-diffusion-webui-gfx803-18a09c7e0032e2e655269e8e2b4f1ca6ed0cc7d3.tar.bz2 stable-diffusion-webui-gfx803-18a09c7e0032e2e655269e8e2b4f1ca6ed0cc7d3.zip |
Simplification and bugfix
Diffstat (limited to 'modules/textual_inversion/preprocess.py')
-rw-r--r-- | modules/textual_inversion/preprocess.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/modules/textual_inversion/preprocess.py b/modules/textual_inversion/preprocess.py index 86c1cd33..454dcc36 100644 --- a/modules/textual_inversion/preprocess.py +++ b/modules/textual_inversion/preprocess.py @@ -124,13 +124,11 @@ def center_crop(image: Image, w: int, h: int): def multicrop_pic(image: Image, mindim, maxdim, minarea, maxarea, objective, threshold):
iw, ih = image.size
err = lambda w, h: 1-(lambda x: x if x < 1 else 1/x)(iw/ih/(w/h))
- try:
- w, h = max(((w, h) for w in range(mindim, maxdim+1, 64) for h in range(mindim, maxdim+1, 64)
- if minarea <= w * h <= maxarea and err(w, h) <= threshold),
- key= lambda wh: ((objective=='Maximize area')*wh[0]*wh[1], -err(*wh))
- )
- except ValueError:
- return
+ w, h = max(((w, h) for w in range(mindim, maxdim+1, 64) for h in range(mindim, maxdim+1, 64)
+ if minarea <= w * h <= maxarea and err(w, h) <= threshold),
+ key= lambda wh: (wh[0]*wh[1], -err(*wh))[::1 if objective=='Maximize area' else -1],
+ default=None
+ )
return center_crop(image, w, h)
|