cwlkr / torchvahadane

Gpu accelerated vahadane stain normalization for Digital Pathology workflows.
MIT License
17 stars 3 forks source link

Potential nan in dictionary update steps caused by 0/0 #2

Closed CielAl closed 11 months ago

CielAl commented 1 year ago

Attempt fix in #1 In the update_dict method in https://github.com/cwlkr/torchvahadane/blob/main/torchvahadane/dict_learning.py#L100, when the atomic norm is too small, the corresponding atom is re-initialized with tensor.normal_. However, if all numbers drawn are negative, the following in-place clamp will yield a zero vector, and in the in-place normalization of dictionary[:, k] /= dictionary[:, k].norm() a nan vector will be generated and this will invalidate the whole computation procedure.