SUN-1024 / DA-TransUnet

DA-TransUNet: Combining Dual Attention of Position and Channel with Transformer U-net for Medical Image Segmentation
GNU General Public License v3.0
120 stars 10 forks source link

在运行test.py 时,snapshot 取值epoch_149.pth,但是epoch_149.pth的key出现错误,这种情况如何解决,或者需要跑完train.py得到模型参数吗? #3

Open kebai633932 opened 10 months ago

kebai633932 commented 10 months ago

代码 snapshot = os.path.join(snapshot_path, 'best_model.pth') if not os.path.exists(snapshot): snapshot = snapshot.replace('bestmodel', 'epoch'+str(args.max_epochs-1)) 报错:C:\ProgramData\anaconda3\python.exe C:\Users\86133\Desktop\project_TransUNet\TransUNet\test.py ../model/TU_Synapse224/TU_pretrain_R50-ViT-B_16_skip3_epo150_bs24_224\epoch_149.pth Traceback (most recent call last): File "C:\Users\86133\Desktop\project_TransUNet\TransUNet\test.py", line 139, in net.load_state_dict(torch.load(snapshot)) File "C:\Users\86133\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 2041, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for VisionTransformer: Missing key(s) in state_dict: "transformer.embeddings.hybrid_model.body.block1/.unit1/.gn1.weight", " Unexpected key(s) in state_dict: "transformer.embeddings.DAblock1.conv5a.0.weight",

进程已结束,退出代码为 1 epoch149

yizhipan commented 9 months ago

https://blog.csdn.net/m0_69607904/article/details/135243311?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22135243311%22%2C%22source%22%3A%22m0_69607904%22%7D

变更代码会导致 我给的.pth文件错误,你重新自己跑试试看