Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ on:
- main
paths:
- "docs/**"
- "api-docs/**"
- "napari_cellseg3d/**"
- "pyproject.toml"
- ".github/workflows/docs.yml"
- ".github/workflows/build_docs.yml"
pull_request:
branches:
- main
paths:
- "docs/**"
- "api-docs/**"
- "napari_cellseg3d/**"
- "pyproject.toml"
- ".github/workflows/docs.yml"
- ".github/workflows/build_docs.yml"
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -44,12 +46,16 @@ jobs:
- name: Install docs dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[docs]"
python -m pip install -e ".[docs,api-docs]"

- name: Build Jupyter Book
run: |
jupyter-book build docs/

- name: Build API reference
run: |
mkdocs build -f api-docs/mkdocs.yml

- name: Upload Pages artifact
if: github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@v3
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,17 @@ venv/
/napari_cellseg3d/code_models/models/dataset/
/napari_cellseg3d/code_models/models/saved_weights/
/docs/source/logo/old_logo/
/docs/source/code/_autosummary/
/reqs/
/loss_plots/
/wandb/
notebooks/csv_cell_plot.html
notebooks/full_plot.html
*.csv
*.png
!api-docs/docs/assets/*.png
notebooks/instance_test.ipynb
*.prof
/docs/_build/
/docs/source/code/_autosummary/*.rst
cov.syspath.txt
napari_cellseg3d/dev_scripts/wandb
wandb/
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ repos:
rev: 1.0.0
hooks:
- id: mdformat
exclude: ^api-docs/
additional_dependencies:
- mdformat-myst
- id: mdformat
name: mdformat (api-docs)
files: ^api-docs/
# keep mkdocs-autorefs [label][identifier] links unescaped
args: [--ignore-missing-references]
additional_dependencies:
- mdformat-mkdocs==5.3.0

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.21.2
Expand Down
Binary file added api-docs/docs/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions api-docs/docs/assets/stylesheets/cellseg3d.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* CellSeg3D palette: napari greys (napari_cellseg3d/interface.py) + logo purple/magenta */

:root {
--cs-napari-grey: #262930;
--cs-napari-darkgrey: #202228;
--cs-napari-param-grey: #414851;
--cs-purple: #5b3aa8;
--cs-purple-light: #a48be0;
--cs-magenta: #b0306a;
--cs-magenta-light: #e0609a;
}

[data-md-color-primary="custom"] {
--md-primary-fg-color: var(--cs-napari-grey);
--md-primary-fg-color--light: var(--cs-napari-param-grey);
--md-primary-fg-color--dark: var(--cs-napari-darkgrey);
--md-primary-bg-color: #ffffff;
--md-primary-bg-color--light: #ffffffb3;
}

[data-md-color-accent="custom"] {
--md-accent-fg-color: var(--cs-magenta);
--md-accent-fg-color--transparent: #b0306a1a;
}

[data-md-color-scheme="default"] {
--md-typeset-a-color: var(--cs-purple);
}

[data-md-color-scheme="slate"] {
--md-default-bg-color: var(--cs-napari-grey);
--md-default-bg-color--light: #262930b3;
--md-code-bg-color: var(--cs-napari-darkgrey);
--md-typeset-a-color: var(--cs-purple-light);
--md-accent-fg-color: var(--cs-magenta-light);
--md-accent-fg-color--transparent: #e0609a1a;
}

[data-md-color-scheme="slate"][data-md-color-primary="custom"] {
--md-primary-fg-color: var(--cs-napari-darkgrey);
}

/* The logo is a detailed disc: use the full header height */
.md-header__button.md-logo {
margin: 0;
padding: 0.2rem;
}

.md-header__button.md-logo img {
height: 2.6rem;
}

/* Landing page logo */
.md-typeset img.cs-hero-logo {
display: block;
margin: 1rem 0 2rem;
}
10 changes: 10 additions & 0 deletions api-docs/docs/high-level/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# High-level API

Entry points for running CellSeg3D from Python without the napari interface, as used in the [Colab notebooks](https://github.com/AdaptiveMotorControlLab/CellSeg3D/tree/main/notebooks).

- [Inference](inference.md): segment a volume with a pretrained model, then threshold and split it into instances.
- [Training](training.md): train WNet3D (self-supervised) or a supervised model.

Every object is configured with a dataclass from [`napari_cellseg3d.config`][napari_cellseg3d.config].

Other functionality is documented in the [API Reference](../reference/napari_cellseg3d/index.md).
38 changes: 38 additions & 0 deletions api-docs/docs/high-level/inference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Inference

```python
from tifffile import imread

from napari_cellseg3d.config import ModelInfo
from napari_cellseg3d.dev_scripts import remote_inference as cs3d

image = imread("examples/c5image.tif")

config = cs3d.CONFIG # InferenceWorkerConfig with defaults for a single volume
config.model_info = ModelInfo(name="SwinUNetR", model_input_size=64, num_classes=2)

results = cs3d.inference_on_images(image, config=config)

labels, stats = cs3d.post_processing(
results[0].semantic_segmentation,
config=cs3d.PostProcessConfig(),
)
```

For WNet3D, pass `results[0].semantic_segmentation[1]` to `post_processing`.

## Functions

::: napari_cellseg3d.dev_scripts.remote_inference.inference_on_images

::: napari_cellseg3d.dev_scripts.remote_inference.post_processing

::: napari_cellseg3d.dev_scripts.remote_inference.PostProcessConfig

## Configuration and worker

- [`InferenceWorkerConfig`][napari_cellseg3d.config.InferenceWorkerConfig]: device, model, weights, sliding window and post-processing settings.
- [`ModelInfo`][napari_cellseg3d.config.ModelInfo]: model name, input size and number of classes.
- [`SlidingWindowConfig`][napari_cellseg3d.config.SlidingWindowConfig]: window size and overlap.
- [`InferenceResult`][napari_cellseg3d.code_models.workers_utils.InferenceResult]: what `inference_on_images` returns, one per image.
- [`InferenceWorker`][napari_cellseg3d.code_models.worker_inference.InferenceWorker]: the worker `inference_on_images` runs.
50 changes: 50 additions & 0 deletions api-docs/docs/high-level/training.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Training

## WNet3D (self-supervised)

```python
from pathlib import Path

from napari_cellseg3d.config import WandBConfig, WeightsInfo, WNetTrainingWorkerConfig
from napari_cellseg3d.dev_scripts import colab_training as c

config = WNetTrainingWorkerConfig(
device="cuda:0",
max_epochs=50,
learning_rate=2e-5,
validation_interval=2,
batch_size=4,
num_workers=2,
weights_info=WeightsInfo(),
results_path_folder="results",
train_data_dict=c.create_dataset_dict_no_labs(Path("train_images")),
eval_volume_dict=c.create_eval_dataset_dict(Path("eval_images"), Path("eval_labels")), # or None
)

Path(config.results_path_folder).mkdir(parents=True, exist_ok=True)
worker = c.get_colab_worker(worker_config=config, wandb_config=WandBConfig(mode="disabled"))
Comment thread
Copilot marked this conversation as resolved.
Resolved
for _report in worker.train():
pass
```

::: napari_cellseg3d.dev_scripts.colab_training.get_colab_worker

::: napari_cellseg3d.dev_scripts.colab_training.create_dataset_dict_no_labs

::: napari_cellseg3d.dev_scripts.colab_training.create_eval_dataset_dict

- [`WNetTrainingWorkerConfig`][napari_cellseg3d.config.WNetTrainingWorkerConfig]: WNet3D hyperparameters and data.
- [`WNetTrainingWorker`][napari_cellseg3d.code_models.worker_training.WNetTrainingWorker]: `train()` is a generator yielding a `TrainingReport` per epoch and per validation.

## Supervised models

Supervised models (SegResNet, SwinUNetR, …) use the same pattern with their own config and worker:

- [`SupervisedTrainingWorkerConfig`][napari_cellseg3d.config.SupervisedTrainingWorkerConfig]
- [`SupervisedTrainingWorker`][napari_cellseg3d.code_models.worker_training.SupervisedTrainingWorker]

## Shared configuration

- [`TrainingWorkerConfig`][napari_cellseg3d.config.TrainingWorkerConfig]: fields common to all training configs.
- [`WeightsInfo`][napari_cellseg3d.config.WeightsInfo]: pretrained or custom weights.
- [`WandBConfig`][napari_cellseg3d.config.WandBConfig]: Weights & Biases logging.
9 changes: 9 additions & 0 deletions api-docs/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CellSeg3D API Reference

![napari-cellseg3D logo](assets/logo.png){ .cs-hero-logo width="280" }

Reference for the `napari_cellseg3d` Python package, generated from its docstrings.

To run inference or training from Python, start with the [High-level API](high-level/index.md).

For installation and usage of the napari plugin, see the [main user documentation](https://adaptivemotorcontrollab.github.io/CellSeg3D/).
96 changes: 96 additions & 0 deletions api-docs/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
site_name: CellSeg3D API Reference
site_description: API reference for napari-cellseg3d
site_url: https://adaptivemotorcontrollab.github.io/CellSeg3D/api/
site_dir: "../docs/_build/html/api"

repo_name: AdaptiveMotorControlLab/CellSeg3D
repo_url: https://github.com/AdaptiveMotorControlLab/CellSeg3D

theme:
name: material
logo: assets/logo.png
favicon: assets/logo.png
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
primary: custom
accent: custom
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: custom
accent: custom
toggle:
icon: material/brightness-4
name: Switch to light mode
features:
- content.code.copy
- navigation.indexes
- navigation.tabs
- navigation.top
- search.highlight
- search.suggest
- toc.follow

plugins:
- search
- autorefs
- api-autonav:
modules:
- "../napari_cellseg3d"
exclude:
- "napari_cellseg3d._tests"
- "napari_cellseg3d._version"
- "napari_cellseg3d.dev_scripts"
- "napari_cellseg3d.res"
- "napari_cellseg3d.setup"
nav_section_title: "API Reference"
api_root_uri: "reference"
exclude_private: true
- mkdocstrings:
default_handler: python
handlers:
python:
paths: [".."]
options:
docstring_style: google
docstring_options:
warn_missing_types: false
docstring_section_style: table
show_root_heading: true
show_symbol_type_heading: true
show_signature_annotations: true
separate_signature: true
summary: true
inventories:
- url: https://docs.python.org/3/objects.inv
domains: [py, std]
- url: https://numpy.org/doc/stable/objects.inv
- url: https://pytorch.org/docs/stable/objects.inv
- url: https://napari.org/stable/objects.inv

extra_css:
- assets/stylesheets/cellseg3d.css

markdown_extensions:
- admonition
- attr_list
- pymdownx.details
- pymdownx.highlight
- pymdownx.superfences

extra:
social:
- icon: material/book-open-variant
link: https://adaptivemotorcontrollab.github.io/CellSeg3D/
name: User documentation

nav:
- Home: index.md
- High-level API:
- high-level/index.md
- Inference: high-level/inference.md
- Training: high-level/training.md
- API Reference
10 changes: 0 additions & 10 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,11 @@ html:
use_issues_button: true
use_repository_button: true

# Add auto-generated API docs
sphinx:
extra_extensions:
- 'sphinx.ext.napoleon'
- 'sphinx.ext.autodoc'
- 'sphinx.ext.autosummary'
- 'sphinx.ext.viewcode'
- 'sphinx.ext.autosectionlabel'
config:
add_module_names: False
autosectionlabel_prefix_document: True
autosummary_generate: True
autoclass_content: "both"
# templates_path: ['_templates']
exclude_patterns:
- '_build'
- '_templates'
# - 'napari_cellseg3d/__pycache__'
32 changes: 0 additions & 32 deletions docs/_templates/custom-class-template.rst

This file was deleted.

Loading
Loading