Blosc2: Could not build empty array
I seem to be having issues with the Blosc2 library again.
I have installed master branch of nnUNet. I have tried different versions of Python and Blosc2.
I am unable to get the validation step of 3d_lowres to finish, so I can't proceed with 3d_cascade_fullres.
Is there an easy fix for this? I'm currently using np.savez_compressed(output_filename_truncated + '.npz', seg=seg.astype(np.uint8)) which at least saves the files and finishes without error, but this obviously doesn't work with cascade. I'm working through to see if there's a simple fix, but I haven't found one yet.
.venv312) [vmiller@gluskap nnUNetv2]$ CUDA_VISIBLE_DEVICES=0 nnUNet_compile=False nnUNetv2_train 602 3d_lowres 0 -p nnUNetResEncUNetMPlans --val
Using device: cuda:0
#######################################################################
Please cite the following paper when using nnU-Net:
Isensee, F., Jaeger, P. F., Kohl, S. A., Petersen, J., & Maier-Hein, K. H. (2021). nnU-Net: a self-configuring method for deep learning-based biomedical image segmentation. Nature methods, 18(2), 203-211.
#######################################################################
2025-06-10 13:43:48.680991: Using splits from existing split file: /home/vmiller/work/nnUNet/nnUNet_preprocessed/Dataset602_Cavity7/splits_final.json
2025-06-10 13:43:48.681550: The split file contains 5 splits.
2025-06-10 13:43:48.681923: Desired fold for training: 0
2025-06-10 13:43:48.682451: This split has 5 training and 2 validation cases.
2025-06-10 13:43:48.683149: predicting Bundles_003
2025-06-10 13:43:48.710807: Bundles_003, shape torch.Size([1, 124, 557, 124]), rank 0
2025-06-10 13:43:55.623185: predicting Nov-2017-AP-Hill-2L_006
2025-06-10 13:43:55.649772: Nov-2017-AP-Hill-2L_006, shape torch.Size([1, 124, 495, 124]), rank 0
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/home/vmiller/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
^^^^^^^^^^^^^^^^^^^
File "/home/vmiller/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/multiprocessing/pool.py", line 51, in starmapstar
return list(itertools.starmap(args[0], args[1]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/nnunetv2/inference/export_prediction.py", line 148, in resample_and_save
dataset_class.save_seg(segmentation.astype(dtype=np.uint8 if len(label_manager.foreground_labels) < 255 else np.uint16), output_file)
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/nnunetv2/training/dataloading/nnunet_dataset.py", line 192, in save_seg
blosc2.asarray(seg, urlpath=output_filename_truncated + '.b2nd', chunks=chunks_seg, blocks=blocks_seg)
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/blosc2/ndarray.py", line 3615, in asarray
ndarr = empty(shape, array.dtype, chunks=chunks, blocks=blocks, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/blosc2/ndarray.py", line 2981, in empty
return blosc2_ext.empty(shape, chunks, blocks, dtype, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "blosc2/blosc2_ext.pyx", line 2732, in blosc2.blosc2_ext.empty
File "blosc2/blosc2_ext.pyx", line 2234, in blosc2.blosc2_ext._check_rc
RuntimeError: Could not build empty array
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/vmiller/work/caml/nnUNetv2/.venv312/bin/nnUNetv2_train", line 8, in <module>
sys.exit(run_training_entry())
^^^^^^^^^^^^^^^^^^^^
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/nnunetv2/run/run_training.py", line 266, in run_training_entry
run_training(args.dataset_name_or_id, args.configuration, args.fold, args.tr, args.p, args.pretrained_weights,
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/nnunetv2/run/run_training.py", line 211, in run_training
nnunet_trainer.perform_actual_validation(export_validation_probabilities)
File "/home/vmiller/work/caml/nnUNetv2/.venv312/lib/python3.12/site-packages/nnunetv2/training/nnUNetTrainer/nnUNetTrainer.py", line 1339, in perform_actual_validation
_ = [r.get() for r in results]
^^^^^^^
File "/home/vmiller/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/multiprocessing/pool.py", line 774, in get
raise self._value
RuntimeError: Could not build empty array
(.venv312) [vmiller@gluskap nnUNetv2]$
@vmiller987, did you solve your issue?
@vmiller987, did you solve your issue?
Oof, no I did not. I actually closed the wrong issue. I was rushing last week. I haven't had time to dig into this issue, but I'm hoping this week to at least attempt to replicate it and dig through it.
Hi @vmiller987,
I think the issue arises as in the resample_and_seg neither chunks_seg nor blocks_seg are set, which in blosc2.asarray leads to the observed error. There needs to be some logic implemented to calculate the correct chunks_seg nor blocks_seg, I will let Fabi know of that and hope it will be fixed soon.
Best, Yannick
Hi @vmiller987,
I think the issue arises as in the
resample_and_segneitherchunks_segnorblocks_segare set, which inblosc2.asarrayleads to the observed error. There needs to be some logic implemented to calculate the correctchunks_segnorblocks_seg, I will let Fabi know of that and hope it will be fixed soon.Best, Yannick
I'm hoping to have some time later this week to replicate and see if I can confirm that's where the issue lies. I'm starting to dig deeper into nnUNet's code and trying to learn and understand more. I appreciate the advice!
Thanks, Vincent
Could you try modifying this line to
if chunks_seg is None and blocks_seg is None:
blosc2.asarray(seg, urlpath=output_filename_truncated + '.b2nd')
else:
blosc2.asarray(seg, urlpath=output_filename_truncated + '.b2nd', chunks=chunks_seg, blocks=blocks_seg)
That should work, even though it doesn't give you optimised parameters for efficient partial loading.
I encountered the same issue — in my case, the problem was that the folder where I wanted to save the compressed file didn’t exist. Creating the directory beforehand fixed it. Hope this helps someone else!
I'm experiencing the same problem when using blosc2==3.6.1. However, when I downgrade to blosc2==3.5.0, the code runs without issues.
@ykirchhoff I have not been able to replicate this problem. We've done major refactors on how we store and use our datasets along with discovering some hardware issues that we've resolved. As for now, I don't have this issue, and I've done a few cascade models now.
@PengchengShi1220 That is helpful. I checked and I've been using blosc2==3.5.1 without issue.
I've been back to nnUNet the last 2-3 weeks and haven't had any major issues.
I encountered the same issue — in my case, the problem was that the folder where I wanted to save the compressed file didn’t exist. Creating the directory beforehand fixed it. Hope this helps someone else!
what is the folder where I wanted to save the compressed file?
I try blosc2==3.5.1 and 3.5.0, but it doesn't work
I encountered this same issue, and the solutions above did not work. Removing the .b2nd files in the folder '.../nnUNetTrainer__nnUNetPlans__3d_lowres/predicted_next_stage/3d_cascade_fullres/' so that it would remake them has worked for me. Unfortunately i have no idea why it worked.