File ~/anaconda3/envs/TOSICA/lib/python3.8/site-packages/torch/nn/modules/module.py:1051, in Module.load_state_dict(self, state_dict, strict)
1046 error_msgs.insert(
1047 0, 'Missing key(s) in state_dict: {}. '.format(
1048 ', '.join('"{}"'.format(k) for k in missing_keys)))
1050 if len(error_msgs) > 0:
-> 1051 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
1052 self.class.name, "\n\t".join(error_msgs)))
1053 return _IncompatibleKeys(missing_keys, unexpected_keys)
RuntimeError: Error(s) in loading state_dict for Transformer:
Missing key(s) in state_dict: "blocks.1.norm1.weight", "blocks.1.norm1.bias", "blocks.1.attn.qkv.weight", "blocks.1.attn.qkv.bias", "blocks.1.attn.proj.weight", "blocks.1.attn.proj.bias", "blocks.1.norm2.weight", "blocks.1.norm2.bias", "blocks.1.mlp.fc1.weight", "blocks.1.mlp.fc1.bias", "blocks.1.mlp.fc2.weight", "blocks.1.mlp.fc2.bias".
#############################################################
I have changed the code for cuda device in all .py to suit for my conputer. such like:
############
model.load_state_dict(torch.load(model_weight_path, map_location=device), strict=False)
############
I have changed this line... seems it can run and get results, is that issue cuase by gmt file?
hello, I just used TOSICA for cell type annotation,got some issue in Model pre.
RuntimeError Traceback (most recent call last) Cell In[65], line 2 1 model_weight_path = './tosicago/model-0.pth' ----> 2 new_adata = TOSICA.pre(query_data, model_weight_path = model_weight_path,project='tosicago')
File ~/anaconda3/envs/TOSICA/lib/python3.8/site-packages/TOSICA/init.py:117, in pre(adata, model_weight_path, project, laten, save_att, save_lantent, n_step, cutoff, n_unannotated, batch_size, embed_dim, depth, num_heads) 74 r""" 75 Prediect query data with the model and pre-trained weights. 76 Parameters (...) 114 adata.var['pathway_index'] : Gene set of each colume 115 """ 116 mask_path = os.getcwd()+'/%s'%project+'/mask.npy' --> 117 adata = prediect(adata,model_weight_path,project=project,mask_path = mask_path,laten=laten, 118 save_att = save_att, save_lantent = save_lantent,n_step=n_step,cutoff=cutoff,n_unannotated = n_unannotated,batch_size=batch_size,embed_dim=embed_dim,depth=depth,num_heads=num_heads) 119 return(adata)
File ~/anaconda3/envs/TOSICA/lib/python3.8/site-packages/TOSICA/pre.py:61, in prediect(adata, model_weight_path, project, mask_path, laten, save_att, save_lantent, n_step, cutoff, n_unannotated, batch_size, embed_dim, depth, num_heads) 59 model = create_model(num_classes=n_c, num_genes=num_genes,mask = mask, has_logits=False,depth=depth,num_heads=num_heads).to(device) 60 # load model weights ---> 61 model.load_state_dict(torch.load(model_weight_path, map_location=device)) 62 model.eval() 63 parm={}
File ~/anaconda3/envs/TOSICA/lib/python3.8/site-packages/torch/nn/modules/module.py:1051, in Module.load_state_dict(self, state_dict, strict) 1046 error_msgs.insert( 1047 0, 'Missing key(s) in state_dict: {}. '.format( 1048 ', '.join('"{}"'.format(k) for k in missing_keys))) 1050 if len(error_msgs) > 0: -> 1051 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( 1052 self.class.name, "\n\t".join(error_msgs))) 1053 return _IncompatibleKeys(missing_keys, unexpected_keys)
RuntimeError: Error(s) in loading state_dict for Transformer: Missing key(s) in state_dict: "blocks.1.norm1.weight", "blocks.1.norm1.bias", "blocks.1.attn.qkv.weight", "blocks.1.attn.qkv.bias", "blocks.1.attn.proj.weight", "blocks.1.attn.proj.bias", "blocks.1.norm2.weight", "blocks.1.norm2.bias", "blocks.1.mlp.fc1.weight", "blocks.1.mlp.fc1.bias", "blocks.1.mlp.fc2.weight", "blocks.1.mlp.fc2.bias". #############################################################
I have changed the code for cuda device in all .py to suit for my conputer. such like:
device = 'cuda:1' #change 0 to1 device = torch.device(device if torch.cuda.is_available() else "cpu")
It is result this preoblem?