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.
- https://github.com/tensorflow/tensorflow/issues/62075#issuecomment-2295292911
- https://github.com/tensorflow/tensorflow/issues/62075#issuecomment-2305668525
- https://stackoverflow.com/questions/77338229/tensorflow-2-14-0-with-cuda-not-registering-cuda
- https://stackoverflow.com/questions/78894063/how-can-i-resolve-tensorflow-warnings-cudnn-cufft-cublas-and-numa
- https://stackoverflow.com/questions/78004801/setting-nvidia-driver-to-work-with-tensorflow-2-15-gpu
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 installation instructions recommends using the latest docker image so I selected the following
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
To run the jupyter notebook, we need to copy the link from the terminal and paste it in the browser
Start a new notebook.
Select the Python 3 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
After that you just need to import them as usual. You can see TensorFlow in action in my VisiumHD segmentation post