Skip to content

qreader.detect_and_decode() -> "Unable to allocate 44.1 TiB for an array with shape (2939262272, 5504, 3)" #54

@Psilopa

Description

@Psilopa

Not 100% sure if this is a QReader issue, but it seems like the prime suspect here.

On calling qreader.detect_and_decode(), I got a crash after the code tried to use 44.1 TB of memory. As the dimensions of

Here's the traceback:
Traceback (most recent call last):
File "C:\Python3115\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Python3115\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "C:\ImagingData\jkm\jkm_postprocessing_cli.py", line 246, in processSampleEvents
successQ = processSingleEvent(filename,data_out_table)
File "C:\ImagingData\jkm\jkm_postprocessing_cli.py", line 131, in processSingleEvent
bkdata = image.readbarcodes(barcodepackage)
File "C:\ImagingData\jkm\jkm\sample.py", line 198, in readbarcodes
bkdata = jkm.barcodes.extractbarcodedata(img, qrpackage, encoding='ascii')
File "C:\ImagingData\jkm\jkm\barcodes.py", line 63, in extractbarcodedata
d = extract_qreader(greyimg)
File "C:\ImagingData\jkm\jkm\barcodes.py", line 34, in extract_qreader
decoded_text = qreader.detect_and_decode(image=greyimg)
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\qreader_init
.py", line 223, in detect_and_decode
detections = self.detect(image=image, is_bgr=is_bgr)
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\qreader_init
.py", line 153, in detect
return self.detector.detect(image=image, is_bgr=is_bgr)
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\qrdet\qrdet.py", line 84, in detect
results = _yolo_v8_results_to_dict(results = results[0], image=image)
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\qrdet_qrdet_helpers.py", line 100, in _yolo_v8_results_to_dict
crop_qr(image=image, detection=detections[0], crop_key=PADDED_QUAD_XYN)
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\qrdet_qrdet_helpers.py", line 199, in crop_qr
image = np.pad(image, ((top_pad, bottom_pad), (left_pad, right_pad), (0, 0)), mode='constant',
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\numpy\lib_arraypad_impl.py", line 842, in pad
padded, original_area_slice = _pad_simple(array, pad_width)
File "C:\Users\digi_luo\AppData\Roaming\Python\Python311\site-packages\numpy\lib_arraypad_impl.py", line 115, in _pad_simple
padded = np.empty(new_shape, dtype=array.dtype, order=order)
numpy._core._exceptions._ArrayMemoryError: Unable to allocate 44.1 TiB for an array with shape (2939262272, 5504, 3) and data type uint8
The originating code is here: https://github.com/Psilopa/jkm/blob/main/jkm/barcodes.py

Looks like pad values get real odd as the new shape is "(2939262272, 5504, 3)" ... original images are 8256 x 5504 x 3).

This did not happen immediately: the same code was running for a few hours, processing hundreds of images. Using another QR code package (pyzbar) we have not run into this issue with over 200.000 images processed.

The full originating code is here: https://github.com/Psilopa/jkm/blob/fix_write_after_rename/jkm/barcodes.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions