Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions yolov6/core/inferer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def infer(self, conf_thres, iou_thres, classes, agnostic_nms, max_det, save_dir,
''' Model Inference and results visualization '''
vid_path, vid_writer, windows = None, None, []
fps_calculator = CalcFPS()
for img_src, img_path, vid_cap in tqdm(self.files):
frame_num = 0
for img_src, img_path, vid_cap in tqdm(self.files):
img, img_src = self.precess_image(img_src, self.img_size, self.stride, self.half)
img = img.to(self.device)
if len(img.shape) == 3:
Expand Down Expand Up @@ -97,7 +98,7 @@ def infer(self, conf_thres, iou_thres, classes, agnostic_nms, max_det, save_dir,
for *xyxy, conf, cls in reversed(det):
if save_txt: # Write to file
xywh = (self.box_convert(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
line = (cls, *xywh, conf)
line = (cls, *xywh, conf, frame_num)
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * len(line)).rstrip() % line + '\n')

Expand All @@ -107,7 +108,7 @@ def infer(self, conf_thres, iou_thres, classes, agnostic_nms, max_det, save_dir,

self.plot_box_and_label(img_ori, max(round(sum(img_ori.shape) / 2 * 0.003), 2), xyxy, label, color=self.generate_colors(class_num, True))

img_src = np.asarray(img_ori)
img_src = np.asarray(img_ori)

# FPS counter
fps_calculator.update(1.0 / (t2 - t1))
Expand Down Expand Up @@ -150,6 +151,10 @@ def infer(self, conf_thres, iou_thres, classes, agnostic_nms, max_det, save_dir,
save_path = str(Path(save_path).with_suffix('.mp4')) # force *.mp4 suffix on results videos
vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
vid_writer.write(img_src)

# increment frame number
frame_num += 1


@staticmethod
def precess_image(img_src, img_size, stride, half):
Expand Down