def _log_visuals(birdview, loss, waypoints, _waypoints):
    images = list()

    for i in range(birdview.shape[0]):
        canvas = np.uint8(
            birdview[i].detach().cpu().numpy().transpose(1, 2, 0) *
            255).copy()
        canvas = visualize_birdview(canvas)
        canvas = Image.fromarray(canvas)
        draw = ImageDraw.Draw(canvas)

        def _dot(i, j, color):
            x = int(192 - (i + 1) / 2 * canvas.width)
            y = int((j + 1) / 2 * canvas.height)

            draw.ellipse((x - 2, y - 2, x + 2, y + 2), fill=color)

        for x, y in waypoints[i]:
            _dot(x, y, (0, 0, 255))
        for x, y in _waypoints[i]:
            _dot(x, y, (255, 0, 0))

        loss_i = loss[i].sum()

        draw.text((5, 10), 'Loss: %.2f' % loss_i)

        images.append(
            (loss_i, torch.ByteTensor(np.uint8(canvas).transpose(2, 0, 1))))

    images.sort(key=lambda x: x[0], reverse=True)

    result = torchvision.utils.make_grid([x[1] for x in images[:32]], nrow=4)
    result = [wandb.Image(result.numpy().transpose(1, 2, 0))]

    return result
Ejemplo n.º 2
0
    def __init__(self, rgb, birdview):
        self.canvas = Image.fromarray(rgb)
        self.draw = ImageDraw.Draw(self.canvas)

        self.canvas_birdview = Image.fromarray(
            crop_birdview(visualize_birdview(birdview)))
        self.draw_birdview = ImageDraw.Draw(self.canvas_birdview)

        self.step = 0
Ejemplo n.º 3
0
def _log_visuals(rgb, birdview, loss, waypoints_map, waypoints, _waypoints):
    images = list()

    for i in range(birdview.shape[0]):
        canvas_rgb = np.uint8(
            rgb[i].detach().cpu().numpy().transpose(1, 2, 0) * 255).copy()
        canvas_rgb = Image.fromarray(canvas_rgb)
        draw_rgb = ImageDraw.Draw(canvas_rgb)

        canvas_map = np.uint8(
            birdview[i].detach().cpu().numpy().transpose(1, 2, 0) *
            255).copy()
        canvas_map = visualize_birdview(canvas_map)
        canvas_map = Image.fromarray(canvas_map)
        draw_map = ImageDraw.Draw(canvas_map)

        def _dot(canvas, draw, i, j, color, rescale):
            if rescale:
                x = int((i + 1) / 2 * canvas.width)
                y = int((j + 1) / 2 * canvas.height)
            else:
                x = int(i)
                y = int(j)

            draw.ellipse((x - 2, y - 2, x + 2, y + 2), fill=color)

        for x, y in waypoints_map[i]:
            _dot(canvas_map, draw_map, x, y, (0, 0, 255), False)

        for x, y in waypoints[i]:
            _dot(canvas_rgb, draw_rgb, x, y, (0, 0, 255), True)

        for x, y in _waypoints[i]:
            _dot(canvas_rgb, draw_rgb, x, y, (255, 0, 0), True)

        loss_i = loss[i].sum()

        draw_rgb.text((5, 10), 'Loss: %.2f' % loss_i)

        k = min(canvas_rgb.size)
        canvas_map.thumbnail((k, k))
        canvas = np.hstack([np.array(x) for x in [canvas_rgb, canvas_map]])

        images.append(
            (loss_i, torch.ByteTensor(np.uint8(canvas).transpose(2, 0, 1))))

    images.sort(key=lambda x: x[0], reverse=True)

    result = torchvision.utils.make_grid([x[1] for x in images[:32]], nrow=4)
    result = [wandb.Image(result.numpy().transpose(1, 2, 0))]

    return result
Ejemplo n.º 4
0
def save(save_dir, observations, step, debug):
    rgb = observations['rgb']
    birdview = observations['birdview']
    segmentation = observations['segmentation']

    pos = observations['position']
    ori = observations['orientation']
    measurements = np.float32([pos[0], pos[1], pos[2], np.arctan2(ori[1], ori[0])])
    # print(math.degrees(np.arctan2(ori[1], ori[0])))

    if debug:
        cv2.imshow('rgb', cv2.cvtColor(rgb[:, :, :3], cv2.COLOR_BGR2RGB))
        cv2.imshow('birdview', cv2.cvtColor(visualize_birdview(birdview), cv2.COLOR_BGR2RGB))
        cv2.imshow('segmentation', cv2.cvtColor(colorize_segmentation(segmentation), cv2.COLOR_BGR2RGB))
        cv2.waitKey(1)
    else:
        np.save(save_dir / ('measurements_%04d' % step), measurements)
        np.save(save_dir / ('birdview_%04d' % step), birdview)

        Image.fromarray(rgb).save(save_dir / ('image_%04d.png' % step))
        Image.fromarray(segmentation).save(save_dir / ('segmentation_%04d.png' % step))
Ejemplo n.º 5
0
    import sys
    import cv2
    from PIL import ImageDraw
    # from ..utils import visualize_birdview
    # from ..converter import ConverterTorch
    from utils.common import visualize_birdview
    from utils.converter import ConverterTorch

    print(sys.argv[1])
    data = CarlaDataset(sys.argv[1])
    convert = ConverterTorch()

    for i in range(len(data)):
        rgb, birdview, meta = data[i]
        canvas = np.uint8(birdview.detach().cpu().numpy().transpose(1, 2, 0) * 255).copy()
        canvas = visualize_birdview(canvas)
        canvas = Image.fromarray(canvas)
        draw = ImageDraw.Draw(canvas)

        origin = np.array([birdview.shape[-1] // 2, birdview.shape[-1] - 5])
        offsets = np.array([[0, 0], [0, -10], [-5, -20]])
        points = origin + offsets
        points_cam = convert(torch.FloatTensor(points))
        points_reproject = convert.cam_to_map(points_cam)

        for x, y in points:
            draw.ellipse((x - 2, y - 2, x + 2, y + 2), fill=(0, 0, 255))

        for x, y in points_reproject:
            draw.ellipse((x - 2, y - 2, x + 2, y + 2), fill=(255, 0, 0))