DengPingFan / Inf-Net

Inf-Net: Automatic COVID-19 Lung Infection Segmentation from CT Images, IEEE TMI 2020.
http://dpfan.net/InfNet
MIT License
346 stars 97 forks source link

Error while executing MyTest_Lunginf.py #15

Closed titu1992 closed 4 years ago

titu1992 commented 4 years ago

Hi, Thank you for this helpful compilation. I am able to generate my weights after training MyTrain_LungInf.py with backbone = 'Res2Net50' However when I am trying to run the MyTest_LungInf.py I am facing the below issue although I have placed the pre-trained weights of 'Inf-Net_Pseduo' in the reuired path. Is it because of some mis-match between the trained 'Semi-Inf-Net-100.pth' and the pre-trained 'Inf-Net_Pseduo'? How could we fix this?

Traceback (most recent call last): File "MyTest_LungInf.py", line 65, in inference() File "MyTest_LungInf.py", line 39, in inference model.load_state_dict(torch.load(opt.pth_path)) File "/home/user/Virtualenv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 839, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for Inf_Net: Unexpected key(s) in state_dict: "total_ops", "total_params", "resnet.total_ops", "resnet.total_params", "resnet.conv1.total_ops", "resnet.conv1.total_params", "resnet.layer1.total_ops", "resnet.layer1.total_params", "resnet.layer1.0.total_ops", "resnet.layer1.0.total_params", "resnet.layer1.0.convs.total_ops", "resnet.layer1.0.convs.total_params", "resnet.layer1.0.bns.total_ops", "resnet.layer1.0.bns.total_params", "resnet.layer1.0.downsample.total_ops", "resnet.layer1.0.downsample.total_params", "resnet.layer1.1.total_ops", "resnet.layer1.1.total_params", "resnet.layer1.1.convs.total_ops", "resnet.layer1.1.convs.total_params", "resnet.layer1.1.bns.total_ops", "resnet.layer1.1.bns.total_params", "resnet.layer1.2.total_ops", "resnet.layer1.2.total_params", "resnet.layer1.2.convs.total_ops", "resnet.layer1.2.convs.total_params", "resnet.layer1.2.bns.total_ops", "resnet.layer1.2.bns.total_params", "resnet.layer2.total_ops", "resnet.layer2.total_params", "resnet.layer2.0.total_ops", "resnet.layer2.0.total_params", "resnet.layer2.0.convs.total_ops", "resnet.layer2.0.convs.total_params", "resnet.layer2.0.bns.total_ops", "resnet.layer2.0.bns.total_params", "resnet.layer2.0.downsample.total_ops", "resnet.layer2.0.downsample.total_params", "resnet.layer2.1.total_ops", "resnet.layer2.1.total_params", "resnet.layer2.1.convs.total_ops", "resnet.layer2.1.convs.total_params", "resnet.layer2.1.bns.total_ops", "resnet.layer2.1.bns.total_params", "resnet.layer2.2.total_ops", "resnet.layer2.2.total_params", "resnet.layer2.2.convs.total_ops", "resnet.layer2.2.convs.total_params", "resnet.layer2.2.bns.total_ops", "resnet.layer2.2.bns.total_params", "resnet.layer2.3.total_ops", "resnet.layer2.3.total_params", "resnet.layer2.3.convs.total_ops", "resnet.layer2.3.convs.total_params", "resnet.layer2.3.bns.total_ops", "resnet.layer2.3.bns.total_params", "resnet.layer3.total_ops", "resnet.layer3.total_params", "resnet.layer3.0.total_ops", "resnet.layer3.0.total_params", "resnet.layer3.0.convs.total_ops", "resnet.layer3.0.convs.total_params", "resnet.layer3.0.bns.total_ops", "resnet.layer3.0.bns.total_params", "resnet.layer3.0.downsample.total_ops", "resnet.layer3.0.downsample.total_params", "resnet.layer3.1.total_ops", "resnet.layer3.1.total_params", "resnet.layer3.1.convs.total_ops", "resnet.layer3.1.convs.total_params", "resnet.layer3.1.bns.total_ops", "resnet.layer3.1.bns.total_params", "resnet.layer3.2.total_ops", "resnet.layer3.2.total_params", "resnet.layer3.2.convs.total_ops", "resnet.layer3.2.convs.total_params", "resnet.layer3.2.bns.total_ops", "resnet.layer3.2.bns.total_params", "resnet.layer3.3.total_ops", "resnet.layer3.3.total_params", "resnet.layer3.3.convs.total_ops", "resnet.layer3.3.convs.total_params", "resnet.layer3.3.bns.total_ops", "resnet.layer3.3.bns.total_params", "resnet.layer3.4.total_ops", "resnet.layer3.4.total_params", "resnet.layer3.4.convs.total_ops", "resnet.layer3.4.convs.total_params", "resnet.layer3.4.bns.total_ops", "resnet.layer3.4.bns.total_params", "resnet.layer3.5.total_ops", "resnet.layer3.5.total_params", "resnet.layer3.5.convs.total_ops", "resnet.layer3.5.convs.total_params", "resnet.layer3.5.bns.total_ops", "resnet.layer3.5.bns.total_params", "resnet.layer4.total_ops", "resnet.layer4.total_params", "resnet.layer4.0.total_ops", "resnet.layer4.0.total_params", "resnet.layer4.0.convs.total_ops", "resnet.layer4.0.convs.total_params", "resnet.layer4.0.bns.total_ops", "resnet.layer4.0.bns.total_params", "resnet.layer4.0.downsample.total_ops", "resnet.layer4.0.downsample.total_params", "resnet.layer4.1.total_ops", "resnet.layer4.1.total_params"

GewelsJI commented 4 years ago

Nope, the trained 'Semi-Inf-Net-100.pth' and the pre-trained 'Inf-Net_Pseduo' totally matches. Besides, I have checked the each item in ''Semi-Inf-Net-100.pth" but fail to find the param_name that contains total_ops and total_params. May you provide training details and testing details?

aytek03 commented 4 years ago

Also I have the same issue too. I trained well (myTrain_lungInf.py) but when I tested (myTest_lungInf.py), mismatch occured.

size mismatch for resnet.layer4.2.conv3.weight: copying a param with shape torch.Size([2048, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([2048, 832, 1, 1]).

GewelsJI commented 4 years ago

I have replied to your e-mail, please check it. @aytek03

aytek03 commented 4 years ago

I run 100 epoch and I got Inf-Net-100.pth. Then I changed this code in Res2Net.py (in backbone)

def res2net50_v1b_26w_4s(pretrained=False, **kwargs):

model_lung_infection.load_state_dict(model_zoo.load_url(model_urls['res2net50_v1b_26w_4s']))

model.load_state_dict(model_zoo.load_url(model_urls['res2net50_v1b_26w_4s']))

because name 'model_lung_infection' is not defined in this code.

Then I changed ResNet50 to Res2Net50 but I have this error code in myTest_lungInf.py:

RuntimeError: Error(s) in loading state_dict for Inf_Net: Unexpected key(s) in state_dict: "total_ops", "total_params",..

we do not have total_ops and total_params.

Have do we solve sir?

aytek03 commented 4 years ago

I find the error in this line:

model.load_state_dict(torch.load('./Snapshots/save_weights/Inf-Net/Inf-Net-100.pth'))

When I directly download the pre-trained weights from your .pth, it works but when I use my trained .pth, I got an error.

Why? I changed to Res2net50 and trained but this system does not work.

GewelsJI commented 4 years ago

I think THOP may result in an error. You better close off it. If you solve this problem, please notify me.

aytek03 commented 4 years ago

Yes it works sir. When I close THOP settings in MyTrain_LungInf.py then I run MyTest_LungInf.py. Then I got the result images.

GewelsJI commented 4 years ago

Have a nice day! Thank you for your attention to our work.

zyrant commented 4 years ago

我也遇到了这个问题,我把计算参数的代码放到了train的后面,这样解决了这个问题并且还能计算参数

aytek03 commented 4 years ago

我也遇到了这个问题,我把计算参数的代码放到了train的后面,这样解决了这个问题并且还能计算参数

Can you share this code?

harveyyeung commented 4 years ago

我也遇到了这个问题,我把计算参数的代码放到了train的后面,这样解决了这个问题并且还能计算参数

请问能展示你的解决问题部分的代码吗?同样遇到这个问题,调整了几次都不成功。谢谢了

GewelsJI commented 4 years ago

我也遇到了这个问题,我把计算参数的代码放到了train的后面,这样解决了这个问题并且还能计算参数

请问能展示你的解决问题部分的代码吗?同样遇到这个问题,调整了几次都不成功。谢谢了

你可以把计算参数的这一段去掉试试

harveyyeung commented 4 years ago

我也遇到了这个问题,我把计算参数的代码放到了train的后面,这样解决了这个问题并且还能计算参数

请问能展示你的解决问题部分的代码吗?同样遇到这个问题,调整了几次都不成功。谢谢了

你可以把计算参数的这一段去掉试试

感谢作者,拉取新代码修改部分问题后,PseudoGenerator和test都跑通了,非常感谢!

GewelsJI commented 4 years ago

You are welcome!

harvey notifications@github.com 于2020年8月31日周一 下午11:12写道:

我也遇到了这个问题,我把计算参数的代码放到了train的后面,这样解决了这个问题并且还能计算参数

请问能展示你的解决问题部分的代码吗?同样遇到这个问题,调整了几次都不成功。谢谢了

你可以把计算参数的这一段去掉试试

感谢作者,拉取新代码修改部分问题后,PseudoGenerator和test都跑通了,非常感谢!

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/DengPingFan/Inf-Net/issues/15#issuecomment-683841554, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJEUADOUSJQQLSWJFQVUBA3SDO4XRANCNFSM4NXP7KAA .