def draw_ann(ann, *, keypoint_painter, filename=None, margin=0.5, aspect=None, **kwargs): from openpifpaf import show # pylint: disable=import-outside-toplevel bbox = ann.bbox() xlim = bbox[0] - margin, bbox[0] + bbox[2] + margin ylim = bbox[1] - margin, bbox[1] + bbox[3] + margin if aspect == 'equal': fig_w = 5.0 else: fig_w = 5.0 / (ylim[1] - ylim[0]) * (xlim[1] - xlim[0]) with show.canvas(filename, figsize=(fig_w, 5), nomargin=True, **kwargs) as ax: ax.set_axis_off() ax.set_xlim(*xlim) ax.set_ylim(*ylim) if aspect is not None: ax.set_aspect(aspect) keypoint_painter.annotation(ax, ann)
def pif(self, image, target, stride, keypoint_sets, *, keypoints, skeleton): resized_image = image[::stride, ::stride] bce_targets = target[0] bce_masks = (bce_targets[:-1] + bce_targets[-1:]) > 0.5 for f in self.pif_indices: LOG.debug('intensity field %s', keypoints[f]) with show.canvas() as ax: ax.imshow(resized_image) ax.imshow(target[0][f] + 0.5 * bce_masks[f], alpha=0.9, vmin=0.0, vmax=1.0) with show.canvas() as ax: ax.imshow(image) show.white_screen(ax, alpha=0.5) self.keypoint_painter.keypoints(ax, keypoint_sets, skeleton=skeleton) show.quiver(ax, target[1][f, :2], xy_scale=stride) if self.show_margin: show.margins(ax, target[1][f, :6], xy_scale=stride)
def view_keypoints(image_cpu, annotations, gt): highlight = [5, 7, 9, 11, 13, 15] keypoint_painter = show.KeypointPainter(highlight=highlight) skeleton_painter = show.KeypointPainter(show_box=False, color_connections=True, markersize=1, linewidth=6) with show.canvas() as ax: ax.imshow((np.moveaxis(image_cpu.numpy(), 0, -1) + 2.0) / 4.0) keypoint_painter.annotations( ax, [ann for ann in annotations if ann.score() > 0.01]) with show.canvas() as ax: ax.set_axis_off() ax.imshow((np.moveaxis(image_cpu.numpy(), 0, -1) + 2.0) / 4.0) skeleton_painter.annotations( ax, [ann for ann in annotations if ann.score() > 0.01]) instances_gt = None if gt: instances_gt = np.stack([a['keypoints'] for a in gt]) # for test: overwrite prediction with true values # instances = instances_gt.copy()[:1] with show.canvas() as ax: ax.imshow((np.moveaxis(image_cpu.numpy(), 0, -1) + 2.0) / 4.0) keypoint_painter.keypoints(ax, instances_gt, skeleton=COCO_PERSON_SKELETON) with show.canvas() as ax: ax.imshow((np.moveaxis(image_cpu.numpy(), 0, -1) + 2.0) / 4.0) show.white_screen(ax) keypoint_painter.keypoints(ax, instances_gt, color='lightgrey', skeleton=COCO_PERSON_SKELETON) keypoint_painter.annotations( ax, [ann for ann in annotations if ann.score() > 0.01])
def single(self, image, targets): keypoint_sets = None if 'skeleton' in self.head_names: i = self.head_names.index('skeleton') keypoint_sets = targets[i][0] with show.canvas() as ax: ax.imshow(image) for target, headname, stride in zip(targets, self.head_names, self.strides): LOG.debug('%s with %d components', headname, len(target)) if headname in ('paf', 'paf19', 'pafs', 'wpaf'): self.paf(image, target, stride, keypoint_sets, keypoints=COCO_KEYPOINTS, skeleton=COCO_PERSON_SKELETON) elif headname in ('pif', 'pif17', 'pifs'): self.pif(image, target, stride, keypoint_sets, keypoints=COCO_KEYPOINTS, skeleton=COCO_PERSON_SKELETON) elif headname in ('paf25',): self.paf(image, target, stride, keypoint_sets, keypoints=COCO_KEYPOINTS, skeleton=DENSER_COCO_PERSON_CONNECTIONS) else: LOG.warning('unknown head: %s', headname)