Problem description
RuntimeError: Error(s) in loading state_dict for FasterRCNN:Missing key(s) in state_dict: “backbone.body.conv1.weight”, “backbone.body.bn1.weight”, …
Solution:
# model.load_state_dict(torch.load("./model.pth"))
model.load_state_dict(torch.load("./model.pth"), False)
Source code analysis
load_state_dict(state_dict, strict=True)[SOURCE]
Copies parameters and buffers from state_dict into this module and its descendants. If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.
Parameters
state_dict (dict) – a dict containing parameters and persistent buffers.
strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True
Returns
missing_keys is a list of str containing the missing keys
unexpected_keys is a list of str containing the unexpected keys
Return type
NamedTuple with missing_keys and unexpected_keys fields
Read More:
- [Solved] RuntimeError: Error(s) in loading state_dict for Model: 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
- K8S error validating data: ValidationError(Deployment.spec): missing required field selector
- [Solved] bin/hive Startup Error: Operation category READ is not supported in state standby
- [Solved] RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of s
- [Solved] Websocket Error: WebSocket is already in CLOSING or CLOSED state
- K8s cluster initialization error: Port 6443 is in use [Solved]
- [Solved] Schema initialization FAILED Metastore state would be inconsistent
- Debug Error: Failed to fetch current robot state [How to Solve]
- [Solved] react Error: Can‘t perform a React state update on an unmounted component
- [Solved] Hive 2.3.9 Error: Error: Unrecognized column type: UNIONTYPE (state=,code=0)
- [Solved] RuntimeError: each element in list of batch should be of equal size
- [Solved] Gitee generates public key error: Enter file in which to save the key…
- Yolox_s.pth Convert to tensorRT Error: AttributeError: ‘tensorrt.tensorrt.Builder‘ object has no attribute ‘max_workspace_size‘
- Scanf_S always reports errors [How to Solve]
- k8s kubernetes ingress error: endpoints “default-http-backend“ not found
- [Solved] go cobra Error: required flag(s) “pkg-name” not set
- [Solved] k8s error retrieving resource lock default/fuseim.pri-ifs: Unauthorized
- [Solved] k8s kubeadmin init Error: http://localhost:10248/healthz‘ failed