state_dict for {}:\n\t{}‘.format( RuntimeError: Error(s) in loading state_dict for Mnist_CN

created at 06-26-2022 views: 20

Problem

Error when loading model parameters:

raise RuntimeError(‘Error(s) in loading state_dict for {}:\n\t{}’.format(
RuntimeError: Error(s) in loading state_dict for Mnist_CNN:
Missing key(s) in state_dict: “input0_shape”, “output_shape”, “conv1.input0_shape”, “conv1.output_shape”, “pool1.input0_shape”, “pool1.output_shape”, “conv2.input0_shape”, “conv2.output_shape”, “pool2.input0_shape”, “pool2.output_shape”, “fc1.input0_shape”, “fc1.output_shape”, “fc2.input0_shape”, “fc2.output_shape”.

Error code line:

# Load the latest global parameters in the current communication
# Pass in the network model and load the global_parameters parameter
net.load_state_dict(global_parameters, strict=True)

solution

Change net.load_state_dict(global_parameters, strict=True) to net.load_state_dict(global_parameters, strict=False)

cause analysis

The environment when loading and using the model is inconsistent with the environment when training the model. This model is trained with GPU, and I was using CPU, so there will be some problems.

created at:06-26-2022
edited at: 06-26-2022: