Skip to main content



Framework agnostic, faster data reading for DeepLearning.

A native extension for Python built with C++ and pybind11.

Installation • Why? • What is the performance gain? • Tutorial • License

PyPI version

DataReadingBlocks for Python is a python module that provides collection of C++ backed data reading primitives. It targets deep-learning needs, but it is framework agnostic.

Installation

Available as pypi package:

$ pip install dareblopy

To build from sources refer to wiki page.

Why?

Development initially started to speedup reading from ZIP archives, reduce copying data, increase time of GIL being released to improve concurrency.

But why reading from ZIP archive? Reading a ton of small files (which is often the case) can be slow, specially if the drive is network attached, e.g. with NFS. However, the bottle neck here is hardly the disk speed, but the overhead of filesystem, name-lookup, creating file descriptors, and additional network usage if NFS is used.

If, all the small files are agglomerated into larger file (or several large files), that improves performance substantially. This is exactly the reason behind TFRecords in TensorFlow:

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. This is especially true if the data is being streamed over a network. This can also be useful for caching any data-preprocessing.

The downside of TFRecords is that it's TensorFlow only.

A much simpler, yet still effective solution is to store data in ZIP archive with zero compression. However, using zipfile package from standard library can be slow, since it is implemented purely in Python and in certain cases can cause unnecessary data copying.

That's precisely the reason behind development of DareBlopy. In addition to that it also has such features as:

  • Readying JPEG images directly to numpy arrays (from ZIP and from filesystem), to reduce memory usage and unnecessary data copies.
  • Two JPEG backends selectable at run-time: libjpeg and libjpeg-turbo. Both backends are embedded into DareBlopy and do not depend on any system package.
  • Reading of TFRecords (not all features are support though) without dependency on TensorFlow that enables usage of datasets stored as TFRecords with ML frameworks other than TensorFlow, e.g. Pytorch.
  • Random yielders, iterators and, dataloaders to simplify doing DataLearning with TFRecords with other ML frameworks.
  • No dependency on system packages. You install it from pip - it works.
  • Support for compressed ZIP archives, including LZ4 compression.
  • Virtual filesystem. Allows mounting of zip archives.

What is the performance gain?

Well, it depends a lot on a particular use-case. Let's consider several. All details of the benchmarks you can find in run_benchmark.py. You can also run it on your machine and compare results to the ones reported here.

Reading files to bytes

Python's bytes object can be a bit nasty. Generally speaking, you can not return from C/C++ land data as a bytes object without making a data copy. That's because memory for bytes object must be allocated as one chunk for both, the header and data itself. In DareBlopy this extra copy is eliminated, you can find details here.

In this test scenario, we read 200 files, each of which ~30kb. Reading is done from local filesystem and from a ZIP archive.

Reading files using DareBlopy is faster even when read from filesystem, but when read from ZIP it provides substantial improvement.

Reading JPEGs to numpy's ndarray

This is where DareBlopy's feature of direct readying to numpy array is demonstrated. When the file is read, it is decompressed directly to a preallocated numpy array, and all of that happens on C++ land while GIL is released.

Note: here PIL v.7.0.0 is used, on Ubuntu 18. In my installation, it does not use libjpeg-turbo.

It this case, difference between ZIP/filesystem is quite insignificant, but things change dramatically if filesystem is streamed over a network:

Reading TFRecords

DareBlopy can read TensorFlow records. This functionality was developed in the first place for reading FFHQ dataset from TFRecords.

It introduces alias to string type: uint8, which allows to return directly numpy array if the shape is known beforehand.

For example, code like:

        features = {
            'data': db.FixedLenFeature([], db.string)
        }

Can be replaced with:

        features = {
            'data': db.FixedLenFeature([3, 32, 32], db.uint8)
        }

This decoding to numpy array comes at zero cost, which is demonstrated below:

Tutorial

Import DareBlopy

import dareblopy as db
from IPython.display import Image, display
import PIL.Image

Open zip archive:

archive = db.open_zip_archive("test_utils/test_image_archive.zip")

Read image to bytes and display:

b = archive.open_as_bytes('0.jpg')
Image(b)

jpeg

Alternatively, read image to numpy:

img = archive.read_jpg_as_numpy('0.jpg')
img.shape
(256, 256, 3)
display(PIL.Image.fromarray(img))

png

For more advanced usage please refer to:

License

Apache License 2.0

Metadata

Release files for dareblopy 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for dareblopy 0.0.5
File
dareblopy-0.0.5-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
dareblopy-0.0.5-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details
dareblopy-0.0.5-cp38-cp38-manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64 Details
dareblopy-0.0.5-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
dareblopy-0.0.5-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
dareblopy-0.0.5-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details
dareblopy-0.0.5-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
dareblopy-0.0.5-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
dareblopy-0.0.5-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details
dareblopy-0.0.5-cp35-cp35m-manylinux2010_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.12+ x86-64 Details
dareblopy-0.0.5-cp34-cp34m-manylinux2010_x86_64.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.12+ x86-64 Details
dareblopy-0.0.5-cp27-cp27mu-manylinux2010_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.12+ x86-64 Details
dareblopy-0.0.5-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details
dareblopy-0.0.5-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details
dareblopy-0.0.5-cp27-cp27m-manylinux2010_x86_64.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.12+ x86-64 Details

Total release size: 96.6 MB

Release files / dareblopy-0.0.5-cp38-cp38-win_amd64.whl

Download URL dareblopy-0.0.5-cp38-cp38-win_amd64.whl
Size 1.4 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
1b3c724f0f7bc83e8f58c3ff8d19e7b5093bab3da9c74289a3b0066b34602495
BLAKE2b-256 checksum
How to use checksums
47bdd5aa6ff64be048b8519d8d42461b2f003dcaf8bfdeeecd7a8177708a603a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp38-cp38-win32.whl

Download URL dareblopy-0.0.5-cp38-cp38-win32.whl
Size 1.2 MB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
4738c620ec4829396d26e82749607f962e3f9ad42cf1ae4d51503909d086e900
BLAKE2b-256 checksum
How to use checksums
0733d449f6eb56f913407f2e4c29af10e2153354d8c6d21dcc19088c0e7dfe18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp38-cp38-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp38-cp38-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 3.8 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
9fbfe0f06d8fb68887225ab4b2f7aa831f6b26a9405f266ec50bcae33794c329
BLAKE2b-256 checksum
How to use checksums
85e6105445a3b2e303a78d166a8678ae8dbeacde5c3b53b4542afa50bc766573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / dareblopy-0.0.5-cp37-cp37m-win_amd64.whl

Download URL dareblopy-0.0.5-cp37-cp37m-win_amd64.whl
Size 1.4 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
199d11e9ef62df5374c91d549ac8116145eb86d22605f16447e04284f2812d87
BLAKE2b-256 checksum
How to use checksums
6491fbbd7c47936e13d97609c423c7cb17cd5e2e77ea9a47684c1f7474eb034a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp37-cp37m-win32.whl

Download URL dareblopy-0.0.5-cp37-cp37m-win32.whl
Size 1.2 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
1e5ab6a2deb41e10ff65509e82692d74ceaf9b7d837f1bfdb6e2827dfc8b9a2c
BLAKE2b-256 checksum
How to use checksums
445397bcda59ad0a7bc089c793fad90231589d2dfe008fce61d6d37dcfb52441
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp37-cp37m-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp37-cp37m-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
0302b0d4db187872f36401dc9c8342ceaf03dfa4654bbf7041f46300af8e6e51
BLAKE2b-256 checksum
How to use checksums
1497f2cec7c0f2d8c0be734d7b0b7203c54c602bcc2a29f1763fe350059ba69c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / dareblopy-0.0.5-cp36-cp36m-win_amd64.whl

Download URL dareblopy-0.0.5-cp36-cp36m-win_amd64.whl
Size 1.4 MB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
4d4cb248ab209e5a73ba291208ed5e37e299f3fd991b84e99708272b9f1ce805
BLAKE2b-256 checksum
How to use checksums
34c1bd34f1baf87a65674050fd00bdb07513545d77b9f296ba9c1dc4e817f7d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp36-cp36m-win32.whl

Download URL dareblopy-0.0.5-cp36-cp36m-win32.whl
Size 1.2 MB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
fca4c28aafd53fcd2fbe2f99cec60b2866fcc4429e2a2be85b8ecd227de9cd23
BLAKE2b-256 checksum
How to use checksums
963467f316e43f1d7c0fd83f23cef0cd4678022c74d9679fe55cc7f76379d814
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp36-cp36m-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp36-cp36m-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
c361291c55f28569c3c0d36e47a50d0d35c30e1d4eb9aafdfe79faa79e3c6970
BLAKE2b-256 checksum
How to use checksums
ddaf5248bb058c558886bd369a5d53d8dd87c77bbddf44c088b2b677e5de9ee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / dareblopy-0.0.5-cp35-cp35m-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp35-cp35m-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
0aaada1378ac6decbbc86359c0c67ca3e7fc512a49a82e3c61b411ad2cfb42d7
BLAKE2b-256 checksum
How to use checksums
346433c88923e06d186330bc2867bb6d87ce3ec9b2a0c46ed25fd7ca287d001b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / dareblopy-0.0.5-cp34-cp34m-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp34-cp34m-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
58ca250a12dfcb687845842f67d86f6f9973806b7d6400215c1125ce90034e13
BLAKE2b-256 checksum
How to use checksums
6b6cc7d9d1a1b29de4ce64873f8cc812fde6c782a7fc0b3e89f2f413d3bd37e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / dareblopy-0.0.5-cp27-cp27mu-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp27-cp27mu-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
f3ac40253b9fdafa6e55002be6701426bc3c15c9abe331db2c389413f0fadc31
BLAKE2b-256 checksum
How to use checksums
6284121577c1234f9cd6dbdbe8a2cec3fc09532dd1261954187df8ecf78fe923
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / dareblopy-0.0.5-cp27-cp27m-win_amd64.whl

Download URL dareblopy-0.0.5-cp27-cp27m-win_amd64.whl
Size 1.3 MB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
336c22cd738c9c9baf9358c07098976affeaeb1719e56c15bf8c9b0ddd2b8b41
BLAKE2b-256 checksum
How to use checksums
01b32457d79f767dff36cbf26b4e313ef0f0fd8d9ac0027ff9d70c94e577f771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp27-cp27m-win32.whl

Download URL dareblopy-0.0.5-cp27-cp27m-win32.whl
Size 1.1 MB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
cc1c0dfaf49ab98d0f90c5deae7b549709f7975a6c75f063bbf02d01c3b9848a
BLAKE2b-256 checksum
How to use checksums
995eb49e24dc0974db2da62ce82c62794a71bf8e6338ed7283662c0fc863e57f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.6

Release files / dareblopy-0.0.5-cp27-cp27m-manylinux2010_x86_64.whl

Download URL dareblopy-0.0.5-cp27-cp27m-manylinux2010_x86_64.whl
Size 12.3 MB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
799d58823e00e7930af7da43fe2c56bd32d2a81cec67121d6b95dd3e3704919b
BLAKE2b-256 checksum
How to use checksums
15267d73fb5b225e297cf4091dd30838b818ccf953872ee8ec9002ea2b8f0115
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.5 This release

15 release files

0.0.4

7 release files

0.0.2

7 release files

0.0.1

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page