Using TensorFlow in 2025

With the increasing use of AI and neural networks in modern single cell and spatial tools and applications, a working installation of TensorFlow is a must.

On the good old days, installing TensorFlow was kind of straigh forward, I always followed the excellent PyImageSearch guide. It involved the following steps:

  • Install Ubuntu dependencies
  • Install NVIDIA drivers, CUDA, and cuDNN
  • Install pip and set a virtual environment
  • Install TensorFlow in the virtual environment
  • Install useful Python packages

However it does not work anymore. According to the TensorFlow documentation and other guides (see this for example), it should as easy as using the pip package manager.

Sadly, it did not work for me as my GPU was not being detected. After a lot of googling, chatGPTing and stackoverflow reading it turns out that installing and setting TensorFlow is kind of knightmare lately. I let you here a few links if wish to read more about it.

After multipe testing, including trying google colab with a GPU (it kind of worked but I got random disconnections in the middle of the training and had memory limits issues) I decided to try a docker installation. In fact, this is adviced in the TensorFlow documentation.

TensorFlow Docker

TensorFlow installation instructions recommends using the latest docker image so I selected the following

TF docker images

but, again, it did not work on my computer and I ended up using the 2.15.0-gpu-jupyter image and running docker as follows to have access to the downlodaded data and juptyer notebook:

1docker run -p 8888:8888 -v /path/to/data/:/tf/visium --gpus all -it --rm tensorflow/tensorflow:2.15.0-gpu-jupyter

Running docker

To run the jupyter notebook, we need to copy the link from the terminal and paste it in the browser

Jupiter notebook in your browser

Start a new notebook.

New Notebook

Select the Python 3 kernel.

Python Kernel

we start installing the required packages with pip from inside the notebook:

1!pip install pandas numpy matplotlib anndata geopandas scanpy tifffile csbdeep stardist shapely scipy pyarrow leidenalg

Package installation

After that you just need to import them as usual. You can see TensorFlow in action in my VisiumHD segmentation post

comments powered by Disqus