Skip to content

Fix transposed dimensions#1609

Merged
kostrykin merged 3 commits intobgruening:masterfrom
anuprulez:fix_axes
Apr 15, 2025
Merged

Fix transposed dimensions#1609
kostrykin merged 3 commits intobgruening:masterfrom
anuprulez:fix_axes

Conversation

@anuprulez
Copy link
Copy Markdown
Contributor

@anuprulez anuprulez commented Apr 15, 2025

This PR fixes #1608

Tested with all the models in https://training.galaxyproject.org/training-material/topics/imaging/tutorials/process-image-bioimageio/tutorial.html

In the above tutorial, "NeuronSegmentationInEM" does not have any Pytorch model available at the mentioned link. I propose to change it to https://bioimage.io/#/?id=10.5281%2Fzenodo.5874741

ping @kostrykin

Copy link
Copy Markdown
Collaborator

@kostrykin kostrykin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Can you maybe please use something like <output name="output_predicted_image" file="result.tiff" ftype="tiff" compare="image_diff" /> for the tests?

<test>
<param name="input_imaging_model" value="input_imaging_model.zip" location="https://zenodo.org/api/records/6647674/files/weights-torchscript.pt/content"/>
<param name="input_image_file" value="input_nucleisegboundarymodel.png"/>
<param name="input_image_input_size" value="256,256,1,1"/>
<param name="input_image_input_axes" value="bcyx"/>
<output name="output_predicted_image" ftype="tiff">
<assert_contents>
<has_size size="524846" delta="110" />
</assert_contents>
</output>
<output name="output_predicted_image_matrix" ftype="npy">
<assert_contents>
<has_size size="524416" delta="110" />
</assert_contents>
</output>
</test>

This will be more reliable.

Copy link
Copy Markdown
Collaborator

@kostrykin kostrykin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to increment the @VERSION_SUFFIX@:

<token name="@VERSION_SUFFIX@">2</token>

@kostrykin
Copy link
Copy Markdown
Collaborator

kostrykin commented Apr 15, 2025

And another question, this is beyond the scope of this PR, but maybe we can discuss this :)

I tried to wrap my head around the input_axes parameter in this tool, but I just don't get it. Why is this input required?

<param name="input_image_input_axes" type="select" label="Axes of the input image" optional="false" help="Provide the input axes of the input image. See the chosen model's RDF file to find the correct axes. For example: for the BioImage.IO model MitochondriaEMSegmentationBoundaryModel, the input axes is 'bczyx'">
<option value="bczyx">bczyx</option>
<option value="bcyx">bcyx</option>
<option value="byxc">byxc</option>
</param>

The only place that I could find where it is used is in

target_dimension = len(input_axes)

so it looks like you only need the number of axes?

If this is the case, I have two follow-up questions:

  1. Wouldn't only two options be enough then, something like
   <option value="bcyx">Four axes (e.g., bcyx, byxc)</option> 
   <option value="bczyx">Five axes (e.g., bczyx)</option> 
  1. Can't this information be extracted from the input image directly? I mean, if it's just the number of axes, it should be the number of dimensions of the numpy array of the image, shouldn't it?

@anuprulez
Copy link
Copy Markdown
Contributor Author

so it looks like you only need the number of axes?

Yes, it is required to get the exact number of dimensions that the model needs to process the image.

  1. Wouldn't only two options be enough then, something like
   <option value="bcyx">Four axes (e.g., bcyx, byxc)</option> 
   <option value="bczyx">Five axes (e.g., bczyx)</option> 

Yes, it should work. I will make this change

  1. Can't this information be extracted from the input image directly? I mean, if it's just the number of axes, it should be the number of dimensions of the numpy array of the image, shouldn't it?

We are not currently taking input numpy arrays for processing as inputs, only TIFF and PNG. However, the numpy arrays might contain the correct number of dimensions that the models need but the TIFF files do not have this information. For example, the RDF file for this model "Mitochondria EM Segmentation Boundary Model" (https://bioimage.io/#/?id=10.5281%2Fzenodo.5874841) says that the input size is 256 x 256 x 32 x 1 but the input axes are bczyx. This difference I am not sure I understand it. The mode requires TIFF image to be represented as 5 dimensional to be processed.

@anuprulez
Copy link
Copy Markdown
Contributor Author

Thanks!

Can you maybe please use something like <output name="output_predicted_image" file="result.tiff" ftype="tiff" compare="image_diff" /> for the tests?

<test>
<param name="input_imaging_model" value="input_imaging_model.zip" location="https://zenodo.org/api/records/6647674/files/weights-torchscript.pt/content"/>
<param name="input_image_file" value="input_nucleisegboundarymodel.png"/>
<param name="input_image_input_size" value="256,256,1,1"/>
<param name="input_image_input_axes" value="bcyx"/>
<output name="output_predicted_image" ftype="tiff">
<assert_contents>
<has_size size="524846" delta="110" />
</assert_contents>
</output>
<output name="output_predicted_image_matrix" ftype="npy">
<assert_contents>
<has_size size="524416" delta="110" />
</assert_contents>
</output>
</test>

This will be more reliable.

I agree but with file="results.tiff", we have to keep results.tiff files in the test_data, no? These tiff files are big (> 1 MB) and the related tests may not pass. For smaller files (<1MB) we can do it

@kostrykin
Copy link
Copy Markdown
Collaborator

Yes, it should work. I will make this change

Awesome!

I agree but with file="results.tiff", we have to keep results.tiff files in the test_data, no? These tiff files are big (> 1 MB) and the related tests may not pass. For smaller files (<1MB) we can do it

At least for this particular test, the file is just about 500 kB: result.tiff.zip

@anuprulez
Copy link
Copy Markdown
Contributor Author

Also, opened a PR for updating the associated GTN tutorial to replace the unsupported TensorFlow model to a Pytorch one: galaxyproject/training-material#5957

Comment on lines 72 to 74
<assert_contents>
<has_size size="524846" delta="110" />
</assert_contents>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the image_diff check in place, I think we can remove this?

The has_size test is very heuristical, it might even raise a false-negative check failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

@kostrykin kostrykin enabled auto-merge April 15, 2025 14:36
@kostrykin
Copy link
Copy Markdown
Collaborator

Thanks!

@kostrykin
Copy link
Copy Markdown
Collaborator

For example, the RDF file for this model "Mitochondria EM Segmentation Boundary Model" (https://bioimage.io/#/?id=10.5281%2Fzenodo.5874841) says that the input size is 256 x 256 x 32 x 1 but the input axes are bczyx. This difference I am not sure I understand it.

Alright, we're on the same page here :)

@kostrykin kostrykin merged commit 399a62b into bgruening:master Apr 15, 2025
10 checks passed
@anuprulez anuprulez deleted the fix_axes branch April 15, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BMZ inference tool, inconsistency with input data

2 participants