LiQian-XC / sctour

A deep learning architecture for robust inference and accurate prediction of cellular dynamics
https://sctour.readthedocs.io
MIT License
52 stars 4 forks source link

RuntimeError: mat1 and mat2 must have the same dtype, but got Double and Float #14

Closed yuzu1999 closed 2 weeks ago

yuzu1999 commented 2 weeks ago

When I run tnode.train(), an error message appears as follows: RuntimeError: mat1 and mat2 must have the same dtype, but got Double and Float

The following is the code before the error occurs:

import sctour as sct import omicverse as ov import numpy as np import scanpy as sc import anndata as ad import pandas as pd

sc.settings.set_figure_params(dpi=50, facecolor="white")

adata=sc.read_h5ad("07_Anno_filter.h5ad") adata

AnnData object with n_obs × n_vars = 7048 × 2000

adata_counts=adata.raw.to_adata().copy() adata_counts

AnnData object with n_obs × n_vars = 7048 × 21155

print(adata_counts.X)

ov.utils.retrieve_layers(adata_counts,layers='counts') adata_counts

AnnData object with n_obs × n_vars = 7048 × 21155

print(adata_counts.X)

adata=adata_counts

sc.pp.calculate_qc_metrics(adata, percent_top=None, log1p=False, inplace=True)

sc.pp.highly_variable_genes(adata, flavor='seurat_v3', n_top_genes=2000, subset=True)

np.where(~np.equal(np.mod(adata.X.toarray(), 1), 0))

(array([], dtype=int64), array([], dtype=int64))

Train the scTour model

tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5) tnode.train()

I don't know how to solve it, please help me! Thank you very much!

yuzu1999 commented 2 weeks ago

Thank you, I solved this problem after converting adata.X from float64 to float32.