Closed romainGuiet closed 4 years ago
Hi @romainGuiet,
StarDist library works a bit different so the code needs to be adapted. There is a new notebook in the repository to store StarDist models as TensorFlow SavedModel:
It is written for StarDist version 0.3.6 (most updated version until now):
Once you read your model using StarDist2D:
model_paper = StarDist2D(None, name='your_model', basedir='/path_to_your_model/')
model_paper.load_weights('weights_best.h5')
the input and output are given as
# Input
model_paper.keras_model.input[0]
# Output 1: the object probability (normalized euclidean distance to the nearest background point)
model_paper.keras_model.output[0]
# Output 2: 32 radial distances to the boundary of the object
model_paper.keras_model.output[1]
Hence, to export it as a TensorFlow SavedModel you can now use a very similar code:
OUTPUT_DIR = "/content/drive/My Drive/the_path_where_you_want_to_save_your_model/new_folder"
builder = tf.saved_model.builder.SavedModelBuilder(OUTPUT_DIR)
# StarDist has two different outputs. DeepImageJ can only read one of them, so
# we concatenate them as different channels to use them in ImageJ.
signature = tf.saved_model.signature_def_utils.predict_signature_def(
inputs = {'input': model_paper.keras_model.input[0]},
# concatenate the output of StarDist
outputs = {'output': concatenate([model_paper.keras_model.output[0],model_paper.keras_model.output[1]], axis = 3)})
signature_def_map = { tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature }
builder.add_meta_graph_and_variables(K.get_session(), [tf.saved_model.tag_constants.SERVING],
signature_def_map=signature_def_map)
builder.save()
I hope this helps!
Thank you for reporting the issue
Hi @esgomezm, That's awesome! Thanks a lot for your efforts! Best,
Hi @deepimagej ,
I would like to use my own StarDist model ( we had to add images from our dataset with new annotations) but I can not find a way to export it (yet).
I tried re-using your code example but got these troubles :
-I’ve loaded my model using the function from StarDist and got :
so I guessed that StarDist model might not have an input !
So I tried to use the keras function from your code and got :
so the StarDist model might not be compatible with keras function!
Would you have an example of code for stardist?
Best regards,
Romain