X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=maze.py;h=8ac9fcef0495fbefc6c11f1652367fb44d916f40;hb=6045e9a7dd61f0dab60bd1c6ff71f6bd5c32778b;hp=f6a852e37241f176a65a7cd69c6c8cb934a3a1fc;hpb=f23843d33a4fa5a38f5034deab8f473793732ee3;p=picoclvr.git diff --git a/maze.py b/maze.py index f6a852e..8ac9fce 100755 --- a/maze.py +++ b/maze.py @@ -13,6 +13,8 @@ v_empty, v_wall, v_start, v_goal, v_path = 0, 1, 2, 3, 4 def create_maze(h=11, w=17, nb_walls=8): + assert h % 2 == 1 and w % 2 == 1 + a, k = 0, 0 while k < nb_walls: @@ -219,8 +221,6 @@ def save_image( mazes, target_paths=None, predicted_paths=None, - score_paths=None, - score_truth=None, path_correct=None, path_optimal=None, ): @@ -240,17 +240,6 @@ def save_image( colors[mazes.reshape(-1)].reshape(mazes.size() + (-1,)).permute(0, 3, 1, 2) ) - if score_truth is not None: - score_truth = score_truth.cpu() - c_score_truth = score_truth.unsqueeze(1).expand(-1, 3, -1, -1) - c_score_truth = ( - c_score_truth * colors[4].reshape(1, 3, 1, 1) - + (1 - c_score_truth) * colors[0].reshape(1, 3, 1, 1) - ).long() - c_mazes = (mazes.unsqueeze(1) != v_empty) * c_mazes + ( - mazes.unsqueeze(1) == v_empty - ) * c_score_truth - imgs = c_mazes.unsqueeze(1) if target_paths is not None: @@ -273,18 +262,6 @@ def save_image( ) imgs = torch.cat((imgs, c_predicted_paths.unsqueeze(1)), 1) - if score_paths is not None: - score_paths = score_paths.cpu() - c_score_paths = score_paths.unsqueeze(1).expand(-1, 3, -1, -1) - c_score_paths = ( - c_score_paths * colors[4].reshape(1, 3, 1, 1) - + (1 - c_score_paths) * colors[0].reshape(1, 3, 1, 1) - ).long() - c_score_paths = c_score_paths * (mazes.unsqueeze(1) == v_empty) + c_mazes * ( - mazes.unsqueeze(1) != v_empty - ) - imgs = torch.cat((imgs, c_score_paths.unsqueeze(1)), 1) - img = torch.tensor([255, 255, 0]).view(1, -1, 1, 1) # NxKxCxHxW @@ -305,6 +282,8 @@ def save_image( -1, -1, imgs.size(3) + 2, 1 + imgs.size(1) * (1 + imgs.size(4)) ).clone() + print(f"{img.size()=} {imgs.size()=}") + for k in range(imgs.size(1)): img[ :, @@ -322,9 +301,9 @@ def save_image( if __name__ == "__main__": device = torch.device("cuda" if torch.cuda.is_available() else "cpu") - mazes, paths = create_maze_data(8) + mazes, paths, policies = create_maze_data(8) mazes, paths = mazes.to(device), paths.to(device) - save_image("test.png", mazes, paths, paths) + save_image("test.png", mazes=mazes, target_paths=paths, predicted_paths=paths) print(path_correctness(mazes, paths)) ######################################################################