U-Net for nuclei in fluorescence (bioimage.io affable-shark) β safetensors
This is the NucleiSegmentationBoundaryModel by Constantin Pape (EMBL Heidelberg), known on bioimage.io as affable-shark, converted from the original PyTorch state dict to safetensors.
It segments nuclei in fluorescence microscopy images, mainly with DAPI staining. For each pixel it predicts the probability of a nucleus (foreground) and of a nucleus boundary. The boundary channel separates touching nuclei.
The weights are unchanged. They are only stored in another file format. I did not retrain or fine-tune anything.
I made this conversion for EVAnalyzer, which runs the U-Net through its own Rust implementation and does not need Python or PyTorch. The file is a plain safetensors file, so any other tool that reads safetensors can load it too.
Files
| File | Content |
|---|---|
affable-shark.evanet |
the weights as safetensors, f32, about 116 MB |
.evanet is EVAnalyzer's extension for neural network models. The file itself is a
standard safetensors file, so you can rename it to .safetensors if your tool needs that.
SHA-256 of affable-shark.evanet:
76e07e7ddd0d99be0d9ce49c3efd984bee446109828663416a3a5ae8ee8cf2c7
Architecture
torch-em's UNet2d (2D U-Net):
| Argument | Value |
|---|---|
in_channels |
1 |
out_channels |
2 (foreground, boundaries) |
depth |
4 |
initial_features |
64 |
gain |
2 |
| normalization | InstanceNorm (torch-em's default) |
final_activation |
Sigmoid |
What changed in the conversion
- The 46 tensors keep torch-em's PyTorch names (
base.block.1.weight, ...,out_conv.weight) and are stored as f32. Nothing was left out. __metadata__holds the architecture and the source:evanalyzer_arch:unet2darch_version:1config:{"in_channels":1,"out_channels":2,"depth":4,"initial_features":64,"gain":2,"norm":"instance","final_activation":"sigmoid"}preprocessing:zero_mean_unit_variancename,description,source,license,citation
Check against the original
After the conversion, the file was loaded back and run on the bioimage.io package's own test
input (test_input_0.npy, 256 Γ 256), normalized as described below. Against the package's
expected output (test_output_0.npy), the largest difference is 2.6 Γ 10β»βΆ, and no pixel
changes sides of 0.5.
Use in Python with torch-em
from safetensors.torch import load_file
from torch_em.model import UNet2d
net = UNet2d(in_channels=1, out_channels=2, depth=4, initial_features=64, gain=2,
final_activation="Sigmoid")
net.load_state_dict(load_file("affable-shark.evanet"))
net.eval()
Input and output
- Input: one channel. Height and width must be multiples of 16 (at least 64). Normalize
each image to zero mean and unit variance first:
(x - mean) / (std + 1e-6)over all pixels. - Output: 2 channels with values from 0 to 1. Channel 0 is the foreground (nucleus) probability, channel 1 the boundary probability.
- To get single nuclei, remove the boundaries from the foreground and label the connected regions, or use a watershed or multicut on the boundaries.
In EVAnalyzer: the step AI UNet Segmentation with Output mode = independent channels, Foreground channel = 0 and Boundary channel = 1, followed by Extract Objects.
Training
From the original documentation: trained with torch-em on the nuclei of the 2018 Data Science Bowl (447 training and 50 validation images, Dice loss, Adam, learning rate 1e-4, 1458 epochs).
License
The original weights are published under CC-BY-4.0 (bioimage.io model affable-shark, Constantin Pape). This conversion keeps that license. The training data, the 2018 Data Science Bowl (BBBC038), is published under CC0.
Citation
If you use this model, please cite the original work:
- Constantin Pape: torch-em, the training library. doi:10.5281/zenodo.5108853
- Ronneberger, Fischer, Brox (2015): U-Net: Convolutional Networks for Biomedical Image Segmentation. doi:10.1007/978-3-319-24574-4_28
- Caicedo et al. (2019): Nucleus segmentation across imaging experiments: the 2018 Data Science Bowl. Nature Methods. doi:10.1038/s41592-019-0612-7
- The model on Zenodo: doi:10.5281/zenodo.5764892
Credits
All credit for the model goes to Constantin Pape (EMBL Heidelberg) and the bioimage.io community. This repository is not affiliated with or endorsed by them.