nnInteractive 2.0.0__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nninteractive-2.0.0 → nninteractive-2.1.0}/PKG-INFO +71 -5
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/inference/inference_session.py +62 -6
- nninteractive-2.1.0/nnInteractive/inference/remote/__init__.py +11 -0
- nninteractive-2.1.0/nnInteractive/inference/remote/_protocol.py +27 -0
- nninteractive-2.1.0/nnInteractive/inference/remote/remote_session.py +470 -0
- nninteractive-2.1.0/nnInteractive/inference/remote/serialization.py +142 -0
- nninteractive-2.1.0/nnInteractive/inference/server/app.py +587 -0
- nninteractive-2.1.0/nnInteractive/inference/server/main.py +149 -0
- nninteractive-2.1.0/nnInteractive/utils/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive.egg-info/PKG-INFO +71 -5
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive.egg-info/SOURCES.txt +8 -0
- nninteractive-2.1.0/nnInteractive.egg-info/entry_points.txt +2 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive.egg-info/requires.txt +3 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/pyproject.toml +7 -1
- {nninteractive-2.0.0 → nninteractive-2.1.0}/readme.md +67 -4
- {nninteractive-2.0.0 → nninteractive-2.1.0}/LICENSE +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/inference/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/inference/cvpr2025_challenge_baseline/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/inference/cvpr2025_challenge_baseline/predict.py +0 -0
- {nninteractive-2.0.0/nnInteractive/interaction → nninteractive-2.1.0/nnInteractive/inference/server}/__init__.py +0 -0
- {nninteractive-2.0.0/nnInteractive/trainer → nninteractive-2.1.0/nnInteractive/interaction}/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/interaction/point.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/setup.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/metadata.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/reader.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/run.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/automatic_mask_generator.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/benchmark.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/build_sam.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/backbones/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/backbones/hieradet.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/backbones/image_encoder.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/backbones/utils.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/memory_attention.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/memory_encoder.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/position_encoding.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/sam/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/sam/mask_decoder.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/sam/prompt_encoder.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/sam/transformer.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/sam2_base.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/modeling/sam2_utils.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/sam2_image_predictor.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/sam2_video_predictor.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/sam2_video_predictor_legacy.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/utils/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/utils/amg.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/utils/misc.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/sam2/utils/transforms.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/setup.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/sam2_datasets.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/transforms.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/utils.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/vos_dataset.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/vos_raw_dataset.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/vos_sampler.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/dataset/vos_segment_loader.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/loss_fns.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/model/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/model/sam2.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/optimizer.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/scripts/sav_frame_extraction_submitit.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/train.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/trainer.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/utils/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/utils/checkpoint_utils.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/utils/data_utils.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/utils/distributed.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/utils/logger.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/sam2/training/utils/train_utils.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/supervoxel/src/supervoxel.py +0 -0
- {nninteractive-2.0.0/nnInteractive/utils → nninteractive-2.1.0/nnInteractive/trainer}/__init__.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/trainer/nnInteractiveTrainer.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/bboxes.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/checkpoint_cleansing.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/crop.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/erosion_dilation.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/inference_helpers.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/os_shennanigans.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive/utils/rounding.py +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive.egg-info/dependency_links.txt +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/nnInteractive.egg-info/top_level.txt +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/setup.cfg +0 -0
- {nninteractive-2.0.0 → nninteractive-2.1.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nnInteractive
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: Inference code for nnInteractive
|
|
5
5
|
Author: Helmholtz Imaging Applied Computer Vision Lab
|
|
6
6
|
Author-email: Fabian Isensee <f.isensee@dkfz-heidelberg.de>
|
|
@@ -223,6 +223,9 @@ Requires-Dist: nnunetv2>=2.7.0
|
|
|
223
223
|
Requires-Dist: torch!=2.9.*,>=2.1.2
|
|
224
224
|
Requires-Dist: acvl-utils<0.3,>=0.2.3
|
|
225
225
|
Requires-Dist: batchgenerators>=0.25.1
|
|
226
|
+
Requires-Dist: fastapi>=0.110
|
|
227
|
+
Requires-Dist: uvicorn[standard]>=0.27
|
|
228
|
+
Requires-Dist: httpx>=0.27
|
|
226
229
|
Provides-Extra: dev
|
|
227
230
|
Requires-Dist: black; extra == "dev"
|
|
228
231
|
Requires-Dist: ruff; extra == "dev"
|
|
@@ -417,14 +420,42 @@ session.add_point_interaction(POINT_COORDINATES, include_interaction=False)
|
|
|
417
420
|
session.add_bbox_interaction(BBOX_COORDINATES, include_interaction=True)
|
|
418
421
|
|
|
419
422
|
# Example: Add a scribble interaction
|
|
420
|
-
# - A 3D image of the same shape as img where one slice (any axis-aligned orientation) contains a hand-drawn scribble.
|
|
421
423
|
# - Background must be 0, and scribble must be 1.
|
|
422
424
|
# - Use session.preferred_scribble_thickness for optimal results.
|
|
423
|
-
|
|
425
|
+
#
|
|
426
|
+
# ✅ RECOMMENDED (v2): pass a small 2D crop plus its location.
|
|
427
|
+
# Scribbles live on a single axis-aligned slice, so one of the three bbox
|
|
428
|
+
# dimensions is always size 1 and the in-plane extent typically covers only
|
|
429
|
+
# a small region. The cropped array is ORDERS OF MAGNITUDE
|
|
430
|
+
# smaller than a full-volume mask for typical annotations, which makes this
|
|
431
|
+
# path dramatically faster. Please prefer this
|
|
432
|
+
# form in new integrations.
|
|
433
|
+
#
|
|
434
|
+
# SCRIBBLE_CROP.shape must equal the bbox size. INTERACTION_BBOX uses
|
|
435
|
+
# half-open intervals [[x1,x2],[y1,y2],[z1,z2]] in original-image coordinates.
|
|
436
|
+
# Example: a scribble drawn on axial slice z=64, covering x∈[100,140), y∈[80,150):
|
|
437
|
+
# SCRIBBLE_CROP = <ndarray of shape (40, 70, 1), values 0 or 1>
|
|
438
|
+
# INTERACTION_BBOX = [[100, 140], [80, 150], [64, 65]]
|
|
439
|
+
session.add_scribble_interaction(
|
|
440
|
+
SCRIBBLE_CROP,
|
|
441
|
+
include_interaction=True,
|
|
442
|
+
interaction_bbox=INTERACTION_BBOX,
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
# Legacy form (still supported, but discouraged): a 3D array matching the
|
|
446
|
+
# full original image shape with the scribble baked into one slice.
|
|
447
|
+
# session.add_scribble_interaction(SCRIBBLE_IMAGE, include_interaction=True)
|
|
424
448
|
|
|
425
449
|
# Example: Add a lasso interaction
|
|
426
|
-
# -
|
|
427
|
-
|
|
450
|
+
# - Like scribble but the single slice contains a **closed contour** for the selection.
|
|
451
|
+
# - Same recommendation applies: pass a 2D crop + interaction_bbox for a large speedup.
|
|
452
|
+
session.add_lasso_interaction(
|
|
453
|
+
LASSO_CROP,
|
|
454
|
+
include_interaction=True,
|
|
455
|
+
interaction_bbox=INTERACTION_BBOX,
|
|
456
|
+
)
|
|
457
|
+
# Legacy full-volume form (discouraged):
|
|
458
|
+
# session.add_lasso_interaction(LASSO_IMAGE, include_interaction=True)
|
|
428
459
|
|
|
429
460
|
# You can combine any number of interactions as needed.
|
|
430
461
|
# The model refines the segmentation result incrementally with each new interaction.
|
|
@@ -452,6 +483,41 @@ session.set_target_buffer(torch.zeros(NEW_IMAGE.shape[1:], dtype=torch.uint8))
|
|
|
452
483
|
# Enjoy!
|
|
453
484
|
```
|
|
454
485
|
|
|
486
|
+
## Running inference on a remote GPU (client / server)
|
|
487
|
+
|
|
488
|
+
If the machine running your GUI does not have a powerful GPU, you can run the
|
|
489
|
+
model on a remote box and drive it over HTTP with
|
|
490
|
+
**`nnInteractiveRemoteInferenceSession`** — a drop-in replacement with the same
|
|
491
|
+
public API as the local session. The server loads the model once at startup and
|
|
492
|
+
hosts multiple concurrent client sessions; each client keeps its own image,
|
|
493
|
+
target buffer, and interaction state.
|
|
494
|
+
|
|
495
|
+
Start the server on the GPU box:
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
nninteractive-server \
|
|
499
|
+
--model-dir /path/to/checkpoint_folder --fold all \
|
|
500
|
+
--host 0.0.0.0 --port 1527 \
|
|
501
|
+
--api-key "$(openssl rand -hex 32)"
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
And in the client code, swap the local session for the remote one:
|
|
505
|
+
|
|
506
|
+
```python
|
|
507
|
+
from nnInteractive.inference.remote import nnInteractiveRemoteInferenceSession
|
|
508
|
+
|
|
509
|
+
session = nnInteractiveRemoteInferenceSession(
|
|
510
|
+
server_url="http://gpu-box.lab:1527",
|
|
511
|
+
api_key="…",
|
|
512
|
+
)
|
|
513
|
+
# From here on, the API is identical to nnInteractiveInferenceSession.
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
For full details — installation, authentication, single-user SSH-tunnel setup,
|
|
517
|
+
multi-user deployment behind a reverse proxy, concurrency/session model, idle
|
|
518
|
+
expiry and heartbeats, GUI integration notes, and troubleshooting — see
|
|
519
|
+
[`SERVER_CLIENT.md`](SERVER_CLIENT.md).
|
|
520
|
+
|
|
455
521
|
## nnInteractive SuperVoxels
|
|
456
522
|
|
|
457
523
|
As part of the `nnInteractive` framework, we provide a dedicated module for **supervoxel generation** based on [SAM](https://github.com/facebookresearch/segment-anything) and [SAM2](https://github.com/facebookresearch/sam2). This replaces traditional superpixel methods (e.g., SLIC) with **foundation model–powered 3D pseudo-labels**.
|
|
@@ -83,6 +83,10 @@ class nnInteractiveInferenceSession:
|
|
|
83
83
|
self.preprocessed_image: torch.Tensor = None
|
|
84
84
|
self.preprocessed_props = None
|
|
85
85
|
self.target_buffer: Union[np.ndarray, torch.Tensor] = None
|
|
86
|
+
# Bbox (in original-image coordinates) of the most recent target_buffer write.
|
|
87
|
+
# Captured inside _paste_prediction_to_target_buffer so remote callers can
|
|
88
|
+
# fetch just the touched region without diffing.
|
|
89
|
+
self._last_paste_bbox: Optional[List[List[int]]] = None
|
|
86
90
|
|
|
87
91
|
# this will be set when loading the model (initialize_from_trained_model_folder)
|
|
88
92
|
self.pad_mode_data = self.preferred_scribble_thickness = self.point_interaction = None
|
|
@@ -287,6 +291,7 @@ class nnInteractiveInferenceSession:
|
|
|
287
291
|
else:
|
|
288
292
|
pred_for_target = prediction.to("cpu")
|
|
289
293
|
paste_tensor(self.target_buffer, pred_for_target, target_bbox)
|
|
294
|
+
self._last_paste_bbox = target_bbox
|
|
290
295
|
|
|
291
296
|
def _estimate_refinement_cache_nbytes(self, cache_bbox: List[List[int]]) -> int:
|
|
292
297
|
cache_voxels = int(np.prod(self._bbox_size(cache_bbox), dtype=np.int64))
|
|
@@ -517,6 +522,7 @@ class nnInteractiveInferenceSession:
|
|
|
517
522
|
self.current_interaction_intensity = 1.0
|
|
518
523
|
empty_cache(self.device)
|
|
519
524
|
self.original_image_shape = None
|
|
525
|
+
self._last_paste_bbox = None
|
|
520
526
|
|
|
521
527
|
def _initialize_interactions(self, image_torch: torch.Tensor):
|
|
522
528
|
shape = (self.num_interaction_channels, *image_torch.shape[1:])
|
|
@@ -606,6 +612,7 @@ class nnInteractiveInferenceSession:
|
|
|
606
612
|
self.target_buffer.fill(0)
|
|
607
613
|
elif isinstance(self.target_buffer, torch.Tensor):
|
|
608
614
|
self.target_buffer.zero_()
|
|
615
|
+
self._last_paste_bbox = None
|
|
609
616
|
empty_cache(self.device)
|
|
610
617
|
|
|
611
618
|
def add_bbox_interaction(
|
|
@@ -1287,6 +1294,29 @@ class nnInteractiveInferenceSession:
|
|
|
1287
1294
|
"""
|
|
1288
1295
|
This is used when making predictions with a trained model
|
|
1289
1296
|
"""
|
|
1297
|
+
artifacts = self._load_model_artifacts_from_disk(model_training_output_dir, use_fold, checkpoint_name)
|
|
1298
|
+
self.initialize_from_loaded_artifacts(artifacts)
|
|
1299
|
+
|
|
1300
|
+
def _load_model_artifacts_from_disk(
|
|
1301
|
+
self,
|
|
1302
|
+
model_training_output_dir: str,
|
|
1303
|
+
use_fold: Union[int, str] = None,
|
|
1304
|
+
checkpoint_name: str = "checkpoint_final.pth",
|
|
1305
|
+
) -> dict:
|
|
1306
|
+
"""Read all model artifacts from disk and build the network on ``self.device``.
|
|
1307
|
+
|
|
1308
|
+
Returns an artifact dict that can be applied to this or any other freshly
|
|
1309
|
+
constructed session via :meth:`initialize_from_loaded_artifacts`. The
|
|
1310
|
+
returned references (network, plans_manager, configuration_manager, ...)
|
|
1311
|
+
are safe to share by reference across sessions — they are treated as
|
|
1312
|
+
read-only after construction.
|
|
1313
|
+
|
|
1314
|
+
Note: this also mutates ``self`` (applies capability, sets pad/decay/
|
|
1315
|
+
thickness) because ``num_interaction_channels`` is required to build the
|
|
1316
|
+
network. The caller should follow up with
|
|
1317
|
+
:meth:`initialize_from_loaded_artifacts` (this is what
|
|
1318
|
+
:meth:`initialize_from_trained_model_folder` does).
|
|
1319
|
+
"""
|
|
1290
1320
|
point_interaction_use_etd = True
|
|
1291
1321
|
(
|
|
1292
1322
|
capability_content,
|
|
@@ -1353,12 +1383,38 @@ class nnInteractiveInferenceSession:
|
|
|
1353
1383
|
).to(self.device)
|
|
1354
1384
|
network.load_state_dict(parameters)
|
|
1355
1385
|
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1386
|
+
return {
|
|
1387
|
+
"capability_content": capability_content,
|
|
1388
|
+
"point_interaction": self.point_interaction,
|
|
1389
|
+
"preferred_scribble_thickness": self.preferred_scribble_thickness,
|
|
1390
|
+
"interaction_decay": self.interaction_decay,
|
|
1391
|
+
"pad_mode_data": self.pad_mode_data,
|
|
1392
|
+
"network": network,
|
|
1393
|
+
"plans_manager": plans_manager,
|
|
1394
|
+
"configuration_manager": configuration_manager,
|
|
1395
|
+
"dataset_json": dataset_json,
|
|
1396
|
+
"trainer_name": trainer_name,
|
|
1397
|
+
"label_manager": plans_manager.get_label_manager(dataset_json),
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
def initialize_from_loaded_artifacts(self, artifacts: dict):
|
|
1401
|
+
"""Apply pre-loaded artifacts to this session instance.
|
|
1402
|
+
|
|
1403
|
+
``artifacts`` is the dict returned by :meth:`_load_model_artifacts_from_disk`.
|
|
1404
|
+
Useful for spawning multiple sessions that share one loaded model (e.g.
|
|
1405
|
+
the multi-session inference server).
|
|
1406
|
+
"""
|
|
1407
|
+
self.preferred_scribble_thickness = artifacts["preferred_scribble_thickness"]
|
|
1408
|
+
self.interaction_decay = artifacts["interaction_decay"]
|
|
1409
|
+
self.pad_mode_data = artifacts["pad_mode_data"]
|
|
1410
|
+
self.point_interaction = artifacts["point_interaction"]
|
|
1411
|
+
self._apply_capability(artifacts["capability_content"])
|
|
1412
|
+
self.plans_manager = artifacts["plans_manager"]
|
|
1413
|
+
self.configuration_manager = artifacts["configuration_manager"]
|
|
1414
|
+
self.network = artifacts["network"]
|
|
1415
|
+
self.dataset_json = artifacts["dataset_json"]
|
|
1416
|
+
self.trainer_name = artifacts["trainer_name"]
|
|
1417
|
+
self.label_manager = artifacts["label_manager"]
|
|
1362
1418
|
if self.use_torch_compile and not isinstance(self.network, OptimizedModule):
|
|
1363
1419
|
print("Using torch.compile")
|
|
1364
1420
|
self.network = torch.compile(self.network)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from nnInteractive.inference.remote.remote_session import (
|
|
2
|
+
ServerAtCapacityError,
|
|
3
|
+
SessionExpiredError,
|
|
4
|
+
nnInteractiveRemoteInferenceSession,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"nnInteractiveRemoteInferenceSession",
|
|
9
|
+
"SessionExpiredError",
|
|
10
|
+
"ServerAtCapacityError",
|
|
11
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Shared constants for the nnInteractive client/server HTTP protocol."""
|
|
2
|
+
|
|
3
|
+
# HTTP header used to carry JSON-encoded metadata alongside a binary array body.
|
|
4
|
+
META_HEADER = "X-Meta"
|
|
5
|
+
# HTTP header used to carry a per-client lease token identifying which session
|
|
6
|
+
# on the (multi-session) server the request applies to.
|
|
7
|
+
LEASE_HEADER = "X-Lease-Token"
|
|
8
|
+
|
|
9
|
+
# Endpoint paths.
|
|
10
|
+
PATH_HEALTHZ = "/healthz"
|
|
11
|
+
PATH_CAPABILITIES = "/capabilities"
|
|
12
|
+
PATH_CLAIM = "/claim"
|
|
13
|
+
PATH_RELEASE = "/release"
|
|
14
|
+
PATH_HEARTBEAT = "/heartbeat"
|
|
15
|
+
PATH_LEASE_STATUS = "/lease_status"
|
|
16
|
+
PATH_SET_IMAGE = "/set_image"
|
|
17
|
+
PATH_SET_TARGET_BUFFER = "/set_target_buffer"
|
|
18
|
+
PATH_RESET_INTERACTIONS = "/reset_interactions"
|
|
19
|
+
PATH_SET_DO_AUTOZOOM = "/set_do_autozoom"
|
|
20
|
+
PATH_ADD_BBOX = "/add_bbox_interaction"
|
|
21
|
+
PATH_ADD_POINT = "/add_point_interaction"
|
|
22
|
+
PATH_ADD_SCRIBBLE = "/add_scribble_interaction"
|
|
23
|
+
PATH_ADD_LASSO = "/add_lasso_interaction"
|
|
24
|
+
PATH_ADD_INITIAL_SEG = "/add_initial_seg_interaction"
|
|
25
|
+
|
|
26
|
+
# Body content type for endpoints that ship a packed numpy array.
|
|
27
|
+
CONTENT_TYPE_OCTET_STREAM = "application/octet-stream"
|