stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Feature Request]: Keep original file names for img2img batches

Open tip0un3 opened this issue 2 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

Hello,

I couldn't find it in the settings or in the wiki documentation. Wiki custom images filename has no pattern for original filename. Is there a setting I haven't seen to keep the original filenames after batch processing in img2img?

I've seen that this option exists for the extra menu and upscales.

tip0un3 avatar Jun 23 '23 08:06 tip0un3

"Images filename pattern" refers to txt2img and img2img

chrme avatar Jun 23 '23 18:06 chrme

"Images filename pattern" refers to txt2img and img2img

Yes the Wiki : https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Images-Filename-Name-and-Subdirectory

But I don't see any pattern that refers to the original filename. So the question is, how do I get the same file name in the output as the files in the img2img batch folder? I didn't see any option allowing this except for the extra menu.

tip0un3 avatar Jun 23 '23 19:06 tip0un3

Ah, you wanted to read the metadata from the image itself and use pattern like [origin_img_metadata_prompt]? Iirc, this is not implemented at the moment.

chrme avatar Jun 23 '23 20:06 chrme

No, I make img2img batches for animation. So I have files numbered in frame order: 0001.png, 0002.png, 0003.png, ...

But sometimes I have files in this folder that don't follow each other in name, such as : 0025.png, 0026.png, 0040.png, 0041png, ...

This is deliberate, as the missing frames are in a different folder and I want to batch img2img with a different prompt. Once everything has been processed in img2img, I put the frames together to create my animation.

The problem is that I need to keep the numbering order for my animation in the output, which is why I'm trying to keep the same original file name in the img2img batch output.

As a result, I'm forced to rename my files manually, which takes a lot of time.

tip0un3 avatar Jun 23 '23 20:06 tip0un3

Oh, I get it. But this is also not implemented. But as a temporary solution, you can change this line to: filename = f"{i}{os.path.basename(image)[1]}"

or if you have DEV version this line to: filename = f"{i}{image_path.suffix}"

the result will be 0.png, 1.png, 2.png, 3.png etc but existing filenames in the output folder will be overwritten.

chrme avatar Jun 23 '23 21:06 chrme

I tried your solution but the files are still named with number-seed.png

tip0un3 avatar Jun 28 '23 20:06 tip0un3

hello, has your problem been solved? I have the same problem.

zyseu avatar Dec 20 '23 08:12 zyseu

I also would like to know if there is a solution to this? I don't even understand why files are being renamed in the first place if the input and output directories are different. If there is an issue of duplicate files, then perhaps create a new sub-folder for each batch run with a timestamp name, but preserve the original filenames on generation.

Edit: I did find the solution on that page, leaving it here for @zyseu https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Images-Filename-Name-and-Subdirectory#add--remove-number-to-filename-when-saving

Delerium avatar Jan 04 '24 07:01 Delerium

the best I have for this problem is this:

import os
from os import path
import shutil

Source_Path = 'X:\\input'
Destination = 'X:\\output'
#dst_folder = os.mkdir(Destination)


def main():
    for count, filename in enumerate(os.listdir(Source_Path)):
        dst =  str(count).zfill(5) + ".png"
        print(dst)
        # rename all the files
        os.rename(os.path.join(Destination, dst),  os.path.join(Destination, filename))


# Driver Code
if __name__ == '__main__':
    main()

it takes file names from the input directory and writes them in naming order and replacing in output directory set Images filename pattern to [none] and enable replace mode so that it writes files as just numbers but it doesn't work reliable :( sometimes it will rename in the wrong order and it's not off by 1 so I guess automatic doesn't always name output files in the same order as names of input files :(

Manoa1911 avatar Apr 28 '24 04:04 Manoa1911