Read Images Concurrently with multiple operations in Python
In data science, there is a big problem to load data when we train the model or process the data. As we deal with gigabytes or terabytes of data and reading them one by one is a very time-consuming process.
But we can solve it with concurrent.futures of python. I have written a python library with the help of it that can make your life easier.
Let’s start the discussion on Concurrent-Image-Read python library, I will summarise its usability and functionality.
Installation
pip install ConcurrentImageRead
Now, it can be used directly in code with few lines of code.
Import the Concurrent-Image-Read in your file
import ConcurrentImageRead as CIR
Let’s take an example, I want to load the list of images concurrently.
image_list = ['1.png','2.png','3.png']
Now, I can easily load all images of the list with multi-threading
images = CIR.read(image_list,num_threads=3, channel_type='BGR',root_path='data')
We can also read from directly the directory path. Also, many people have difficulties reading multi-camera and multi-video frames simultaneously.
Default Parameters
- image_list = List or Numpy array or Single Path of image
- num_threads = Number of threads (default 3) (optional)
- channel_type = BGR or RBG (default BGR) (optional)
- root_path = String, Parent path for all files (optional)
- grayscale = True or False (optional)
- resize = List or Tuple resize scale in (width, height) (optional)
- normalisation = True or False, Image array divided by 255 (optional)
- dir_path = String, Path of Image Directory
- file_type = ‘all’ or ‘PNG’,’ JPG’,…etc or [‘JPG’,’ PNG’,…] (case sensitive) (default png) (optional)
- num_threads = Number of threads (default 3) (optional)
- channel_type = BGR or RBG (default BGR) (optional)
- sub_dir = Bool, Find all Images in all child directories also (default False) (optional)
- grayscale = True or False (optional)
- normalisation = True or False, Image array divided by 255 (optional)
- source = Integer for Webcam or String for Path of Camera or List of Cameras
- num_threads = Number of threads (default 3) (optional)
- fps = Integer in seconds, Frame per second (optional)
- end_time_sec = Integer in seconds, end time of camera (optional)
- channel_type = BGR or RBG (default BGR) (optional)
- grayscale = True or False (optional)
- normalisation = True or False, Image array divided by 255 (optional)
- source = List or Numpy array or Single Path of Video
- num_threads = Number of threads (default 3) (optional)
- fps = Integer in seconds, Frame per second (optional)
- end_time_sec = Integer in seconds, end time of camera (optional)
- channel_type = BGR or RBG (default BGR) (optional)
- root_path = String, Parent path for all files (optional)
- grayscale = True or False (optional)
- normalisation = True or False, Image array divided by 255 (optional)
For complete source code, you can visit my GitHub repo of Concurrent-Image-Read. Also, let me know what I can add or update in this library so it can make our work much easier.