Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bioimaging inference tool #1580

Merged
merged 19 commits into from
Feb 26, 2025
Merged

Conversation

anuprulez
Copy link
Contributor

Fixes #1544 issue

]]>
</command>
<inputs>
<param name="input_imaging_model" type="data" format="zip" label="BioImage.IO model" help="Please upload a BioImage.IO model."/>
<param name="input_image_file" type="data" format="tiff,png" label="Input image" help="Please provide an input image for the analysis."/>
<param name="input_image_input_size" type="text" label="Size of the input image" help="Provide the size of the input image. See the chosen model's RDF file to find the correct input size. For example: for the BioImage.IO model MitochondriaEMSegmentationBoundaryModel, the input size is 256 x 256 x 32 x 1. Enter the size as 256,256,32,1."/>
<param name="input_image_input_axes" type="text" label="Axes of the input image" 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 'bzyx'"/>
Copy link
Owner

Choose a reason for hiding this comment

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

could this be a select?

Copy link
Owner

Choose a reason for hiding this comment

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

btw. a text param can also have select options ...

Copy link
Contributor

Choose a reason for hiding this comment

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

can't it be extracted from the rdf so that the user doesn't need to know this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parameter axes provides the real shape (number of dimensions) of the input image/matrix required by the model to make inferences. The parameter input_size is necessary to slice pixels from different input image dimensions. So, both parameters I think are important to ascertain the target size of the image to be provided to the model. RDF file is not available inside the tool from where we could extract the axes information. Also, In a few RDF files, the axes information is not straightforward and written like (from 3d-unet-arabidopsis-apical-stem-cells model):

inputs:
  - axes:
      - type: batch
      - channel_names:
          - channel0
        id: channel
        type: channel
      - id: z
        scale: 1
        size: 100
        type: space
      - id: 'y'
        scale: 1
        size: 128
        type: space
      - id: x
        scale: 1
        size: 128
        type: space

Users have to infer the correct axes information from above. From above, it is bczyx. Other RDF files have this information directly given as bczyx. (bczyx == batch, channel, z, y, x)

I can provide this as a select option.

Copy link
Contributor

Choose a reason for hiding this comment

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

@FynnBe I understood that the info in the RDF file is standardised, right?

<param name="input_image_file" value="input_platynereisemnucleisegmentationboundarymodel.tif" location="https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/organized-badger/1/files/sample_input_0.tif"/>
<param name="input_image_input_size" value="256,256,32,1"/>
<param name="input_image_input_axes" value="bczyx"/>
<output name="output_predicted_image" file="output_platynereisemnucleisegmentationboundarymodel.tif" compare="sim_size" delta="100" />
Copy link
Owner

Choose a reason for hiding this comment

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

@bgruening
Copy link
Owner

If we store the RDF for every model, next to the model on our server and provide this as a second input ... do you think we can then support most models?

We could add a conditional:

  • try to extract model metadata from model RDF file
  • set metadata on your own

@bgruening
Copy link
Owner

We might be able to read the RDF file with https://github.com/bioimage-io/spec-bioimage-io

conda install -c conda-forge bioimageio.spec

Don't get me wrong, I think we can merge this PR as soon as it is green. Maybe we can add in a next iteration the automatic extraction?

<output name="output_predicted_image_matrix" file="output_nucleisegboundarymodel_matrix.npy" compare="sim_size" delta="100" />
</test>
<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"/>
<output name="output_predicted_image" file="output_nucleisegboundarymodel.tif" compare="sim_size" delta="100" />
<param name="input_image_input_axes" value="bcyx"/>
<output name="output_predicted_image" file="output_nucleisegboundarymodel.tif" compare="image_diff" />
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will try that to check if it works with TIF extensions. There are also NPY files which have similar sizes as TIFF files

Copy link
Owner

Choose a reason for hiding this comment

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

just check there size, but using assert-size

@anuprulez
Copy link
Contributor Author

anuprulez commented Feb 25, 2025

@bgruening can you rerun the tests? I am not sure why the first two tool tests fail. They show the following error:

Job in error state.. tool_id: bioimage_inference, exit_code: 1, stderr: Traceback (most recent call last):
  File "/home/runner/work/galaxytools/galaxytools/tools/bioimaging/main.py", line 7, in <module>
    import imageio
ModuleNotFoundError: No module named 'imageio'

If this is the error, the other tests from number 3 to 6 should also fail. Locally, all of them pass.

Thank you!

@bgruening
Copy link
Owner

This looks good to me!

Should we merge this one, so people can try it.

@anuprulez
Copy link
Contributor Author

Yes, I think so.

@bgruening bgruening merged commit e08711c into bgruening:master Feb 26, 2025
11 checks passed
@anuprulez anuprulez deleted the fix_imaging_tool branch February 26, 2025 10:49
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.

4 participants