DEV Community

Cover image for JPEG2RGB Array Showdown: libjpeg-turbo vs kornia-rs vs TensorFlow vs torchvision
Vladimir Iglovikov
Vladimir Iglovikov

Posted on

JPEG2RGB Array Showdown: libjpeg-turbo vs kornia-rs vs TensorFlow vs torchvision

In the realm of image processing and machine learning, the efficiency of loading and preprocessing images directly impacts our projects' performance. Drawing inspiration from the Albumentations library benchmark, I've conducted a detailed analysis comparing how different Python libraries handle the conversion of JPG images into RGB numpy arrays.

You can find all the code for this benchmark here : https://github.com/ternaus/imread_benchmark

The Need for Speed in Benchmarking

Our goal is straightforward: assess the efficiency of libraries for a task that's routine yet crucial in machine learning - turning JPGs into RGB numpy arrays. We're not just comparing numbers; we're looking for practical insights that can influence choice and implementation.

Ensuring a Level Playing Field

A fair benchmark requires uniformity, hence the conversion of all images to RGB numpy arrays regardless of the libraries' default formats (like BGR for OpenCV). This step, although necessary, introduces an additional layer to our testing but doesn't significantly skew the results based on our preliminary analysis.

Benchmark Setup

Hardware Used: AMD Ryzen Threadripper 3970X 32-Core Processor

With this powerhouse CPU, we ensure that our benchmarks focus purely on library performance without hardware-induced bottlenecks.

Observations and Insights

Plots with results

Table with results

The benchmark revealed a mix of expected and surprising results:

  • Traditional choices like OpenCV and imageio hold up well in terms of reliability.
  • Newer or specialized solutions like TensorFlow, kornia-rs, and jpeg4py, however, show a noticeable edge in performance, potentially changing how we approach data preparation for neural network training.

Making Informed Choices in Tool Selection

Time efficiency is crucial in data processing. Our findings highlight key performers and remind us of the importance of selecting the right tools based on our specific needs and workflows.

  • Kornia-rs stands out for those seeking modern, efficient image processing, particularly when not tied to TensorFlow or Torchvision ecosystems.
  • Despite its efficiency, jpeg4py's lack of updates may raise concerns. If your workflow is entrenched in TensorFlow or Torchvision, their native image processing capabilities might suffice.
  • For broader applications, particularly where libjpeg-turbo's performance can be leveraged, kornia-rs presents an appealing option.

In closing, this benchmark doesn't dictate a one-size-fits-all solution but rather provides data to help tailor tool selection to your project's requirements. Whether you're deep into AI research or developing the next big computer vision application, the right tools can significantly streamline your workflow.

Top comments (0)