Fnet setup

Label-free prediction of three-dimensional fluorescence images from transmitted light microscopy by Allen Institute

Chang-Min Hsu, Wen-Wei Tseng

Link to paper: http://dx.doi.org/10.1038/s41592-018-0111-2

The Nextjournal pytorch enviroment

Nextjournal had K80 as the GPU and CUDA 9.2 as runtime.

Python and PyTorch versions are listed below.

import platform, torch
print("Python version: %s.\nPyTorch version: %s." %
PyTorch (Python)

Cloning the repository

Using release_1 branch to reporduce the results in the Nature paper.

Not required in the Nextjournal notebook.

cd ~
git clone https://github.com/AllenCellModeling/pytorch_fnet.git -b release_1
PyTorch (Bash in Python)

Changes I made

The newer GPU models (e.g. Titan V) do not work on older pytorch versions as well as CUDA9 runtime. CUDA compile error would occur. Thus I had to remove version constraints on both pytorch and torchvision packages in environment.yml. As a result, the latest PyTorch and CUDA 10 will be installed.

The environment file by me:


To create and activate fnet enviroment in conda

Not required in the Nextjournal notebook as the environment is already set up.

conda create -f NJ__REF_
conda activate fnet
Shift+Enter to run
PyTorch (Bash in Python)

Installing fnet packages in the repo

Note: Install fnet package before download data or you'll overflow the temp directory from pip caching and the content in the repository.

cd ~/pytorch_fnet  # The folder where the repo resides
pip install .
PyTorch (Bash in Python)

Fix 'cannot import name imsave'

imsave() is deprecated and removed since scipy 1.2.0. Installing the older one instead.

pip install scipy==1.1.0
PyTorch (Bash in Python)
# List packages
conda list
Shift+Enter to run
PyTorch (Bash in Python)

Test run

cd ~/pytorch_fnet
chmod +x ./scripts/test_run.sh
PyTorch (Bash in Python)

Downloading dataset



Downloads all data (do not do this in the Nextjournal Notebook).

They are over 500GB in total so a large enough storage is required. I put them in the NAS and mount it via SMB.

sudo mount -t cifs -o username=sosiristseng,password=********,gid=1000,uid=1000 //<NAS IP address>/lab /home/sosiristseng/lab

Train a model

For example, to train the DNA image model with the first GPU:

./scripts/train_model.sh dna 0

Run predictions with the trained model

./scripts/predict.sh dna 0


  • GTX 1080 Ti: 16 hrs per dataset

  • Titan V: 14.5 hrs (52400 secs) per dataset

Consistent with this benchmark

Visualizing .czi files

  1. Download and extract ImageJ

  2. Dwonload BioFormats .jar package and put it into the folder of ImageJ

  3. Profit!

Runtimes (1)