smartmicroscopy

Deep Learning Examples

A small PyTorch segmentation workflow, CZANN export, and ONNX Runtime inference. These are teaching examples, not validated production models or a guide to rigorous model training.

Setup

From the workshop root, the folder containing pixi.toml:

pixi install --locked

Open the notebooks in VS Code, select the workshop’s default Pixi kernel, and execute cells in order. The environment includes PyTorch, torchvision, czmodel, scikit-image, and ONNX Runtime; no separate notebook pip install is normally needed. GPU access is not required.

The setup uses workshop_utils.py to locate pixi.toml, add the example directory to imports, and report paths. For terminal commands use pixi run --locked ...: a VS Code interpreter selection does not activate an existing Conda/base terminal.

Choose a Notebook

Notebook Workflow Required inputs
unpack_czann.ipynb Extract a CZANN’s metadata and model into a temporary directory. data/DL_models/cyto2022_nuc2.czann
run_prediction_from_czann.ipynb Load a CZANN’s ONNX model, predict one image at a time, and compare with labels. The same CZANN plus nucleus images/labels.
SingleClassSemanticSegmentation_PyTorch.ipynb Load grayscale PNG pairs, train a simple two-class nuclei model, and export CZANN from an in-memory model or JSON specification. Nucleus images/labels; JSON specification for the optional disk-conversion section.

Start with unpacking to inspect an existing model, then inference. Training/export is independent: the inference notebook defaults to cyto2022_nuc2.czann, not the model produced by the training notebook. Changing models also requires checking input/output layout and preprocessing.

Inputs and Outputs

Important Caveats