torch_staintools.functional.concentration package
Submodules
torch_staintools.functional.concentration.implementation module
- class torch_staintools.functional.concentration.implementation.ConcentCfg(algorithm: Literal['ista', 'cd', 'fista', 'ls', 'pinv', 'qr'] = 'fista', regularizer: float = 0.01, rng: torch._C.Generator | None = None, maxiter: int = 50, lr: float | None = None, positive: bool = True, tol: float | None = None)
Bases:
object- algorithm: Literal['ista', 'cd', 'fista', 'ls', 'pinv', 'qr'] = 'fista'
- lr: float | None = None
- maxiter: int = 50
- positive: bool = True
- regularizer: float = 0.01
- rng: Generator | None = None
- tol: float | None = None
- class torch_staintools.functional.concentration.implementation.ConcentrationSolver(cfg: ConcentCfg)
Bases:
Callable- cfg: ConcentCfg
- torch_staintools.functional.concentration.implementation.get_concentration_batch(od_flatten: Tensor, stain_matrix: Tensor, regularizer: float, algorithm: Literal['ista', 'cd', 'fista', 'ls', 'pinv', 'qr'], lr: float | None, maxiter: int, rng: Generator | None, positive: bool)
- torch_staintools.functional.concentration.implementation.get_concentration_one_by_one(od_flatten: Tensor, stain_matrix: Tensor, regularizer: float, algorithm: Literal['ista', 'cd', 'fista', 'ls', 'pinv', 'qr'], lr: float | None, maxiter: int, rng: Generator | None, positive: bool)
- torch_staintools.functional.concentration.implementation.get_concentrations(od: Tensor, stain_matrix: Tensor, regularizer: float, algorithm: Literal['ista', 'cd', 'fista', 'ls', 'pinv', 'qr'], lr: float | None, maxiter: int, rng: Generator | None, positive: bool)
Estimate concentration matrix given an image and stain matrix.
Warning
for cusolver backend, algorithm = ‘ls’ May fail on GPU for individual large input (e.g., 1000 x 1000), regardless of batch size. To use ‘ls’ on large image, consider using magma backend:
`torch.backends.cuda.preferred_linalg_library('magma')`- Parameters:
od – batched optical density image(s) in shape of BxCxHxW
stain_matrix – B x num_stain x input channel
regularizer – regularization term if ISTA algorithm is used
algorithm – which method to compute the concentration: Solve min||HExC - OD||p support ‘ista’, ‘cd’, and ‘ls’. ‘ls’ simply solves the least square problem for factorization of min||HExC - OD||F (Frobenius norm) but is faster. ‘ista’/cd enforce the sparse penalty (L1 norm) but slower.
lr – learning rate for FISTA and ISTA. If None then computed from 1 / Lipschitz constant.
maxiter – max iteration for sparse code optimization.
rng – torch.Generator for random initializations
positive – whether to enforce positive concentration. Default: True
- Returns:
B x num_pixel x num_stains
- Return type:
concentration matrix