BayraktarLab / cell2location

Comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model)
https://cell2location.readthedocs.io/en/latest/
Apache License 2.0
324 stars 58 forks source link

Error in mod.train #284

Open scauzhaos opened 1 year ago

scauzhaos commented 1 year ago

Hi, when I ran mod.train, I encountered this problem, as follows: ValueError: Expected parameter rate (Tensor of shape (1, 1)) of distribution Gamma(concentration: tensor([[10.]]), rate: tensor([[nan]])) to satisfy the constraint GreaterThan(lower_bound=0.0), but found invalid values: tensor([[nan]])

My code: mod.train(max_epochs=30000,

train using full data (batch_size=None)

      batch_size=None,
      # use all data points in training because
      # we need to estimate cell abundance at all locations
      use_gpu=False,
     )

Please help me to fix this issue. Thanks!

vitkl commented 1 year ago

This indicates numerical instability. When does this problem occur? If during later epochs (20k+) you can consider stopping earlier before this problem occurs. If in the middle of training (not the first few epochs) you can try more stringent gene filtering. If this happens during the first epoch - something is wrong with the data - possibly with reference cell type signatures.