theislab / scarches

Reference mapping for single-cell genomics
https://docs.scarches.org/en/latest/
BSD 3-Clause "New" or "Revised" License
323 stars 50 forks source link

Runtime error using scPoli - Tensors must have same number of dimensions: got 1 and 2 #227

Closed lsw0825 closed 4 months ago

lsw0825 commented 5 months ago

Hi, I am trying to follow this tutorial: https://github.com/theislab/scarches/blob/master/notebooks/scpoli_surgery_pipeline.ipynb.

matplotlib==3.8.2 numpy==1.24.4 pandas==1.5.3 scArches==0.5.10 scanpy==1.9.6 scikit-learn==1.3.2 seaborn==0.13.1 torch==2.1.2

When I try to train the model I run into this error: Traceback (most recent call last): File "/home/lifesci/data/scPoli_test.py", line 103, in scpoli_query.train( File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/models/scpoli/scpoli_model.py", line 307, in train self.trainer.train(n_epochs, lr, eps) File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 298, in train self.on_epoch_begin(lr, eps) File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 515, in on_epoch_begin self.initialize_prototypes() File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 395, in initialize_prototypes latent = self.get_latent_train() File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 382, in get_latent_train latent = self.model.get_latent( File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/models/scpoli/scpoli.py", line 354, in get_latent z_mean, z_logvar = self.encoder(x, embed_c) File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(args, **kwargs) File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/models/scpoli/scpoli.py", line 459, in forward x = torch.cat((x, batch), dim=-1) RuntimeError: Tensors must have same number of dimensions: got 1 and 2

Has anyone run into this error and been able to fix it?

Koncopd commented 4 months ago

Hm, can't reproduce this. Do you just run the tutorial with the same data etc? Could you try with the latest version of scarches?

lsw0825 commented 4 months ago

Thanks, When I try with the latest version of scarches, the problem can be solved.