forked from deeplearning-wisc/vos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_weight.py
39 lines (32 loc) · 910 Bytes
/
convert_weight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import torch
import argparse
from collections import OrderedDict
import torch
def get_parser():
parser = argparse.ArgumentParser(description="Detectron2 Model Converter")
parser.add_argument(
"--model",
required=True,
metavar="FILE",
help="path to model weights",
)
parser.add_argument(
"--output",
required=True,
metavar="FILE",
help="path to model weights",
)
return parser
def convert_weight():
args = get_parser().parse_args()
ckpt = torch.load(args.model, map_location="cpu")
if "model" in ckpt:
state_dict = ckpt["model"]
else:
state_dict = ckpt
# breakpoint()
state_dict = state_dict['model_state']
model = {"model": state_dict,"__author__": "custom", "matching_heuristics": True}
torch.save(model, args.output)
if __name__ == "__main__":
convert_weight()