def plot_results(self, results=None, classes=None, show_labels=True, gt_data=None, confidence_threshold=None): if results is None: results = self.results if confidence_threshold is not None: mask = results[:, 4] > confidence_threshold results = results[mask] if classes is not None: colors = plt.cm.hsv(np.linspace(0, 1, len(classes)+1)).tolist() ax = plt.gca() im = plt.gci() image_size = im.get_size() # draw ground truth if gt_data is not None: for box in gt_data: label = np.nonzero(box[4:])[0][0]+1 color = 'g' if classes == None else colors[label] xy_rec = to_rec(box[:4], image_size) ax.add_patch(plt.Polygon(xy_rec, fill=True, color=color, linewidth=1, alpha=0.3)) # draw prediction for r in results: label = int(r[5]) confidence = r[4] color = 'r' if classes == None else colors[label] xy_rec = to_rec(r[:4], image_size) ax.add_patch(plt.Polygon(xy_rec, fill=False, edgecolor=color, linewidth=2)) if show_labels: label_name = label if classes == None else classes[label] xmin, ymin = xy_rec[0] display_txt = '%0.2f, %s' % (confidence, label_name) ax.text(xmin, ymin, display_txt, bbox={'facecolor':color, 'alpha':0.5})
def plot_assignment(self, map_idx): ax = plt.gca() im = plt.gci() img_h, img_w = image_size = im.get_size() # ground truth boxes = self.gt_boxes boxes_x = (boxes[:, 0] + boxes[:, 2]) / 2. * img_h boxes_y = (boxes[:, 1] + boxes[:, 3]) / 2. * img_w for box in boxes: xy_rec = to_rec(box[:4], image_size) ax.add_patch( plt.Polygon(xy_rec, fill=False, edgecolor='b', linewidth=2)) plt.plot(boxes_x, boxes_y, 'bo', markersize=6) # prior boxes for idx, box_idx in self.match_indices.items(): if idx >= self.map_offsets[map_idx] and idx < self.map_offsets[ map_idx + 1]: x, y = self.priors_xy[idx] w, h = self.priors_wh[idx] plt.plot(x, y, 'ro', markersize=4) plt.plot([x, boxes_x[box_idx]], [y, boxes_y[box_idx]], '-r', linewidth=1) ax.add_patch( plt.Rectangle((x - w / 2, y - h / 2), w + 1, h + 1, fill=False, edgecolor='y', linewidth=2))