Skip to content

How to save model to MODEL ZOO pkl format #4665

Answered by HaowenGuan
HaowenGuan asked this question in Q&A
Discussion options

You must be logged in to vote

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)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Lunatik00
Comment options

@ilya1234-ai
Comment options

Answer selected by HaowenGuan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants