이미지 인식 -pytorch-RuntimeError: Error(s) in loading state_dict for DataParallel:

1434 단어 이미지 인식
RuntimeError                              Traceback (most recent call last)
~\ColorRectalCancerClassification_FlyAI - usenet\main.py in 
    144 
    145 print('===============================================================')
--> 146 labels = model.predict_all(x_test)
    147 print(labels)
    148 #f=open("loss.txt",'w')

~\ColorRectalCancerClassification_FlyAI - usenet\model.py in predict_all(self, datas)
     46         # cnn.cuda()
     47         cnn = nn.DataParallel(cnn)
---> 48         cnn.load_state_dict(torch.load(os.path.join(MODEL_PATH, Torch_MODEL_NAME)))
     49         cnn.to(device)
     50         cnn.eval()


RuntimeError: Error(s) in loading state_dict for DataParallel

솔루션: 링크 설명 추가
model.load_state_dict(state_dict, strict=True)

Copies parameters and buffers from :attr:state_dict into this module and its descendants. If :attr:strict is True, then the keys of :attr:state_dict must exactly match the keys returned by this module’s :meth:~torch.nn.Module.state_dict function
 state_dict 。 strict True, state_dict keys keys 。 False, 。

Arguments:
state_dict (dict): a dict containing parameters and persistent buffers.
strict (bool, optional): whether to strictly enforce that the keys in :attr:state_dict match the keys returned by this module’s:meth:~torch.nn.Module.state_dict function. Default: True

좋은 웹페이지 즐겨찾기