Home Creators Posts Import Register Favorites Logout

Downloads

Content

Ultimate Batch Image Pre-Processing Gradio app crops subjects with YOLO models and resizes training images with face focus; it is deprecated for a newer app.

Note: this is an older post kept for reference. The current, maintained version is Ultimate Image Processing App: 1-Click Batch Cropping, SAM 3.1 Masking.

1-click to install and use on Windows and cloud (RunPod, Massed Compute), with a Kaggle notebook added later. Features a face extractor, a subject cropper for 79 classes such as car, person and cat, and a resizer with white-background padding.

This post is deprecated new post is here : https://www.patreon.com/posts/ultimate-image-2-120352012

-

-

-

Please use this post now : https://www.patreon.com/posts/ultimate-image-2-120352012

-

-

-

-

Please use this post now : https://www.patreon.com/posts/ultimate-image-2-120352012

-

-

-

Patreon exclusive posts index to find our scripts easily, Patreon scripts updates history to see which updates arrived to which scripts and amazing Patreon special generative scripts list that you can use in any of your task.

Join discord to get help, chat, discuss and also tell me your discord username to get your special rank : SECourses Discord

Please also Star, Watch and Fork our Stable Diffusion & Generative AI  GitHub repository and join our Reddit subreddit and follow me on LinkedIn (my real profile)

=======

Latest installer zip file : Ulti_Img_PreProcess_v8.zip

9 December 2024 Update

  • Face Extractor code fixed and now fully working

  • Now you can multi-threaded extract faces with add or remove padding option

    • It uses face_yolov9c.pt model from adetailer developer

  • The image types Yolo can process was limited

    • Now the app will convert images into png to be able to process all images during runtime like jfif type

20 November 2024 Update

  • Yolo version upgraded to Yolo V11 from V10

  • You can use this app code to understand and write a Yolo standalone application easily

  • Overwrite older files and click install again to upgrade

3 November 2024 Update

  • Kaggle notebook added upon request

17 October 2024 Update

  • The error on Ubuntu systems, Massed Compute and RunPod fixed

  • Use newer Massed_Compute_Instructions_READ.txt file command

  • Save as JPEG option added

Windows Requirements

  • Python 3.10, FFmpeg, CUDA 12.4, cuDNN 8.9.7, C++ Tools and Git

  • If it doesn't work make sure to below NEW tutorial and install everything exactly as shown in this below tutorial

  • https://youtu.be/DrhUHnYfwC0

How To Install

  • Just extract into your main drives like c:/resize - dont use space char or special letters

  • Double click and execute Windows_Install.bat to install

  • When updating just extract new zip file and rerun Windows_Install.bat file

  • For RunPod and Massed Compute follow the instructions

How To Use

  • This app is developed by me from scratch to pre-process your training images.

  • First use Image Cropper tab to extract subjects from your images (it will not cut the parts of the subject)

  • It uses Yolo v10 model and supports following classes (79 class like car, person, cat, etc..), you can select class from drop-down box : Yolo_10_Class_List.txt

  • So this will zoom the subject with trying to match to the given aspect ratio

  • Still you may not get the perfect aspect ratio if the subject needs to be cropped

  • The benefit of this that, you should zoom the training subject in your images

  • You can watch this video to understand : https://youtu.be/Fbuyu35TkE4

  • Hopefully I will make a full new tutorial soon

  • Then use the Image Resizer tab to resize them into your exact resolution

  • This will focus to the face when resizing however if you don't have a face in image like you are resizing car images, it will just resize without any focus of any part of the subject

  • I also added option resize without cropping (center image and add white background) so that it will expand image with white background to not crop any part of the image

  • Check following how to use images : How To Use Image Cropper.png , How To Use Image Resizer.png

  • First crop images with auto cropper and then use outputs folder of the auto cropper with resizer and it should work hopefully perfect

  • The following tabs of the images still in development : Move Low-Res Files, Rename Files, Extract Faces, Find Duplicates

Used Model Files

  

Related posts

All posts in this topic: Captioning, Dataset and Image Processing Tools · New to SECourses? Start Here: Best and Most Popular SECourses Posts

Files

Comments

Training AI

Thank you for this! Cropping & resizing tabs work perfect. Got the following error when trying the Find Duplicates tab: ``` Traceback (most recent call last): File "C:\Python310\lib\multiprocessing\queues.py", line 244, in _feed obj = _ForkingPickler.dumps(obj) File "C:\Python310\lib\multiprocessing\reduction.py", line 51, in dumps cls(buf, protocol).dump(obj) AttributeError: Can't pickle local object 'find_duplicates..process_image' ``` Edit: OOPS I just noticed your note that the other tabs are still under development. Thank you sir!

Dmitry

Hello, a little confused, I have a version of resizer_v3, if I understand correctly, this is the same resizer_v3 but with the ability to install on RunPod and other external resources? Ie, the old folder resizer can be deleted, I want to restore order in the files, trying to figure out what and how

SECourses

delete olders use this one. this one is faster better more optimized

Error_404_unknown

Hi I keep getting this error W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2024-09-17 21:39:27.818229: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine." I tried updating tensorboard in the venv but that didn't work either. Is this version not compatible with CUDA 12.3? I don't really want to downgrade my system CUDA and risk breaking everything else.

abaj006

I believe I have all the dependancies installed, but getting this error on Windows 10 PC: [WinError 126] The specified module could not be found. Error loading "C:\Users\UserName\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\lib\cudnn_cnn_infer64_8.dll" or one of its dependencies.

SECourses

yep i just tested with fresh install cuda 12.4 and cudnn 8.9.7 works perfect - they are my system default as shown in video

abaj006

Yes, thanks for that. I followed your tutorial video for cudnn and now works.

Goldwaters

Is there a way to specify which detection to crop? For example, an image with multiple people - it seems like YOLO just crops the image to the first person it detects in the image. Even just letting it crop the image multiple times for each person would help and then you could just delete the extras.

SECourses

not that i know. probably you should manually crop such images

Goldwaters

It would be extremely useful if you could extract all detections instead of just the highest confidence one. Somewhere in this code you are taking the best detection and looping over it. Couldn't you tell it to loop over each detection and use the same code each time? https://freeimage.host/i/2JAU2YQ (Maybe not simple, but just thinking, as I'm not a programmer myself exactly)

SECourses

ye not easy. maybe you can try claude 3.5 and modify code and see if it can do something that will work for your case

Shepard2k

Is it possible to save the cropped images in jpg format instead of png? i need to crop 2700 jpg images und would like to save them in jpg again.

Shepard2k

jesus that was fast, thank you!!

대훈 조

I would like to fine-tune on various objects, not on a specific person or item, but on a wide range of different objects. I have a few questions regarding this situation: 1. In Kohya, how many images can I include for fine-tuning? For example, can a large dataset with tens of thousands of images (like 10,000) be processed within the Kohya interface? 2. Is it necessary to crop and resize the images? If I have a dataset with various image sizes, do I need to ensure that all images are of the same size? 3. If resizing is required, does your GUI provide a way to crop & resize images of various objects? 4. Does fine-tuning work well even when there are mixed image file formats, such as PNG, JPG, and JPEG?

SECourses

1 : kohya has no limit i saw people does millions of images 2 : i prefer all 1024x1024 as a beginning - best is compare cropped vs bucketing enabled 3 : my gui has certain objects others will be center cropped 4 : it works 5 : when you train multiple objects with FLUX they get mixed, currently testing de-distilled models to see if this can be improved 6 : SD 3.5 may work better will full research that too hopefully soon

Brian Skipper

Having a strange issue with the resize tab on 3 images. The cropped fine under 768x1024 but when I got to resize them I get the message "No images found to process in the specified resolution folders." I have resize without cropping checked. I'm glad it's only 3 images so I can manually do it for now, but do you know what is going on? The cropped images resolutions are: 1590x2121 2261x3014 2109x2812

SECourses

you need to enter resolutions that you want and also give parent folder path that will have folders named as them.

Brian Skipper

Thanks, yes I had them in a folder named 786x1024 that was generated by your cropping script. They are the right aspect ratio but they wouldn't resize with the script. It did resize a few other images that were in the same folder. I'll try to reproduce this and see what is shown in the terminal when I get time.

s s

SECourses

hi some functions are not coded yet. only crop and resize working perfectly atm.

Nicolas Nicolau

Hi. I try crop and resize with your app. The problem is, the person are cropped correctly, but dont resize to the dimmensions we put, the script only crop. No errors in the console. When i go to resize directory created "1024x1024" (for example) the pics are biggest, like the original, but only the person image 1/1 F:\testpic\testpic (5).jpg: 448x640 1 person, 62.8ms Speed: 3.3ms preprocess, 62.8ms inference, 5.8ms postprocess per image at shape (1, 3, 448, 640) image 1/1 F:\testpic\testpic (6).jpg: 448x640 1 person, 41.5ms Speed: 3.1ms preprocess, 41.5ms inference, 1.5ms postprocess per image at shape (1, 3, 448, 640) image 1/1 F:\testpic\testpic (7).jpg: 640x448 1 person, 1 bench, 57.5ms Speed: 2.6ms preprocess, 57.5ms inference, 2.1ms postprocess per image at shape (1, 3, 640, 448) image 1/1 F:\testpic\testpic (8).jpg: 448x640 1 person, 36.3ms Speed: 2.5ms preprocess, 36.3ms inference, 1.5ms postprocess per image at shape (1, 3, 448, 640) image 1/1 F:\testpic\testpic (9).jpg: 448x640 1 person, 58.9ms Speed: 2.6ms preprocess, 58.9ms inference, 1.0ms postprocess per image at shape (1, 3, 448, 640) Cropping images: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 30/30 [00:41<00:00, 1.38s/image] Processing complete! Processed: 30, Skipped: 0, Total: 30/30 images in 00:00:41.

Nicolas Nicolau

Im if i want only use image resizer i get this in console: ERROR:root:Folder not found for resolution 1280x1280. Skipping this resolution. INFO:root:Total images to process: 0 Bat i hae the some pics i use in the previous example

SECourses

the logic is simple. the auto cropper will crop the subject from the image but will not crop the subject body parts or any parts. then you need to run resizer. for 1280x1280 to work first crop to 1280x1280 then it will generate that folder and that time resizer will work. resizer will crop subject body parts / parts as well. if it is human it will focus on face and will not crop it

Astaroth

Hi I get this error while running the script : File "C:\ImgPreProcess_V6\venv\lib\site-packages\ultralytics\models\yolo\model.py", line 26, in __init__ safe_run("/tmp/ultralytics_runner") File "C:\ImgPreProcess_V6\venv\lib\site-packages\ultralytics\utils\downloads.py", line 283, in safe_run os.chmod(path, 0o770) FileNotFoundError: [WinError 3] Le chemin d’accès spécifié est introuvable: '/tmp/ultralytics_runner'

SECourses

hi in which screen? some screens are not coded yet. i am planning look at them

Astaroth

I am trying to run the image cropper

SECourses

hi it should work. can you reinstall and send me install logs : monstermmorpg@gmail.com

Astaroth

Reinstall worked, it seems like the first install was done with missing required tools. Thanks for the amazing work and fast answers !

SECourses

you are welcome it can sometimes happen

Kevin O'Malley

I replace the find_duplicates function with this to make it work. import threading import queue def process_image(q, folder_path, hash_dict, duplicate_images, destination_folder, hash_size, cutoff, lock): while True: try: filename = q.get_nowait() except queue.Empty: break image_path = os.path.join(folder_path, filename) try: with Image.open(image_path) as img: temp_hash = imagehash.average_hash(img, hash_size) with lock: if temp_hash in hash_dict: duplicate_images.append((filename, hash_dict[temp_hash])) shutil.move(image_path, os.path.join(destination_folder, filename)) else: for h, existing_file in hash_dict.items(): if abs(temp_hash - h) < cutoff: duplicate_images.append((filename, existing_file)) shutil.move(image_path, os.path.join(destination_folder, filename)) break else: hash_dict[temp_hash] = filename except Exception as e: print(f"Error processing {filename}: {e}") finally: q.task_done() def find_duplicates(folder_path, destination_folder, hash_size, cutoff, num_threads): os.makedirs(destination_folder, exist_ok=True) image_files = [f for f in os.listdir(folder_path) if f.lower().endswith(('png', 'jpg', 'jpeg', 'bmp'))] total_files = len(image_files) hash_dict = {} duplicate_images = [] lock = threading.Lock() q = queue.Queue() for filename in image_files: q.put(filename) threads = [] for _ in range(num_threads): t = threading.Thread(target=process_image, args=(q, folder_path, hash_dict, duplicate_images, destination_folder, hash_size, cutoff, lock)) t.start() threads.append(t) for t in threads: t.join() with open('duplicates.txt', 'w') as f: for dup in duplicate_images: f.write(f"{dup[0]} is a duplicate/near-duplicate of {dup[1]}\n") print(f"Found {len(duplicate_images)} duplicates/near-duplicates. Results saved to duplicates.txt.")

reaper557

Thank you very much for continuing to work on and update this app! I particularly appreciate the face extraction, which I have just used in a recent model train. Your implementations work so much better than any janky solutions I've coded up in Python with Qwen2.5 (still fun to do). (づᴗ _ᴗ)づ♡

SECourses

find_duplicates is still not working yet. please remind me tomorrow hopefully i should add.

Hockey

Which resolutions do you recommend putting into "Aspect Ratios (comma-separated, e.g., 1024x1024,1280x720,1920x1080,...)" box for ultimate Dreambooth training later? I have lots of low resolution and high resolution pictures. Can you choose a folder and it will also work on all the subfolders?

SECourses

i recommend 1024x1024. it already process all sub folders. just try to understand folder format

Dmitry

For those who can't work with the "image resizer" tab. Example: We have an image "img1.jpg"(768x512) and we want to change it to a 1024x1024 image - Create a folder named "1024x1024" and put our file - "img1.jpg"(768x512) there - Important: Let's say your folder is located on the desktop: С:\Desktop\1024x1024 The path to specify: "С:\Desktop\" - this is the path that the app will use to search for the "1024x1024"folder. If you specify the path With: С:\Desktop\1024x1024, the application will not see your images, so it will first search for the folder: "1024x1024" and not the files inside the \Desktop\1024x1024 directory. It took me a few nerve cells to figure out what was going on. I hope this will help someone. PS Many thanks to the author of the app for this awesome tool. It may be correct to explain in detail on the "image resizer" tab how to specify the\path correctly.

SECourses

thank you for explanation. a major improvement and new feature hopefully coming soon. i will make a dedicated video for the app

SECourses

hi it is 2 stages. first auto crop and then resize for exact resolution. the logic explained in this video and hopefully i will make a new video soon : https://youtu.be/Fbuyu35TkE4

HüseyinT

"Venv" kurulumu tamamlandıktan sonra "Windows_Start_App" dosyasını çalıştırınca aşağıdaki hatayı aldım: [2025-04-28 02:23:52,018] [INFO] [real_accelerator.py:222:get_accelerator] Setting ds_accelerator to cuda (auto detect) W0428 02:23:53.612000 9716 venv\Lib\site-packages\torch\distributed\elastic\multiprocessing\redirects.py:29] NOTE: Redirects are currently not supported in Windows or MacOs. Error: SAM2 checkpoint file not found at C:\Users\husey\Downloads\Ulti_Img_Process_V13\models\sam2.1_hiera_large.pt Press any key to continue . . . "Windows_Install" dosyasına tıklayıp V13 kurulumunda cmd ekranında aşağıdaki hatayı adım: "... Attempting uninstall: supervision Found existing installation: supervision 0.25.1 Uninstalling supervision-0.25.1: Successfully uninstalled supervision-0.25.1 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. groundingdino 0.1.0 requires supervision>=0.22.0, but you have supervision 0.6.0 which is incompatible. Successfully installed ImageHash-4.3.2 PyWavelets-1.8.0 accelerate-1.6.0 aiofiles-24.1.0 antlr4-python3-runtime-4.9.3 anyio-4.9.0 click-8.1.8 exceptiongroup-1.2.2 fastapi-0.115.12 ffmpy-0.5.0 gradio-5.27.0 gradio-client-1.9.0 groovy-0.1.2 groundingdino-py-0.4.0 h11-0.16.0 httpcore-1.0.9 httpx-0.28.1 hydra-core-1.3.2 iopath-0.1.10 markdown-it-py-3.0.0 mdurl-0.1.2 numpy-2.1.1 omegaconf-2.3.0 opencv-contrib-python-4.11.0.86 orjson-3.10.16 pandas-2.2.3 portalocker-3.1.1 pydub-0.25.1 pygments-2.19.1 python-multipart-0.0.20 pytz-2025.2 pywin32-310 rich-14.0.0 ruff-0.11.7 safehttpx-0.1.6 sam2-1.1.0 seaborn-0.13.2 segment-anything-1.0 semantic-version-2.10.0 shellingham-1.5.4 sniffio-1.3.1 starlette-0.46.2 supervision-0.6.0 tomlkit-0.13.2 typer-0.15.2 tzdata-2025.2 ultralytics-8.3.115 ultralytics-thop-2.0.14 uvicorn-0.34.2 websockets-15.0.1 Cloning into 'GroundingDINO'... remote: Enumerating objects: 463, done. remote: Counting objects: 100% (240/240), done. remote: Compressing objects: 100% (105/105), done. Rremote: Total 463 (delta 175), reused 135 (delta 135), pack-reused 223 (from 1) Receiving objects: 100% (463/463), 12.87 MiB | 1.59 MiB/s, done. Resolving deltas: 100% (241/241), done. .gitattributes: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.52k/1.52k [00:00 snapshot_download(repo_id="MonsterMMORPG/YoloModels",local_dir="models") File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\_snapshot_download.py", line 296, in snapshot_download thread_map( File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\tqdm\contrib\concurrent.py", line 69, in thread_map return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs) File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\tqdm\contrib\concurrent.py", line 51, in _executor_map return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs)) File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\tqdm\std.py", line 1181, in __iter__ for obj in iterable: File "C:\Users\husey\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 621, in result_iterator yield _result_or_cancel(fs.pop()) File "C:\Users\husey\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 319, in _result_or_cancel return fut.result(timeout) File "C:\Users\husey\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 458, in result return self.__get_result() File "C:\Users\husey\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 403, in __get_result raise self._exception File "C:\Users\husey\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\_snapshot_download.py", line 270, in _inner_hf_hub_download return hf_hub_download( File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\file_download.py", line 941, in hf_hub_download return _hf_hub_download_to_local_dir( File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\file_download.py", line 1241, in _hf_hub_download_to_local_dir _download_to_tmp_and_move( File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\file_download.py", line 1675, in _download_to_tmp_and_move http_get( File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\huggingface_hub\file_download.py", line 449, in http_get for chunk in r.iter_content(chunk_size=constants.DOWNLOAD_CHUNK_SIZE): File "C:\Users\husey\Downloads\Ulti_Img_Process_V13\venv\lib\site-packages\requests\models.py", line 822, in generate raise ChunkedEncodingError(e) requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(452224224 bytes read, 445859387 more expected)', IncompleteRead(452224224 bytes read, 445859387 more expected)) Virtual environment made and installed properly Press any key to continue . . .

SECourses

internet hatası almışsın. restart at tekrar kur. gene alırsan vpn varsa kapat. gene alırsan WARP vpn kur aktifleştir onla dene

진표 김

I'm also stuck with the same issue and unable to make progress.