1

I am using Chainer to train (fine-tune) a Resnet model and then use the checkpoint for evaluation. The checkpoint is a npz file with the following structure:

File list in npz checkpoint

When I am loading the model for evaluation with chainer.serializers.load_npz(args.load, model) (where model is the standard resnet) I get the following error: KeyError: 'rpn/loc/b is not a file in the archive'.

I think the problem is that the files in the model do not have the 'updater/optimizer/faster/extractor' prefix.

How can I change the name of the files in the resulting npz to remove the prefix or what else should I do to fix the problem?

Thank you!

Chandan
  • 571
  • 4
  • 21
user2277994
  • 77
  • 2
  • 12

1 Answers1

1

When you load a snapshot generated by the Snapshot Extension, you need to do it from the trainer.

chainer.serializers.load_npz(args.load, trainer) The trainer will automatically load the state of the updater, optimizer and the model.

You can also load only the model manually by accessing the corresponding field in the snapshot and passing it as an argument to the model.serialize function

npz_data = numpy.load(args.load)
snap = chainer.serializers.NpzDeserializer(npz_data)
model.serialize(snap['updater']['model:main'])

This should load only the weights of the model

emcastillo
  • 306
  • 1
  • 4
  • Thank you for your answer! I still can't make it work. I am trying to run the training and evaluation from this repo: https://github.com/naoto0804/cross-domain-detection. I tried the second approach with snap['updater']['model:main'], but the error persists. For the first method, I don't know exactly how to save the trainer object from the training file and read it in the evaluation. (train_model.py and eval_model.py) – user2277994 Mar 25 '20 at 15:51
  • For the first option just do `chainer.serializers.load_npz(args.load, trainer)` after creating the trainer object. This should load the state of everything, optimizer, trainer and updater. – emcastillo Mar 30 '20 at 09:59