mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
long filename and batch processing
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
- disable google fonts check on server startup
|
||||
- fix torchvision/basicsr compatibility
|
||||
- add hdr settings to metadata
|
||||
- improve handling of long filenames and filenames during batch processing
|
||||
- update built-in log monitor in ui, thanks @midcoastal
|
||||
|
||||
## Update for 2023-12-04
|
||||
|
||||
+7
-3
@@ -423,9 +423,11 @@ class FilenameGenerator:
|
||||
if part in invalid_files: # reserved names
|
||||
[part := part.replace(word, '_') for word in invalid_files] # pylint: disable=expression-not-assigned
|
||||
newparts.append(part)
|
||||
fn = Path(*newparts)
|
||||
max_length = max(230, os.statvfs(__file__).f_namemax - 32 if hasattr(os, 'statvfs') else 230)
|
||||
fn = str(fn)[:max_length-max(4, len(ext))].rstrip(invalid_suffix) + ext
|
||||
fn = str(Path(*newparts))
|
||||
max_length = max(256 - len(ext), os.statvfs(__file__).f_namemax - 32 if hasattr(os, 'statvfs') else 256 - len(ext))
|
||||
while len(os.path.abspath(fn)) > max_length:
|
||||
fn = fn[:-1]
|
||||
fn += ext
|
||||
debug(f'Filename sanitize: input="{filename}" parts={parts} output="{fn}" ext={ext} max={max_length} len={len(fn)}')
|
||||
return fn
|
||||
|
||||
@@ -577,6 +579,7 @@ save_thread.start()
|
||||
|
||||
|
||||
def save_image(image, path, basename='', seed=None, prompt=None, extension=shared.opts.samples_format, info=None, short_filename=False, no_prompt=False, grid=False, pnginfo_section_name='parameters', p=None, existing_info=None, forced_filename=None, suffix='', save_to_dirs=None): # pylint: disable=unused-argument
|
||||
import sys
|
||||
if image is None:
|
||||
shared.log.warning('Image is none')
|
||||
return None, None
|
||||
@@ -610,6 +613,7 @@ def save_image(image, path, basename='', seed=None, prompt=None, extension=share
|
||||
if dirname is not None and len(dirname) > 0:
|
||||
os.makedirs(dirname, exist_ok=True)
|
||||
params.filename = namegen.sequence(params.filename, dirname, basename)
|
||||
params.filename = namegen.sanitize(filename)
|
||||
# callbacks
|
||||
script_callbacks.before_image_saved_callback(params)
|
||||
exifinfo = params.pnginfo.get('UserComment', '')
|
||||
|
||||
+10
-10
@@ -79,16 +79,16 @@ def process_batch(p, input_files, input_dir, output_dir, inpaint_mask_dir, args)
|
||||
if proc is None:
|
||||
proc = processing.process_images(p)
|
||||
for n, (image, image_file) in enumerate(itertools.zip_longest(proc.images,batch_image_files)):
|
||||
basename, ext = os.path.splitext(os.path.basename(image_file))
|
||||
ext = ext[1:]
|
||||
if len(proc.images) > 1:
|
||||
if shared.opts.batch_frame_mode: # SBM Frames are numbered globally.
|
||||
basename = f'{basename}-{n + i}'
|
||||
else: # Images are numbered per rept.
|
||||
basename = f'{basename}-{n}'
|
||||
if not shared.opts.use_original_name_batch:
|
||||
basename = ''
|
||||
basename = ''
|
||||
if shared.opts.use_original_name_batch:
|
||||
forced_filename, ext = os.path.splitext(os.path.basename(image_file))
|
||||
else:
|
||||
forced_filename = None
|
||||
ext = shared.opts.samples_format
|
||||
if len(proc.images) > 1:
|
||||
basename = f'{n + i}' if shared.opts.batch_frame_mode else f'{n}'
|
||||
else:
|
||||
basename = ''
|
||||
if output_dir == '':
|
||||
output_dir = shared.opts.outdir_img2img_samples
|
||||
if not save_normally:
|
||||
@@ -96,7 +96,7 @@ def process_batch(p, input_files, input_dir, output_dir, inpaint_mask_dir, args)
|
||||
geninfo, items = images.read_info_from_image(image)
|
||||
for k, v in items.items():
|
||||
image.info[k] = v
|
||||
images.save_image(image, path=output_dir, basename=basename, seed=None, prompt=None, extension=ext, info=geninfo, short_filename=True, no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=image.info, forced_filename=None)
|
||||
images.save_image(image, path=output_dir, basename=basename, seed=None, prompt=None, extension=ext, info=geninfo, short_filename=True, no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=image.info, forced_filename=forced_filename)
|
||||
shared.log.debug(f'Processed: images={len(batch_image_files)} memory={memory_stats()} batch')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user