Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Training an image-to-image (virtual staining) model with BiaPy

Same input as 01_training_instance_segmentation.ipynb, a different approach.

Instead of nuclei labels, the model predicts the DAPI image itself from the phalloidin channel. This is called virtual staining: predicting what a stain would have shown, without staining for it.

The output is an image, not objects. To count or measure nuclei you still need to segment it.

Again we need to organize the data into training, validation and test data.

Kernel: biapy on Research Cloud, nlbi26-day3-biapy on your own laptop.

1. The data

The target is now the DAPI image in training_data/nuclei/. Copy it into each split, next to images/ and labels/, so train, validation and test stay the same as in 01.

2. The settings

As in 01: take BiaPy’s template, change a few settings, save it under a new name.

3. Train

A few minutes on a GPU. Run biapy_out.show() in a new cell if you want to read the output.

4. Check the training graphs

The loss should go down, PSNR and SSIM should go up. Read the curves as in 01: still improving, flat, or overfitting?

5. What does it predict?

BiaPy already ran the model on the test images. Input, real DAPI and prediction side by side.

Where does the prediction differ from the real DAPI? Faint nuclei, bright ones, edges?

If you have time

Each of these is one line, then re-run the config cell, the training cell and the result cells. Give every run its own job_name.

config['MODEL']['ARCHITECTURE'] = 'unet'                    # plain U-Net instead of attention_unet
config['LOSS'] = {'TYPE': ['SSIM'], 'WEIGHTS': [1.0]}       # structure instead of pixel difference

Is the virtual DAPI good enough to segment? Run StarDist on the predictions in per_image/ as in 00_data_collection_stardist.ipynb (that notebook’s kernel), and compare the nuclei with the labels in dataset/test/labels/.