CAREamics / careamics

A deep-learning library for N2V and friends
https://careamics.github.io/
BSD 3-Clause "New" or "Revised" License
28 stars 5 forks source link

BioImage.io export [BUG] #80

Closed CatEek closed 4 months ago

CatEek commented 1 year ago

Method save_as_bioimage of Engine produces this for certain output shapes

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[9], line 1
----> 1 engine.save_as_bioimage(engine.cfg.experiment_name + "bioimage.zip")

File [~/projects/caremics/src/careamics_restoration/engine.py:762](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/home/igor.zubarev/projects/caremics/examples/3D/~/projects/caremics/src/careamics_restoration/engine.py:762), in Engine.save_as_bioimage(self, output_zip, model_specs)
    759     specs = self._generate_rdf(model_specs)
    761     # Build model
--> 762     raw_model = build_zip_model(
    763         path=output_zip,
    764         config=self.cfg,
    765         model_specs=specs,
    766     )
    768     return raw_model
    769 else:

File [~/projects/caremics/src/careamics_restoration/bioimage/io.py:166](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/home/igor.zubarev/projects/caremics/examples/3D/~/projects/caremics/src/careamics_restoration/bioimage/io.py:166), in build_zip_model(path, config, model_specs)
    163     model_specs["tags"].append("2D")
    165 # build model zip
--> 166 raw_model = build_model(
    167     output_path=Path(path).absolute(),
    168     **model_specs,
    169 )
    171 # remove the temporary files
    172 weight_path.unlink()

File [/localfast/mambaforge/envs/cmcs_lf/lib/python3.11/site-packages/bioimageio/core/build_spec/build_model.py:802](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/localfast/mambaforge/envs/cmcs_lf/lib/python3.11/site-packages/bioimageio/core/build_spec/build_model.py:802), in build_model(weight_uri, test_inputs, test_outputs, input_axes, output_axes, name, description, authors, tags, documentation, cite, output_path, architecture, model_kwargs, weight_type, sample_inputs, sample_outputs, input_names, input_step, input_min_shape, input_data_range, output_names, output_reference, output_scale, output_offset, output_data_range, halo, preprocessing, postprocessing, pixel_sizes, maintainers, license, covers, git_repo, attachments, packaged_by, run_mode, parent, config, dependencies, links, training_data, root, add_deepimagej_config, tensorflow_version, opset_version, pytorch_version, weight_attachments)
    800 documentation = _ensure_local(documentation, root)
    801 if covers is None:
--> 802     covers = _generate_covers(root [/](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/) test_inputs[0], root [/](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/) test_outputs[0], input_axes[0], output_axes[0], root)
    803 else:
    804     covers = _ensure_local(covers, root)

File [/localfast/mambaforge/envs/cmcs_lf/lib/python3.11/site-packages/bioimageio/core/build_spec/build_model.py:499](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/localfast/mambaforge/envs/cmcs_lf/lib/python3.11/site-packages/bioimageio/core/build_spec/build_model.py:499), in _generate_covers(in_path, out_path, input_axes, output_axes, root)
    496 cover_path = os.path.join(root, "cover.png")
    497 input_, output = np.load(in_path), np.load(out_path)
--> 499 input_ = to_image(input_, input_axes)
    500 # this is not image data so we only save the input image
    501 if output.ndim < 4:

File [/localfast/mambaforge/envs/cmcs_lf/lib/python3.11/site-packages/bioimageio/core/build_spec/build_model.py:479](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/localfast/mambaforge/envs/cmcs_lf/lib/python3.11/site-packages/bioimageio/core/build_spec/build_model.py:479), in _generate_covers..to_image(data, data_axes)
    477 # transpose the data to "bczyx" [/](https://vscode-remote+ssh-002dremote-002bvdi.vscode-resource.vscode-cdn.net/) "bcyx" order
    478 axes = "bczyx" if data.ndim == 5 else "bcyx"
--> 479 assert set(data_axes) == set(axes)
    480 if axes != data_axes:
    481     ax_permutation = tuple(data_axes.index(ax) for ax in axes)

AssertionError:

Need yo change dummy outputs shape in _get_sample_io_files

Combine this with

https://www.notion.so/RSE-Projects-12392129a1284f88b153dd4c60cff2da?p=fec0e23175df4ffca8653cd7e3d675a2&pm=s

mese79 commented 1 year ago

In the previous update, config axes was "SYX" for 2D, but now it is "YX", and this causes the above error.
I've made a fix in bioimage_export branch.

jdeschamps commented 12 months ago

@CatEek do you have an example for reproducibility?

It might be fixed in #85 thanks to #81