segresnet-mlx 0.2.1__py3-none-any.whl

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.

Potentially problematic release.


This version of segresnet-mlx might be problematic. Click here for more details.

@@ -0,0 +1,49 @@
1
+ """Frozen topology contract for the MONAI SegResNet MLX implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ from dataclasses import dataclass
7
+ from typing import Literal
8
+
9
+ # Accumulation scheme for convolution and GroupNorm; see the README for the three
10
+ # profiles. ``compensated-fp48`` additionally requires transpose-convolution upsampling.
11
+ type ArithmeticProfile = Literal["torch-order-fp32", "compensated-fp32", "compensated-fp48"]
12
+
13
+
14
+ @dataclass(frozen=True, slots=True)
15
+ class SegResNetSpec:
16
+ """The inference-relevant MONAI ``SegResNet`` constructor arguments.
17
+
18
+ ``blocks_down`` and ``blocks_up`` count residual blocks per encoder and decoder
19
+ stage (one more encoder stage than decoder stage). ``init_filters`` is the channel
20
+ count of the first stage and doubles at each deeper stage. ``upsample_mode`` is
21
+ ``"nontrainable"`` (1x1x1 convolution plus trilinear 2x interpolation) or
22
+ ``"deconv"`` (1x1x1 convolution plus 2x transposed convolution). Dropout is not
23
+ part of the spec because it is inactive at inference.
24
+ """
25
+
26
+ in_channels: int
27
+ out_channels: int
28
+ init_filters: int
29
+ blocks_down: tuple[int, ...] = (1, 2, 2, 4)
30
+ blocks_up: tuple[int, ...] = (1, 1, 1)
31
+ num_groups: int = 8
32
+ norm_eps: float = 1e-5
33
+ upsample_mode: str = "nontrainable"
34
+
35
+ def __post_init__(self) -> None:
36
+ if min(self.in_channels, self.out_channels, self.init_filters) < 1:
37
+ raise ValueError("SegResNet channel counts must be positive")
38
+ if len(self.blocks_down) != len(self.blocks_up) + 1:
39
+ raise ValueError("SegResNet needs one more down stage than up stage")
40
+ if not self.blocks_down or any(count < 1 for count in self.blocks_down):
41
+ raise ValueError("SegResNet down stages must contain residual blocks")
42
+ if any(count < 1 for count in self.blocks_up):
43
+ raise ValueError("SegResNet up stages must contain residual blocks")
44
+ if self.num_groups < 1 or not math.isfinite(self.norm_eps) or self.norm_eps <= 0:
45
+ raise ValueError("SegResNet normalization parameters must be positive")
46
+ if self.init_filters % self.num_groups != 0:
47
+ raise ValueError("SegResNet init_filters must be divisible by num_groups")
48
+ if self.upsample_mode not in {"nontrainable", "deconv"}:
49
+ raise ValueError("SegResNet MLX supports nontrainable or deconv upsampling")