Skip to content

Instantly share code, notes, and snippets.

@uschmidt83
Last active September 29, 2023 15:43
Show Gist options
  • Save uschmidt83/4b747862fe307044c722d6d1009f6183 to your computer and use it in GitHub Desktop.
Save uschmidt83/4b747862fe307044c722d6d1009f6183 to your computer and use it in GitHub Desktop.

This note shows how to make a new Python environment containing TensorFlow 1.x, load a model based on CSBDeep, and then export via export_TF(). Please see this on why you might want to do this.

As an example, we load a StarDist model and export it from the new environment. But the same should also work accordingly with all CSBDeep model types.

Assuming that you use conda to manage your environments (if not, e.g. read this), do the following:

  1. Create a new Python environment and install TensorFlow 1.x, CSBDeep and other necessary packages (e.g. StarDist):
conda create -y --name tf1_model_export python=3.7
conda activate tf1_model_export
# note: gpu support is not necessary for tensorflow
pip install "tensorflow<2"
pip install "csbdeep[tf1]"
# also install stardist in this example
pip install "stardist[tf1]"
  1. Make a new Python script to export the model:
from stardist.models import StarDist2D
model = StarDist2D(None, name='my_model', basedir='.')
model.export_TF()
  1. Run the script to export the model
@uschmidt83
Copy link
Author

The correct version of h5py should've been automatically installed when you do pip install "csbdeep[tf1]" or pip install "stardist[tf1]".

Sorry, just seeing that this has changed in our code, but we haven't released this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment