MIC-DKFZ / acvl_utils

7 stars 3 forks source link

broken nnunetv2 import #2

Open jeandre-db opened 1 week ago

jeandre-db commented 1 week ago

ImportError: cannot import name 'crop_to_bbox' from 'acvl_utils.cropping_and_padding.bounding_boxes' (/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.11/site-packages/acvl_utils/cropping_and_padding/bounding_boxes.py) File , line 7 5 import pyspark.sql.functions as f 6 from nnunetv2.imageio.simpleitk_reader_writer import SimpleITKIO ----> 7 from nnunetv2.inference.predict_from_raw_data import nnUNetPredictor 8 from nnunetv2.paths import nnUNet_results, nnUNet_raw 9 import torch

It seems that the update to acvl broke nnunetv2 imports. locking the version to 0.2 fixes this issue.

joshuacwnewton commented 6 days ago

I'm getting the same error. Here's a more detailed traceback:

  File "/home/runner/sct_0.0/spinalcordtoolbox/deepseg/inference.py", line 27, in <module>
    import spinalcordtoolbox.deepseg.nnunet as ds_nnunet
  File "/home/runner/sct_0.0/spinalcordtoolbox/deepseg/nnunet.py", line 13, in <module>
    from nnunetv2.inference.predict_from_raw_data import nnUNetPredictor   # noqa: E402
  File "/home/runner/sct_0.0/python/envs/venv_sct/lib/python3.9/site-packages/nnunetv2/inference/predict_from_raw_data.py", line 22, in <module>
    from nnunetv2.inference.data_iterators import PreprocessAdapterFromNpy, preprocessing_iterator_fromfiles, \
  File "/home/runner/sct_0.0/python/envs/venv_sct/lib/python3.9/site-packages/nnunetv2/inference/data_iterators.py", line 12, in <module>
    from nnunetv2.preprocessing.preprocessors.default_preprocessor import DefaultPreprocessor
  File "/home/runner/sct_0.0/python/envs/venv_sct/lib/python3.9/site-packages/nnunetv2/preprocessing/preprocessors/default_preprocessor.py", line 23, in <module>
    from nnunetv2.preprocessing.cropping.cropping import crop_to_nonzero
  File "/home/runner/sct_0.0/python/envs/venv_sct/lib/python3.9/site-packages/nnunetv2/preprocessing/cropping/cropping.py", line 5, in <module>
    from acvl_utils.cropping_and_padding.bounding_boxes import get_bbox_from_mask, crop_to_bbox, bounding_box_to_slice
  File "/home/runner/sct_0.0/python/envs/venv_sct/lib/python3.9/site-packages/acvl_utils/cropping_and_padding/bounding_boxes.py", line 5, in <module>
    import blosc2
ModuleNotFoundError: No module named 'blosc2'

The culprit seems to be https://github.com/MIC-DKFZ/acvl_utils/commit/e49f45c257fb6cfdcd9192e709961a759bc31065, where an import blosc2 was added. I presume that package is present in @FabianIsensee's development environment, but missing in acvl_utils's dependencies:

https://github.com/MIC-DKFZ/acvl_utils/blob/b2493d4a733bc21d2e2508ec03f470512652d3e1/setup.py#L11-L18

I assume the fix should be as simple as pip install blosc2 (or maybe changing the import to an optional import), but I imagine that acvs_utils==0.2.1 should be yanked as well?

jeandre-db commented 6 days ago

even with the import blosc2, the crop_to_bbox error persists unless you use acvl_utils==0.2

alireza-hokmabadi commented 6 days ago

I had the same error and found that the crop_to_bbox function from acvl_utils/cropping_and_padding/bounding_boxes.py was recently removed, which is causing this import issue with nnUNetPredictor.

By adding this function back into the file, the problem can be resolved. I've made a pull request to address this, and hopefully, it will be merged soon.

Proposed Solution: Add the following function to bounding_boxes.py:

def crop_to_bbox(array: np.ndarray, bounding_box: List[List[int]]): assert len(bounding_box) == len(array.shape), f"Dimensionality of bbox and array do not match. bbox has length " \ f"{len(bounding_box)} while array has dimension {len(array.shape)}" slicer = bounding_box_to_slice(bounding_box) return array[slicer]

jamesobutler commented 4 days ago

This issue has been reported by a user of TotalSegmentator using the 3D Slicer application. See https://discourse.slicer.org/t/totalsegmentator-failed-to-compute-results-returned-non-zero-exit-status-1/38142/6?u=jamesobutler

lassoan commented 2 days ago

Error reports are flooding in for 3D Slicer for TotalSegmentator. It would be great if this issue could be fixed soon! Thank you!

FabianIsensee commented 2 days ago

I am on a trip, will do this tomorrow when I am back. Sorry :-/

FabianIsensee commented 2 days ago

Hey all I tried to patch it from where I am. There is now a v0.2.2 with the missing function added back in and the blosc2 dependency added. I hope this fixes it. Please let me know if it works now. I will in the future set explicit package version dependencies in each release of nnU-Net (== instead of >=) to ensure this doesn't happen again. Not a big fan of the rigidity this causes but that's better than running into situations like these. Sorry for all the chaos I have caused! I will also yank v0.2.1 from pypi as soon as I can. I currently don't have access to that Best, Fabian

lassoan commented 2 days ago

Thank you!

Fixing the problem and yanking the broken version are sufficient as corrective actions. For preventive action, you could set up continuous testing by github actions (test all features that you would feel embarrassed about if they were broken).

Please do not set version with == as it can cause more problems than it solves (lot of unresolvable version incompatibility issues may come up at application level).

hhaentze commented 2 days ago

nnUNetv2 is working again on my system. Thanks for the patch!