pandora-removal / examples /batch_processing.py
4n0nym05-R3s34rch3r's picture
Upload folder using huggingface_hub
b39b584 verified
"""Example of batch processing multiple images with PANDORA."""
import os
from pathlib import Path
from src.pandora_removal import PandoraRemoval, PandoraConfig
def main():
"""Demonstrate batch processing of multiple images."""
# Configure the model
config = PandoraConfig(
model_path="stabilityai/stable-diffusion-2-1",
device="cuda",
max_steps=50,
guidance_scale_ladg=7.5
)
# Initialize and load model
print("Initializing PANDORA model...")
model = PandoraRemoval(config=config)
model.load_model()
print("βœ“ Model loaded successfully!")
# Define dataset structure
# Expected structure:
# dataset/
# β”œβ”€β”€ Images/
# β”‚ β”œβ”€β”€ 001.jpg
# β”‚ β”œβ”€β”€ 002.jpg
# β”‚ └── ...
# └── Masks/
# β”œβ”€β”€ 001.png
# β”œβ”€β”€ 002.png
# └── ...
dataset_path = "path/to/your/dataset"
images_dir = os.path.join(dataset_path, "Images")
masks_dir = os.path.join(dataset_path, "Masks")
output_dir = "output/batch_results"
# Check if directories exist
if not Path(images_dir).exists():
print(f"❌ Images directory not found: {images_dir}")
print("Please update the dataset_path variable.")
return
if not Path(masks_dir).exists():
print(f"❌ Masks directory not found: {masks_dir}")
print("Please update the dataset_path variable.")
return
# Process batch
print(f"\nProcessing images from: {images_dir}")
print(f"Using masks from: {masks_dir}")
print(f"Saving results to: {output_dir}\n")
model.batch_process(
images_dir=images_dir,
masks_dir=masks_dir,
output_dir=output_dir,
border_size=17
)
print("\nβœ“ Batch processing complete!")
if __name__ == "__main__":
main()