|
|
@ -213,16 +213,18 @@ class Results(SimpleClass):
|
|
|
|
assert type(line_width) == int, '`line_width` should be of int type, i.e, line_width=3'
|
|
|
|
assert type(line_width) == int, '`line_width` should be of int type, i.e, line_width=3'
|
|
|
|
|
|
|
|
|
|
|
|
names = self.names
|
|
|
|
names = self.names
|
|
|
|
annotator = Annotator(deepcopy(self.orig_img if img is None else img),
|
|
|
|
pred_boxes, show_boxes = self.boxes, boxes
|
|
|
|
|
|
|
|
pred_masks, show_masks = self.masks, masks
|
|
|
|
|
|
|
|
pred_probs, show_probs = self.probs, probs
|
|
|
|
|
|
|
|
annotator = Annotator(
|
|
|
|
|
|
|
|
deepcopy(self.orig_img if img is None else img),
|
|
|
|
line_width,
|
|
|
|
line_width,
|
|
|
|
font_size,
|
|
|
|
font_size,
|
|
|
|
font,
|
|
|
|
font,
|
|
|
|
pil,
|
|
|
|
pil or (pred_probs is not None and show_probs), # Classify tasks default to pil=True
|
|
|
|
example=names)
|
|
|
|
example=names)
|
|
|
|
pred_boxes, show_boxes = self.boxes, boxes
|
|
|
|
|
|
|
|
pred_masks, show_masks = self.masks, masks
|
|
|
|
# Plot Segment results
|
|
|
|
pred_probs, show_probs = self.probs, probs
|
|
|
|
|
|
|
|
keypoints = self.keypoints
|
|
|
|
|
|
|
|
if pred_masks and show_masks:
|
|
|
|
if pred_masks and show_masks:
|
|
|
|
if img_gpu is None:
|
|
|
|
if img_gpu is None:
|
|
|
|
img = LetterBox(pred_masks.shape[1:])(image=annotator.result())
|
|
|
|
img = LetterBox(pred_masks.shape[1:])(image=annotator.result())
|
|
|
@ -231,6 +233,7 @@ class Results(SimpleClass):
|
|
|
|
idx = pred_boxes.cls if pred_boxes else range(len(pred_masks))
|
|
|
|
idx = pred_boxes.cls if pred_boxes else range(len(pred_masks))
|
|
|
|
annotator.masks(pred_masks.data, colors=[colors(x, True) for x in idx], im_gpu=img_gpu)
|
|
|
|
annotator.masks(pred_masks.data, colors=[colors(x, True) for x in idx], im_gpu=img_gpu)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Plot Detect results
|
|
|
|
if pred_boxes and show_boxes:
|
|
|
|
if pred_boxes and show_boxes:
|
|
|
|
for d in reversed(pred_boxes):
|
|
|
|
for d in reversed(pred_boxes):
|
|
|
|
c, conf, id = int(d.cls), float(d.conf) if conf else None, None if d.id is None else int(d.id.item())
|
|
|
|
c, conf, id = int(d.cls), float(d.conf) if conf else None, None if d.id is None else int(d.id.item())
|
|
|
@ -238,12 +241,15 @@ class Results(SimpleClass):
|
|
|
|
label = (f'{name} {conf:.2f}' if conf else name) if labels else None
|
|
|
|
label = (f'{name} {conf:.2f}' if conf else name) if labels else None
|
|
|
|
annotator.box_label(d.xyxy.squeeze(), label, color=colors(c, True))
|
|
|
|
annotator.box_label(d.xyxy.squeeze(), label, color=colors(c, True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Plot Classify results
|
|
|
|
if pred_probs is not None and show_probs:
|
|
|
|
if pred_probs is not None and show_probs:
|
|
|
|
text = f"{', '.join(f'{names[j] if names else j} {pred_probs.data[j]:.2f}' for j in pred_probs.top5)}, "
|
|
|
|
text = ',\n'.join(f'{names[j] if names else j} {pred_probs.data[j]:.2f}' for j in pred_probs.top5)
|
|
|
|
annotator.text((32, 32), text, txt_color=(255, 255, 255)) # TODO: allow setting colors
|
|
|
|
x = round(self.orig_shape[0] * 0.03)
|
|
|
|
|
|
|
|
annotator.text([x, x], text, txt_color=(255, 255, 255)) # TODO: allow setting colors
|
|
|
|
|
|
|
|
|
|
|
|
if keypoints is not None:
|
|
|
|
# Plot Pose results
|
|
|
|
for k in reversed(keypoints.data):
|
|
|
|
if self.keypoints is not None:
|
|
|
|
|
|
|
|
for k in reversed(self.keypoints.data):
|
|
|
|
annotator.kpts(k, self.orig_shape, kpt_line=kpt_line)
|
|
|
|
annotator.kpts(k, self.orig_shape, kpt_line=kpt_line)
|
|
|
|
|
|
|
|
|
|
|
|
return annotator.result()
|
|
|
|
return annotator.result()
|
|
|
|