Error message:
Using the network weights trained by FCN, UNET and deeplab, an error is reported when loading the model:
RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict....
Training environment:
CPU:Intel E5
GPU: 3090*2
Pytorch1. ten
Solution:
Solve the mismatch problem
method 1 (invalid): the dictionary cannot match strictly. When the model is loaded, use the following code to add false to solve the mismatch problem
net.load_state_dict(t.load(ckpt_path),False)
Note: this method unlocks the strict matching and can ignore the error report. However, the model loaded by this method has problems in the actual segmentation effect due to the mismatch of parameters. Use it with caution!
Method 2: the network is the same, the only difference is that NN is used in the training process The dataparallel() method calls two graphics cards for training, so before loading the model weight, the model is also suitable for dataparallel packaging, which can solve the above error reporting problem.
net = nn.DataParallel(net)
net = net.to(device)
Read More:
- [Solved] RuntimeError: Error(s) in loading state_dict for FasterRCNN: Missing key(s) in state_dict:……
- [Solved] pytorch Load Error: “RuntimeError: Error(s) in loading state_dict for Sequential:”
- [Solved] Error: The slice reducer for key “auth“ returned undefined during initialization. If the state pas
- [Solved] Websocket Error: WebSocket is already in CLOSING or CLOSED state
- [Solved] bin/hive Startup Error: Operation category READ is not supported in state standby
- K8S error validating data: ValidationError(Deployment.spec): missing required field selector
- [Solved] RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of s
- [Solved] Pytorch loading model specified GPU card number error or failed to specify
- K8s cluster initialization error: Port 6443 is in use [Solved]
- [Solved] Schema initialization FAILED Metastore state would be inconsistent
- [Solved] react Error: Can‘t perform a React state update on an unmounted component
- Debug Error: Failed to fetch current robot state [How to Solve]
- How to Solve kubelet starts error (k8s Cluster Restarted)
- Maskrcnn-benchmark Error: KeyError “Non-existent config key: MODEL.BACKBONE.OUT_CHANNELS“
- [Solved] Hive 2.3.9 Error: Error: Unrecognized column type: UNIONTYPE (state=,code=0)
- [Solved] Gitee generates public key error: Enter file in which to save the key…
- Error:scalac: missing or invalid dependency detected while loading class file ***
- [Solved] k8s kubeadmin init Error: http://localhost:10248/healthz‘ failed
- Scanf_S always reports errors [How to Solve]
- Flask Startup Error: s.bind(server_address)PermissionError: [Errno 13] Permission denied