Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Parallel Image Processing | Advanced Patterns and Best Practices
Quizzes & Challenges
Quizzes
Challenges
/
Python Multithreading and Multiprocessing

bookChallenge: Parallel Image Processing

Imagine you are building a tool to automate the processing of a large collection of images. Your goal is to apply a transformation—such as resizing each image to a standard dimension or applying a simple filter—across all files in a directory. Processing each image one by one would be slow, especially with hundreds or thousands of files. By leveraging multiprocessing, you can process many images at once, dramatically reducing the total time required. This approach is especially useful for tasks like preparing image datasets for machine learning or batch editing photographs.

Завдання

Swipe to start coding

Implement a function to process a list of image file paths in parallel using a process pool.

  • Use the concurrent.futures module's ProcessPoolExecutor to execute the process_func on each image path in the image_paths list.
  • Collect the results into a list and return it.
  • Use the num_workers parameter to set the number of processes in the pool.
  • Call the process_images_parallel function with a sample list of image paths, a simple processing function (such as returning the file name in uppercase), and a specified number of workers. Print the result using the following template:
    • print(result)

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 3
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

What are some common transformations I can apply to images using multiprocessing?

Can you explain how multiprocessing speeds up image processing tasks?

How do I set up multiprocessing for image processing in Python?

close

bookChallenge: Parallel Image Processing

Свайпніть щоб показати меню

Imagine you are building a tool to automate the processing of a large collection of images. Your goal is to apply a transformation—such as resizing each image to a standard dimension or applying a simple filter—across all files in a directory. Processing each image one by one would be slow, especially with hundreds or thousands of files. By leveraging multiprocessing, you can process many images at once, dramatically reducing the total time required. This approach is especially useful for tasks like preparing image datasets for machine learning or batch editing photographs.

Завдання

Swipe to start coding

Implement a function to process a list of image file paths in parallel using a process pool.

  • Use the concurrent.futures module's ProcessPoolExecutor to execute the process_func on each image path in the image_paths list.
  • Collect the results into a list and return it.
  • Use the num_workers parameter to set the number of processes in the pool.
  • Call the process_images_parallel function with a sample list of image paths, a simple processing function (such as returning the file name in uppercase), and a specified number of workers. Print the result using the following template:
    • print(result)

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 3
single

single

some-alt