-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdetector.py
33 lines (25 loc) · 1009 Bytes
/
detector.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
import os
import torch
from torch.autograd import Variable
from models import Darknet
from utils import utils
import utils.config as cnf
def setup_detector(opt):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
weights_path = os.path.join(opt.weights_path, "weights_RADAR.pth" if opt.radar else "weights_LIDAR.pth")
# Set up model
model = Darknet(opt.model_def, img_size=cnf.BEV_WIDTH).to(device)
# Load checkpoint weights
model.load_state_dict(torch.load(weights_path, map_location = device))
# Eval mode
model.eval()
return model
def detector(model, bev_maps, opt):
Tensor = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor
# Configure bev image
input_imgs = Variable(bev_maps.type(Tensor))
# Get detections
with torch.no_grad():
detections = model(input_imgs)
detections = utils.non_max_suppression_rotated_bbox(detections, opt.conf_thres, opt.nms_thres)
return detections