The modified code available here: https://github.com/BIGBALLON/CIFAR-ZOO/blob/master/eval.py
1. Is the model imported successfully?
1.1 problem
Missing key(s) in state_dict: "features.0.weight"
Unexpected key(s) in state_dict: "module.features.0.weight"
For example, if the following command is used at this time to import the model:
net.load_state_dict(checkpoint["state_dict"], strict=False)
Here the strict parameter is set to False (unmatched network layer parameters will be ignored). How to use the multi-GPU parallel training model name when training, there will be more "module.", the model may not be imported successfully.
reference:
https://blog.csdn.net/shiwanghualuo/article/details/101756876
https://blog.csdn.net/qq_32998593/article/details/89343507
1.2 Solve
net.load_state_dict({k.replace('module.',''):v for k,v in checkpoint["state_dict"].items()}, strict=True)
2. Input image preprocessing
Torch often uses PIL to read pictures, some preprocessing in transforms (resize, ToTensor, etc.). It has been verified before that PIL and opencv only need to be converted to the same color space, and it is basically no problem.