Closed wangzhangfei-hkd closed 4 years ago
This problem has been solved. First, you need to train yourself, and then test it.
i have meet the same problem and i do not understand what you mean. why should i need to train it again and than test it.
i have meet the same problem and i do not understand what you mean. why should i need to train it again and than test it.
Hi, After testing, directly using the weight file given by the author will report an error. You can get the weight file after training yourself, and then you can test it without error. Because I didn’t look at the code carefully, I still don’t know the difference between the two.
It seems that they have changed names of some weights in newer versions, so to load provided pretrained model I had to change loading code a bit:
def load_params_from_file(model, filename, to_cpu=False):
if not os.path.isfile(filename):
raise FileNotFoundError
print('==> Loading parameters from checkpoint %s to %s' % (filename, 'CPU' if to_cpu else 'GPU'))
loc_type = torch.device('cpu') if to_cpu else None
checkpoint = torch.load(filename, map_location=loc_type)
model_state_disk = checkpoint['state_dict'] # LINE CHANGED
if 'version' in checkpoint:
print('==> Checkpoint trained from version: %s' % checkpoint['version'])
update_model_state = {}
for key, val in model_state_disk.items():
new_key = "module." + key # NEW LINE
if new_key in model.state_dict() and model.state_dict()[new_key].shape == model_state_disk[key].shape: # LINE CHANGED
update_model_state[new_key] = val # LINE CHANGED
# logger.info('Update weight %s: %s' % (key, str(val.shape)))
update_model_state['module.neck.point_fc.weight'] = model_state_disk['neck.backbone.point_fc.weight'] # NEW LINE
update_model_state['module.neck.point_cls.weight'] = model_state_disk['neck.backbone.point_cls.weight'] # NEW LINE
update_model_state['module.neck.point_reg.weight'] = model_state_disk['neck.backbone.point_reg.weight'] # NEW LINE
state_dict = model.state_dict()
state_dict.update(update_model_state)
model.load_state_dict(state_dict)
for key in state_dict:
if key not in update_model_state:
print('Not updated weight %s: %s' % (key, str(state_dict[key].shape)))
print('==> Done (loaded %d/%d)' % (len(update_model_state), len(model.state_dict())))
With that code I am able to load a model and achieve accuracy metrics provided at main page (without any retraining).
I tried to use the original function block and the updated function, the results are all 0. I guess I need to re-train the model by myself. But when I run the train.py, there are errors. This model really cost me a lot of time to debug.
您的邮件我已经收到了 我会及时的阅读 谢谢
Dear author, when I run the program, I have the following problems:
i changed it to
model_state_disk = checkpoint['state_dict']
But the accuracy of the final detection results is very low, the results are as followsHow can I modify it to achieve the results of your paper. We look forward to your reply.