Skip to main content

Lightweight inference package for dafne models

Project description

dafne-monai-inference

Lightweight inference and incremental learning package for Dafne models, built on MONAI and PyTorch.

Overview

This package provides:

  • Inference — sliding-window (3D) and slice-by-slice (2D) segmentation inference using trained Dafne models
  • Incremental learning — online fine-tuning of a deployed model on new annotated data, with optional EWC (Elastic Weight Consolidation) regularization to prevent catastrophic forgetting
  • Network architecturesDafneUnetModel and DafneDynUnetModel, wrapping MONAI's UNet and DynUNet with Dafne-compatible interfaces
  • Transforms — preprocessing pipeline with anisotropy handling, spacing normalization, and bounding-box cropping

Installation

pip install dafne-monai-inference

Requirements

  • Python >= 3.8
  • torch >= 2.0
  • monai >= 1.3
  • numpy >= 1.24
  • scikit-image >= 0.19

Usage

Inference

from dafne_inference.inference import run_inference

# model_obj: a DynamicTorchModel loaded from a .model file
# data_dict must contain 'image' (numpy array) and either 'affine' or 'resolution'
result = run_inference(model_obj, data_dict)
# result: dict { label_name: binary_mask (np.int8) }

Incremental learning

from dafne_inference.incremental import run_incremental_learning

# trainingData: dict with key 'image_list' (list of numpy arrays) and 'resolution'
# trainingOutputs: dict of masks corresponding to each image
run_incremental_learning(model_obj, trainingData, trainingOutputs, bs=1, minTrainImages=2)

Network architectures

from dafne_inference.networks import DafneUnetModel, DafneDynUnetModel

# Standard UNet
model = DafneUnetModel(
    spatial_dims=3,
    in_channels=1,
    out_channels=5,
    start_channel=32,
    n_levels=5
)

# Dynamic UNet (nnU-Net style)
model = DafneDynUnetModel(
    spatial_dims=3,
    in_channels=1,
    out_channels=5,
    kernels=[[3,3,3], [3,3,3], [3,3,3]],
    strides=[[1,1,1], [2,2,2], [2,2,2]]
)

License

GNU General Public License v3 or later (GPLv3+)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dafne_monai_inference-1.0.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dafne_monai_inference-1.0.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file dafne_monai_inference-1.0.0.tar.gz.

File metadata

  • Download URL: dafne_monai_inference-1.0.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for dafne_monai_inference-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5fb2ed250c05d26fe54322610400648f3911983018481a99e6589ac1c406cf53
MD5 4e5d4602347465e0e0cbf2341bcc8bc3
BLAKE2b-256 3631788d8a2b749db8a8cbbd911bb21fdd4ab959cc026b22e2e6e2207a302bae

See more details on using hashes here.

File details

Details for the file dafne_monai_inference-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dafne_monai_inference-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7b21e5eac2eb7fb7610b14e8a3a7e507631f61768a0f2c683901e9eac66d711
MD5 e70ac6e2eb963bee7130ab45e712fd5f
BLAKE2b-256 2bbac779d3db0772644e8a028a4dfddd43bc4e8b9d052ef25e125f83a924eb6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page