How to load Chainer training checkpoint from npz?

432 Views Asked by At

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!

1

There are 1 best solutions below

2
emcastillo On

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