Skip to content

UNet Training

With PanSeg you can train bespoke segmentation models! This is especially useful to get great results on a big dataset for which the build-in models work not perfectly.
First proofread some images from the dataset. Then train a new model on this high-quality data, and run it on the whole dataset.

You can also fine-tune existing models on your data.

Training from a dataset

For training from an dataset stored on disk, create the directories train and val. Your training images must be stored as h5 files in these directories. The h5 files must contain the input image under the raw key, and the segmentation under the label key.

mydataset/
├── train/
│   ├── first.h5
│   └── second.h5
└── val/
    ├── val_one.h5
    └── val_two.h5 

Train from GUI

To train from images loaded in the GUI, you need a layer containing the input image and one containing the segmentation. Make sure the quality of the segmentation is as good as possible by using the proofreading tool.

Widgets

Traceback (most recent call last):
  File "/home/runner/miniconda3/envs/panseg-dev/lib/python3.12/site-packages/markdown_exec/_internal/formatters/python.py", line 71, in _run_python
    exec_python(code, code_block_id, exec_globals)
  File "/home/runner/miniconda3/envs/panseg-dev/lib/python3.12/site-packages/markdown_exec/_internal/formatters/_exec_python.py", line 8, in exec_python
    exec(compiled, exec_globals)  # noqa: S102
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<code block: n22>", line 13, in <module>
    html = render_widget(w, skip_name=True, skip_doc=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/panseg/panseg/docs/snippets/napari_widgets_render.py", line 93, in render_widget
    widget_par_doc = get_parameters_tooltips(widget)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/panseg/panseg/docs/snippets/napari_widgets_render.py", line 37, in get_parameters_tooltips
    for key in widget._param_options.keys():
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/miniconda3/envs/panseg-dev/lib/python3.12/site-packages/magicgui/widgets/bases/_container_widget.py", line 117, in __getattr__
    return object.__getattribute__(self, name)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute '_param_options'