nyukat / breast_cancer_classifier

Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening
https://ieeexplore.ieee.org/document/8861376
GNU Affero General Public License v3.0
840 stars 269 forks source link

RuntimeError: Error(s) in loading state_dict for SplitBreastModel: #22

Closed sanjaykhobragade closed 4 years ago

sanjaykhobragade commented 4 years ago

With Device_type = 'cpu', I am getting below error during running 'Stage 4a: Run Classifier (Image)' stage.

Traceback (most recent call last): File "src/modeling/run_model.py", line 238, in main() File "src/modeling/run_model.py", line 233, in main parameters=parameters, File "src/modeling/run_model.py", line 188, in load_run_save model, device = load_model(parameters) File "src/modeling/run_model.py", line 51, in load_model model.load_state_dict(torch.load(parameters["model_path"])["model"]) File "/usr/local/envs/py3env/lib/python3.5/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 SplitBreastModel: Missing key(s) in state_dict: "fc1_cc.weight", "fc1_cc.bias", "fc1_mlo.weight", "fc1_mlo.bias", "output_layer_cc.fc_layer.weight", "output_layer_cc.fc_layer.bias", "output_layer_mlo.fc_layer.weight", "output_layer_mlo.fc_layer.bias". Unexpected key(s) in state_dict: "fc1_lcc.weight", "fc1_lcc.bias", "fc1_rcc.weight", "fc1_rcc.bias", "fc1_lmlo.weight", "fc1_lmlo.bias", "fc1_rmlo.weight", "fc1_rmlo.bias", "output_layer_lcc.fc_layer.weight", "output_layer_lcc.fc_layer.bias", "output_layer_rcc.fc_layer.weight", "output_layer_rcc.fc_layer.bias", "output_layer_lmlo.fc_layer.weight", "output_layer_lmlo.fc_layer.bias", "output_layer_rmlo.fc_layer.weight", "output_layer_rmlo.fc_layer.bias".

zphang commented 4 years ago

It looks like you may be using the single-image model weights with the exam-level model script. Your model_path should look like models/sample_image_model.p rather than models/ImageOnly__ModeImage_weights.p. Can you verify this?

sanjaykhobragade commented 4 years ago

Thx for response, @zphang Yes, I had IMAGE_MODEL_PATH='models/ImageOnly__ModeImage_weights.p'. So, instead I should change it to 'models/sample_image_model.p' ?

And IMAGEHEATMAPS_MODEL_PATH is defined as 'models/ImageHeatmaps__ModeImage_weights.p'. Should this be 'sample_imageheatmaps_model.p' instead?

zphang commented 4 years ago

There are two separate scripts: run.sh and run_single.sh. It looks like you're getting the configurations mixed between them. Both scripts should have the correct image model paths at the top of the script.

sanjaykhobragade commented 4 years ago

Yes, that indeed was the case. Thank you! This issue can be closed.