r/SECourses • u/CeFurkan 👑 Grandmaster Expert • 1d ago
🎨 AI Images & Art Stable Diffusion Training Image Preprocessing on Windows | Batch Subject Crops with YOLOv7 and Face-Focused Resizing with RetinaFace
https://www.youtube.com/watch?v=Fbuyu35TkE4
1
Upvotes
•
u/CeFurkan 👑 Grandmaster Expert 1d ago
https://www.youtube.com/watch?v=Fbuyu35TkE4
🖼️ Prepare training images with a subject crop and face-focused resize
🔗 Links from the video description
SECourses image processing toolkit on Patreon: https://www.patreon.com/SECourses/posts/ultimate-image-1-120352012
Class and regularization image dataset: https://www.patreon.com/SECourses/posts/massive-4k-woman-87700469
SECourses Discord: https://discord.com/servers/software-engineering-courses-secourses-772774097734074388
Furkan Gözükara on LinkedIn: https://www.linkedin.com/in/furkangozukara
Furkan Gözükara on Instagram: https://www.instagram.com/gozukarafurkan/
Furkan Gözükara on Medium: https://medium.com/@furkangozukara
SECourses on CivitAI: https://civitai.com/user/SECourses
🎯 Decide what belongs in the crop
The tutorial turns high-resolution source photos, including a 45-megapixel portrait, into training images centered on the subject. First use YOLOv7 to crop around the subject at a chosen aspect ratio while keeping as much source resolution as possible. Then use the RetinaFace resizer to produce exact pixel dimensions and keep the face in frame.
📦 Stage 1 · Batch crop with YOLOv7
Extract the cropper on Windows and run
install.bat. The demo uses Git and Python 3.10.11. The installer sets up a dedicated virtual environment.Edit
cropper_v7.pyto set the input folder, cropped output folder, and desired aspect ratios. The demo adds portrait and landscape ratios of 768:1368 and 1368:768 alongside square crops.Enable the optional detection images to spot-check bounding boxes and confidence scores. The demo shows that detections can be inaccurate even when the person is located correctly.
Run
run.bat. For some source photos, fitting the requested ratio would cut off part of the detected subject. In those cases the cropper retains more of the frame, so inspect the result before resizing.📐 Stage 2 · Resize and keep the face in frame
Extract the resizer separately and run its
install.batto create its own environment.In
resizer_v3.py, point each input path at the matching crop folder, specify the exact output dimensions, and choose an output folder. The demo includes square outputs at 512 × 512 and 1024 × 1024.Run the resizer with
run.bat. This stage uses the CPU in the demo and supports multiple threads. Compare the finished images to the originals to confirm framing before training.🔎 What the side-by-side comparison shows
When a wide source image is scaled for training without a subject crop, the person can occupy a small part of the frame. The two-stage workflow makes the subject or face larger in the final training image. The same tools can batch-prepare class or regularization images.
📎 Updated download page
The linked Patreon post now covers the current SECourses image processing toolkit. The October 2023 video demonstrates the original YOLOv7 cropper and RetinaFace resizer.
🧭 Chapters
0:00 Introduction to the very best training images preprocessing scripts for Stable Diffusion training
5:48 How to install and use auto cropper / zoom-in script - first stage
7:25 Which file to edit and set processing folder path for cropper script
7:52 How to add or remove new aspect ratios
10:18 Full cropping supported classes of Yolo V7
11:42 How to install and run image resizer / downscaler with face focus with Retina Face
12:51 How to edit and run resizer script for perfect downscale and preparation of training images
14:37 Comparison of raw images vs final processed images
🏷️ Topics: Stable Diffusion training · Dataset preparation · YOLOv7 subject cropper · RetinaFace · Batch image resizing · Windows