A Python tool to preprocess images for LoRA training, with optional face cropping, background removal, and captioning.
- Face-aware square cropping
- Background removal with
rembg - LLaVA captioning for full images
- Blendshape detection for facial expressions
- Easy CLI interface
git clone https://github.com/baba-yaga/lora-image-preprocessor.git
cd lora-image-preprocessor
pip install -r requirements.txtThe main script is lora_image_preprocessor/main.py. You can run it from the project root directory.
--input_dir: (Required) The directory containing the images to process.--output_dir: The directory base name where the processed images and captions will be saved. The actual name will be appended with the resoltion of the outputs and other flags: face and/or no_bg, if given. Defaults to the input directory.--face_only: If specified, the script will crop the image to the detected face. Note that in images where both eyes are not visible, or in cartoon-like images, the face is usually not detected.--remove_bg: If specified, the background of the images will be removed.--blur_bg: If specified, the background of the images will be blurred using a Gaussian kernel.--resolution: The target output resolution for the images (default: 512).--output_format: The output image format (e.g., png, jpg) (default: png).--face_crop_padding: The padding factor for face cropping (default: 1.8).--no_caption: If specified, the script will not generate captions.
Process all images in a directory:
python -m lora_image_preprocessor.main --input_dir input_images --output_dir output_imagesProcess only images with faces:
python -m lora_image_preprocessor.main --input_dir input_images --output_dir output_images --face_onlyRemove the background from all images:
python -m lora_image_preprocessor.main --input_dir input_images --output_dir output_images --remove_bgProcess images without generating captions:
python -m lora_image_preprocessor.main --input_dir input_images --output_dir output_images --no_caption