X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=maze.py;h=6e8e179d8f4d70a60a27fb85bee3c2c1f8b2f711;hb=41c7509dc3d2153da79ed09ecf4a3b592503f15e;hp=6c3fe94fe189159a4a450fb90c33f02d73cb6e92;hpb=0e74c10ba17f2f969072f3989579c0d6f47f1cbb;p=beaver.git diff --git a/maze.py b/maze.py index 6c3fe94..6e8e179 100755 --- a/maze.py +++ b/maze.py @@ -187,9 +187,14 @@ def create_maze_data( ###################################################################### -def save_image(name, mazes, target_paths, predicted_paths=None, path_correct=None): - mazes, target_paths = mazes.cpu(), target_paths.cpu() - +def save_image( + name, + mazes, + target_paths=None, + predicted_paths=None, + score_paths=None, + path_correct=None, +): colors = torch.tensor( [ [255, 255, 255], # empty @@ -200,13 +205,22 @@ def save_image(name, mazes, target_paths, predicted_paths=None, path_correct=Non ] ) + mazes = mazes.cpu() + mazes = colors[mazes.reshape(-1)].reshape(mazes.size() + (-1,)).permute(0, 3, 1, 2) - target_paths = ( - colors[target_paths.reshape(-1)] - .reshape(target_paths.size() + (-1,)) - .permute(0, 3, 1, 2) - ) - imgs = torch.cat((mazes.unsqueeze(1), target_paths.unsqueeze(1)), 1) + + imgs = mazes.unsqueeze(1) + + if target_paths is not None: + target_paths = target_paths.cpu() + + target_paths = ( + colors[target_paths.reshape(-1)] + .reshape(target_paths.size() + (-1,)) + .permute(0, 3, 1, 2) + ) + + imgs = torch.cat((imgs, target_paths.unsqueeze(1)), 1) if predicted_paths is not None: predicted_paths = predicted_paths.cpu() @@ -217,6 +231,11 @@ def save_image(name, mazes, target_paths, predicted_paths=None, path_correct=Non ) imgs = torch.cat((imgs, predicted_paths.unsqueeze(1)), 1) + if score_paths is not None: + score_paths = (score_paths.cpu() * 255.0).long() + score_paths = score_paths.unsqueeze(1).expand(-1, 3, -1, -1) + imgs = torch.cat((imgs, score_paths.unsqueeze(1)), 1) + # NxKxCxHxW if path_correct is None: path_correct = torch.zeros(imgs.size(0)) <= 1