How to save model to MODEL ZOO pkl format #4665
-
I have trained a R50-FPN with customized dataset and I hope to save the model to I inspect the model zoo format, the model is in OrderedDict format, but checkpointer model is different, how can we do the convertion? What is the trick to save a model as pkl file just like MODEL_ZOO.md? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Well, I figured it out, and I am gonna answer myself. args = default_argument_parser().parse_args()
cfg = setup(args)
model = Trainer.build_model(cfg)
DetectionCheckpointer(model).resume_or_load(cfg.MODEL.WEIGHTS, resume=False)
checkpointer = DetectionCheckpointer(model, save_dir='output/supervised')
from collections import OrderedDict
weights = OrderedDict()
for p in checkpointer.model.state_dict():
weights[p] = checkpointer.model.state_dict()[p].numpy()
with open(os.path.join("output/model_supervised.pkl"), 'wb') as f:
myModel = {'model': weights, '__author__': "youself"}
pickle.dump(myModel, f) |
Beta Was this translation helpful? Give feedback.
Well, I figured it out, and I am gonna answer myself.