TensorFlow 2.0 migration

Hi all,

This is a general question but is there a plan to move Stardist, n2v and csbdeep to TensorFlow 2.0?

I’m asking because after the wonderful Neubias meeting I have quite a few tools I want to test.

Now some of these rely on TensorFlow 2 and I’m not looking forward to managing multiple CuDNN and Cuda versions on each machine to make sure that everyone is happy. Docker is not an option for us or our users right now, at least for working on local windows workstations…

So I’ll start by pinging the people who can give their opinions on the matter, sorry if I forget anyone… @frauzufall, @uschmidt83, @mweigert, @fjug?

Thanks for your input

4 Likes

Hi all,

even if you did not ping me directly, it just wanted to add that we (ZEISS Microscopy) just did switched our whole machine-learning backend to TensorFlow2. It is always work, but for our perspective a step we had to take.

And obviously we we be happy if the community also switches to using TF2, because this would simplify the import of external models into the ZEN ecosystem, a new feature that will be released soon and which was showcased at the NEUBIAS.

As promised there we also now released the respective PyPi package, that allows packaging TF.SavedModels (TF2) for our Segmentation Service into CZMODEL (more services like Image2image etc. will come).

For more information: PyPi - czmodel

1 Like

FWIW, Anaconda manages packages for both cudatoolkit and cudnn, so you should be able to set up different environments with different versions of those as needed.

4 Likes

As Jan said, conda environments with multiple versions of cuda/cudnn is the way forward. You can also link system cuda versions to conda environments, but it’s much easier to make a fresh conda environment, and then run e.g. conda install cudatoolkit=10.1 cudnn.

Also, fwiw I asked @mweigert this yesterday, and he said it’s planned (no date though).

2 Likes

Thanks @imagejan, @adamltyson,

OK I get that I should use conda to manage this.

How do you guys then have it setup for Fiji and the embedded plugins (CSBDEEP, DeepImageJ)? Are you then running a different conda environment for your Fiji installation as well?

1 Like

From Java perspective there are no bindings yet for TF 2, we have to wait and see which way will be the most useful in the future - pytorch Java bindings / bridge to python / TF2 when it get’s released / DL4J…

Sorry if that’s offtopic, bit here’s my setup to switch between CUDA versions in Linux:
I have multiple CUDA installations where I copied the cuDNN files into as well:

(base) ➜  ~ ls -l /usr/local
lrwxrwxrwx  1 root root   20 Feb  4 17:58 cuda -> /usr/local/cuda-10.0
drwxr-xr-x 19 root root 4096 Feb  4 17:58 cuda-10.0
drwxr-xr-x 17 root root 4096 Okt 17 23:24 cuda-10.1
drwxr-xr-x 17 root root 4096 Jul  9  2018 cuda-8.0
drwxr-xr-x 18 root root 4096 Jul  9  2018 cuda-9.0
drwxr-xr-x 18 root root 4096 Jul  9  2018 cuda-9.2

… my PATH points to the symbolic link:

export PATH=/usr/local/cuda/bin:${PATH}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}

… and then I can easily switch between them:

sudo ln -sfn /usr/local/cuda-9.0 /usr/local/cuda

To switch between TensorFlow versions, I use the Edit > Options > TensorFlow.. command.

5 Likes

Upgrading CSBDeep (which is also the foundation for StarDist and and n2v) to be compatible with TensorFlow 2.x has been on our TODO list for a while now. But honestly, I think you are the only one who has specifically asked us for this.

Besides installation issues, what are the benefits for users?

The CSBDeep Fiji plugin uses ImageJ-TensorFlow, which does not support Tensorflow 2.x.

1 Like

@uschmidt83 Another benefit for us is integrating StarDist into existing analysis software that depends on tf 2.x

To add what Uwe aleady said: Yes, moving to tf 2.x will happen at some point (biggest thing imo is rewriting the custom image tensorboard callbacks).

Wasn’t aware of this - that would be nasty then (as model export to Fiji is important for both csbdeep and stardist).
Although from the tf doc it appears that 2.x support is possible:
https://www.tensorflow.org/api_docs/java/reference/org/tensorflow/package-summary
or?

2 Likes

Hi all,

the latest release of CSBDeep (Python) does work with either TensorFlow 1 or 2.

Also, in a quick test we were able to export a model with TensorFlow 2.2.0 from Python and then use it with TensorFlow 1.14.0 in Fiji.

StarDist (Python) will be updated soon to be compatible with TensorFlow 2.

Best,
Uwe

6 Likes

Hi all! Awesome! Congrats @uschmidt83 for the work!

I just had a chance to setup StarDist with TF 2.1 from within Anaconda with almost no issues, including GPUTOOLS support.

https://c4science.ch/w/bioimaging_and_optics_platform_biop/computers-servers/software/gpu-deep-learning/miniconda/

There is still a little bug with
limit_gpu_memory(0.8) in the example notebooks:
ValueError: 'total_memory' must be provided when using TensorFlow 2.

So I need to provide the total memory explicitly? No worries about that, just wanted to be sure there wasn’t something else to do.

2 Likes

I don’t consider this a bug, since there’s no way around this then providing that value to the function.

Yes, you need to provide the total amount of memory that your GPU has (e.g. 8GB), such that I can compute a fraction of it. The API in TF2 has changed, there’s no easy way to use fraction instead.

1 Like