How fast is your Data Loader...?
How fast your image is loading..?

How fast is your Data Loader...?

One of the bottleneck Computer Vision (CV) tasks is image loading. It can be a culprit behind the lag you are getting in your execution.

The importance of this task would be an implementation of a?Dataloader?class in any CNN training framework. It is crucial to make image loading fast. If it is not so, the training procedure becomes CPU bound and wastes precious GPU time.

The most famous Python libraries which allow us to read images most efficiently are -

  • OpenCV
  • Pillow
  • Pillow-SIMD
  • TurboJpeg

Some additional formats which are readily used are -

  • LMDB (Lightning Memory-Mapped Database Manager): A commonly used approach to image loading when speed is a priority is to convert data into a better representation – database or serialized buffer – beforehand. One of the largest advantages of such “databases” is that they operate with zero system calls per data access, while the file system requires several system calls per data access. We can create an LMDB database that will collect all images in key-value format.
  • TFRecords: Another useful database is TFRecords. To read data efficiently it can be helpful to serialize your data and store it in a set of files (100-200MB each) that can each be read linearly (TensorFlow manual)

Well, this article is highly inspired by this article [Link], hence, I won't be sharing any code here. But some intuitive visualization and tabular data would serve the purpose.

  • OpenCV: ?This one is the OpenCV library (probably one of the most famous one...!!). We can use one simple function to read an image from the disk –?cv2.imread.
  • Pillow: With PIL library. We can read an image using?Image.open?function.
  • Pillow-SMID: Pillow-SIMD uses new techniques which allow reading and transforming images faster with the same API as standard Pillow. Pillow and Pillow-SIMD cannot be used simultaneously in the same virtual environment – Pillow-SIMD will be used by default. To use Pillow-SIMD and avoid mistakes caused by Pillow and Pillow-SIMD being together, you need to create a new virtual environment and use.
  • TurboJpeg: There is another library called TurboJpeg. As it follows from the title – it can read only images compressed with JPEG.

Comparison Results

Loading time comparison results for all the libraries
Comparison results  for RGB and BGR formats
Loading time comparison between TFRecords and LMDB

Conclusion

The comparison results on JPEG images are really interesting. We can see that the TurboJpeg is the fastest library. Another important thing to mention is that Pillow-SIMD is faster than the original Pillow. In our task, the loading speed increased nearly by 40%.?For image database – TFRecords shows better mean results than LMDB, in particular, because of the built-in decoder function. On the other hand, LMDB allows us to read images faster.?

Thanks for following this article till here..!!

Note: Some of the content here is from third-party websites and content platforms.

Happy Learning..!!

Pankaj Mishra

要查看或添加评论,请登录

Pankaj Mishra (Ph.D)的更多文章

社区洞察

其他会员也浏览了