Spaces:
Runtime error
Runtime error
| """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() | |