Spaces:
Runtime error
Runtime error
Download modules/parallel.py from A1mal/APLIES-Model: direct link, hf CLI and curl.
- Browser
- Download file 869 Bytes
-
https://huggingface.co/spaces/A1mal/APLIES-Model/resolve/67a7c4c3fcccd398f45f3fd00afdfc5ccf2bf7e8/modules/parallel.py
- Command line
-
hf download hf://spaces/A1mal/APLIES-Model@67a7c4c3fcccd398f45f3fd00afdfc5ccf2bf7e8/modules/parallel.py
-
curl -L -o parallel.py https://huggingface.co/spaces/A1mal/APLIES-Model/resolve/67a7c4c3fcccd398f45f3fd00afdfc5ccf2bf7e8/modules/parallel.py
869 Bytes
| import numpy as np | |
| from multiprocessing import Pool, cpu_count | |
| from modules.enhance import enhancement_pipeline | |
| def process_image_chunk(args): | |
| """ | |
| Worker function to process a horizontal slice of the image. | |
| """ | |
| chunk, config = args | |
| return enhancement_pipeline(chunk, config) | |
| def parallel_enhancement(img, config): | |
| """ | |
| Orchestrates parallel image processing using multiprocessing Pool. | |
| """ | |
| cores = max(1, cpu_count() - 1) | |
| # Split image into horizontal chunks based on number of logical cores | |
| chunks = np.array_split(img, cores, axis=0) | |
| # Prepare arguments for each worker | |
| worker_args = [(chunk, config) for chunk in chunks] | |
| with Pool(processes=cores) as pool: | |
| processed_chunks = pool.map(process_image_chunk, worker_args) | |
| # Reassemble chunks | |
| return np.vstack(processed_chunks) | |