예제 #1
0
	def visualize_results(self, batch, out):

		background_image = batch["scene_img"][0]["scaled_image"].copy()

		inp = batch["in_xy"]
		gt = batch["gt_xy"]
		pred = out["out_xy"]
		pred = pred.view(pred.size(0), self.hparams.best_k_val, -1, pred.size(-1))

		y = out["y_map"]
		y_softmax = out["y_softmax"]



		image = visualize_traj_probabilities(
			input_trajectory=inp.cpu()[:, 0],
			gt_trajectory=None,
			prediction_trajectories=pred.cpu()[:,:, 0],
			background_image=background_image,
			img_scaling=self.val_dset.img_scaling,
			scaling_global=self.val_dset.scaling_global,
			grid_size=20,
			y_softmax=y_softmax,
			y=y,
			global_patch=re_im(batch["global_patch"][0]).cpu().numpy(),
			probability_mask=batch["prob_mask"][0][0].cpu().numpy(),
			grid_size_in_global=self.val_dset.grid_size_in_global

			)



		self.logger.experiment.add_image(f'Trajectories', image, self.current_epoch)
예제 #2
0
    def visualize_results(self, batch, out):

        y = out["y_map"]
        y_softmax = out["y_softmax"]

        image = visualize_probabilities(
            y_softmax=y_softmax,
            y=y,
            global_patch=re_im(batch["global_patch"][0]).cpu().numpy(),
            probability_mask=batch["prob_mask"][0][0].cpu().numpy(),
            grid_size_in_global=self.val_dset.grid_size_in_global)
        self.logger.experiment.add_image(f'Map', image, self.current_epoch)
예제 #3
0
    def plot(self,
             index,
             modes=["in", "gt"],
             image_type="scaled",
             final_mask=False):

        out = self.get_scene(index)

        if "seq_start_end" in out:
            (index, end) = out["seq_start_end"]

        image = out["scene_img"][0]

        if image_type == "orig":
            img_label = "img"
            img = image[img_label]
            scale = 1
        elif image_type == "scaled":
            img_label = "scaled_image"
            img = image[img_label]
            if self.format == "meter":
                scale = 1. / self.img_scaling
            else:
                scale = 1
        elif image_type == "global":
            img_label = "global_image"
            img = image[img_label]
            scale = 1. / self.scaling_global

        elif image_type == "local":
            img_label = "local_image"
            img = image[img_label]
            scale = 1. / self.scaling_local
        elif image_type == "patch":
            img = re_im(out["global_patch"][0, :3].permute(1, 2, 0))
            scale = 1. / self.scaling_global

        else:
            assert False, "'{}' not valid <image_type>".format(image_type)

        center = out["in_xy"][-1, 0] * scale

        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.imshow(img)

        if final_mask:

            rel_scaling = (2 * self.grid_size_in_global +
                           1) / (2 * self.grid_size_out_global + 1)

            mask = out["prob_mask"][0, 0]

            final_pos_out = torch.cat(torch.where(mask == 1)).float()

            final_pos = torch.zeros_like(final_pos_out)
            final_pos[0] = final_pos_out[1]
            final_pos[1] = final_pos_out[0]
            center_pixel_global = out["in_xy"][-1, 0] * scale
            if not image_type == "patch":

                final_pos_pixel_centered = (
                    final_pos - self.grid_size_out_global
                ) * self.scaling_global * scale * rel_scaling

                final_pos_pixel = final_pos_pixel_centered + center_pixel_global

            elif image_type == "patch":
                final_pos_pixel = final_pos * rel_scaling
                mask = mask.numpy()
                mask = (mask * 255).astype(np.uint8)

                mask = Image.fromarray(mask, mode="L")
                mask = mask.resize((int(2 * self.grid_size_in_global + 1),
                                    int(2 * self.grid_size_in_global + 1)))
                ax.imshow(mask, alpha=0.5)

            plt.plot(final_pos_pixel[0], final_pos_pixel[1], "x")
            error = abs(final_pos_pixel / scale - out["gt_xy"][-1])
            error_bound = rel_scaling * self.scaling_global
            print("Error real and approximation: {} Threshold: {} ".format(
                error, error_bound))
            # assert (error < error_bound).all(), "Error above error bound"

        for m in modes:
            if m == "gt":
                marker = '-'
            else:
                marker = '-'

            traj = out["{}_xy".format(m)][:, 0] * scale
            traj = traj.cpu().numpy()

            if image_type == "patch":
                traj = traj + (self.grid_size_in_global) - center.cpu().numpy()

            ax.plot((traj[:, 0]).astype(int), (traj[:, 1]).astype(int),
                    linestyle=marker,
                    linewidth=int(3))

        plt.show()

        def trim_axs(axs, N):
            """little helper to massage the axs list to have correct length..."""
            axs = axs.flat
            for ax in axs[N:]:
                ax.remove()
            return axs[:N]