-
Notifications
You must be signed in to change notification settings - Fork 129
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
Use bioimageio.core to generate model export (WIP) #158
Conversation
Let me know if you prefer a PR in your forked repo. Meanwhile:
from keras.models import Model
unet = load_model(os.path.join(full_QC_model_path, 'weights_best.hdf5'), custom_objects={'_weighted_binary_crossentropy': weighted_binary_crossentropy(np.ones(2))})
# Create a model without compilation so it can be used in any other environment.
input = unet.input
single_output = unet.output
unet = Model(input, single_output) I've just seen that in this notebook they import keras directly rather than from TF. This could fail again in the bioimageio.core validator.
|
@esgomezm I continued a bit on this and have used your code snippet to export the "uncompiled" keras model.
and I also haven't implemented tensorflow weight export yet. (It would be good to implement a function in bioimageio.core for this, maybe we can discuss this now.) |
Do you mean
For the export to TF, we can take the function in
|
Yes, sorry I always mix this up.
Yes, it would be good if we could re-implement this function in |
I have updated the notebook now so that it also adds the tensorflow weights. The model is available here: @esgomezm could you again share the new model with me? |
Nice. Please, find it here: https://drive.google.com/drive/u/0/folders/1-vGzP95Po_Pu0n6K1ei5GYKlGU2aqI74 |
@esgomezm I had to fix a few more things, but now it's almost working: Here's the current model (without threshold): https://drive.google.com/file/d/1-LWeHUBUp_1xeqUAxph6ugby659N4y6r/view?usp=sharing |
@esgomezm I have updated the thresholding now so that the tests also pass when applying it. |
@esgomezm we fixed a few more things and now everything should be working if you use: At some point we should also tackle the model import. That should be pretty straightforward:
|
@esgomezm I have updated the notebook now so that it uses the correct versions of the bioimageio.core library and I have also implemented loading a pretrained model from bioimage.io. Here is the most recent model I have exported with the notebook: https://drive.google.com/file/d/1-LWeHUBUp_1xeqUAxph6ugby659N4y6r/view?usp=sharing |
Is there any 2D UNet uploaded to zenodo so I can try the bioimage.io model load from the notebook? Currently the bioimage model zoo is empty and the old version is not working so I cannot access any model |
@esgomezm yes, you can use this model to try: https://drive.google.com/file/d/1-LWeHUBUp_1xeqUAxph6ugby659N4y6r/view |
Hey @constantinpape, Happy New Year! I managed to make the notebook working also with a pre-trained model and the bioimage.io model also works in deepImageJ :) I'm cleaning the output to update it in my repo so I can then accept your pull request here with the updated notebook. Also, I tried to upload the model to the BMZ but I get the following message referring to the version number. I think it has to do more with the bioimageio.core export model functionality than with the notebook: |
Solved the part of the validator. The name in the rdf.yaml needs to be the same we write in the upload formulary. There's a PR already opened from my repository and I cannot create a new one until this is either accepted or closed. Please let me know how you want to proceed. |
Hi @esgomezm and also happy new year :). |
Update notebook
I merged your PR @esgomezm and I think this is good to go. |
The cell is running through, but there are still several issues:
test_model
cannot be used because of the dask import error caused by mismatch with pyyaml version (fixed by installing an older pyyaml < 6, see PyYAML 6.0 load() function requires Loader argument yaml/pyyaml#576)scale_range
andscale_linear
) that I don't understand and that I am not adding right now.The notebook is available at
https://colab.research.google.com/github/constantinpape/ZeroCostDL4Mic/blob/master/Colab_notebooks/BioImage.io notebooks/U-Net_2D_ZeroCostDL4Mic_BioImageModelZoo_export.ipynb
(p.s. white spaces in urls are evil ;))
cc @esgomezm