-
Notifications
You must be signed in to change notification settings - Fork 136
/
convert.py
44 lines (34 loc) · 1.48 KB
/
convert.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
40
41
42
43
44
# Author:LiPu
import argparse
from sys import platform
from models import *
from utils.datasets import *
from utils.utils import *
def convert():
img_size = opt.img_size # (320, 192) or (416, 256) or (608, 352) for (height, width)
weights = opt.weights
# Initialize
device = torch_utils.select_device(opt.device)
# Initialize model
model = Darknet(opt.cfg, img_size, is_gray_scale=opt.gray_scale)
# Load weights
attempt_download(weights)
if weights.endswith('.pt'): # pytorch format
model.load_state_dict(torch.load(weights, map_location=device)['model'])
else: # darknet format
_ = load_darknet_weights(model, weights)
# Eval mode
model.to(device).eval()
save_weights(model, path='weights/best.weights')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--cfg', type=str, default='cfg/yolov3.cfg', help='cfg file path')
parser.add_argument('--weights', type=str, default='weights/yolov3.weights', help='path to weights file')
parser.add_argument('--output', type=str, default='output', help='output folder') # output folder
parser.add_argument('--img_size', type=int, default=416, help='inference size (pixels)')
parser.add_argument('--device', default='', help='device id (i.e. 0 or 0,1) or cpu')
parser.add_argument('--gray-scale', action='store_true', help='gray scale trainning')
opt = parser.parse_args()
print(opt)
with torch.no_grad():
convert()