|
|
||
|---|---|---|
| .. | ||
| images | ||
| output | ||
| README.md | ||
| flow.py | ||
| main.py | ||
| nodes.py | ||
| requirements.txt | ||
README.md
Parallel Image Processor (AsyncParallelBatchFlow Example)
This example demonstrates how to use AsyncParallelBatchFlow to process multiple images with multiple filters in parallel.
How it Works
- Image Generation: Creates sample images (gradient, checkerboard, circles)
- Filter Application: Applies different filters (grayscale, blur, sepia) to each image
- Parallel Processing: Processes all image-filter combinations concurrently
Flow Structure
graph TD
subgraph AsyncParallelBatchFlow[Image Processing Flow]
subgraph AsyncFlow[Per Image-Filter Flow]
A[Load Image] --> B[Apply Filter]
B --> C[Save Image]
end
end
Key Components
-
LoadImage (AsyncNode)
- Loads an image from file
- Uses PIL for image handling
-
ApplyFilter (AsyncNode)
- Applies the specified filter
- Supports grayscale, blur, and sepia
-
SaveImage (AsyncNode)
- Saves the processed image
- Creates output directory if needed
-
ImageBatchFlow (AsyncParallelBatchFlow)
- Manages parallel processing of all image-filter combinations
- Returns parameters for each sub-flow
Running the Example
- Install dependencies:
pip install -r requirements.txt
- Run the example:
python main.py
Sample Output
The example will:
- Create 3 sample images:
cat.jpg,dog.jpg,bird.jpg - Apply 3 filters to each image
- Save results in
output/directory (9 total images)
Example output structure:
output/
├── cat_grayscale.jpg
├── cat_blur.jpg
├── cat_sepia.jpg
├── dog_grayscale.jpg
...etc
Key Concepts
- Parallel Flow Execution: Each image-filter combination runs as a separate flow in parallel
- Parameter Management: The batch flow generates parameters for each sub-flow
- Resource Management: Uses semaphores to limit concurrent image processing
- Error Handling: Gracefully handles failures in individual flows