From 898656145b3ca21dbfc3cfa9a2cdc6a4f1c66464 Mon Sep 17 00:00:00 2001 From: Christy-Marchese Date: Tue, 17 Aug 2021 16:09:00 -0700 Subject: [PATCH 1/5] Stacked and Panel Training scripts --- Experiments/RunTrainBasicClassification.py | 4 +- Experiments/RunTrainPaneledClassification.py | 34 +++ Experiments/RunTrainStackedClassification.py | 34 +++ Experiments/TrainBasicClassification.py | 7 +- Experiments/TrainCmdClassification.py | 2 +- Experiments/TrainPaneledClassification.py | 212 +++++++++++++++++++ Experiments/TrainRNNClassification.py | 6 +- Experiments/TrainStackedClassification.py | 208 ++++++++++++++++++ 8 files changed, 498 insertions(+), 9 deletions(-) create mode 100644 Experiments/RunTrainPaneledClassification.py create mode 100644 Experiments/RunTrainStackedClassification.py create mode 100644 Experiments/TrainPaneledClassification.py create mode 100644 Experiments/TrainStackedClassification.py diff --git a/Experiments/RunTrainBasicClassification.py b/Experiments/RunTrainBasicClassification.py index 0e221d0..4fd0f44 100644 --- a/Experiments/RunTrainBasicClassification.py +++ b/Experiments/RunTrainBasicClassification.py @@ -27,7 +27,7 @@ "alexnet", ] -for dataset in ["uniform-full", "corrected-wander-full"]: +for dataset in ["corrected-wander-full"]: for model in compared_models: @@ -37,6 +37,6 @@ "TrainBasicClassification.py", model, dataset, - #"--pretrained", + "--pretrained", ] ) diff --git a/Experiments/RunTrainPaneledClassification.py b/Experiments/RunTrainPaneledClassification.py new file mode 100644 index 0000000..da78a07 --- /dev/null +++ b/Experiments/RunTrainPaneledClassification.py @@ -0,0 +1,34 @@ +# --- +# jupyter: +# jupytext: +# formats: py:light +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.11.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +from subprocess import run + +compared_models = [ + "resnet18", +] + +for dataset in ["handmade-full", "corrected-wander-full"]: + + for model in compared_models: + + run( + [ + "python", + "TrainPaneledClassification.py", + model, + dataset, + "--pretrained", + ] + ) diff --git a/Experiments/RunTrainStackedClassification.py b/Experiments/RunTrainStackedClassification.py new file mode 100644 index 0000000..0dc6928 --- /dev/null +++ b/Experiments/RunTrainStackedClassification.py @@ -0,0 +1,34 @@ +# --- +# jupyter: +# jupytext: +# formats: py:light +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.11.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +from subprocess import run + +compared_models = [ + "resnet18", +] + +for dataset in ["handmade-full", "corrected-wander-full"]: + + for model in compared_models: + + run( + [ + "python", + "TrainStackedClassification.py", + model, + dataset, + "--pretrained", + ] + ) diff --git a/Experiments/TrainBasicClassification.py b/Experiments/TrainBasicClassification.py index 91477b7..5c7f9ca 100644 --- a/Experiments/TrainBasicClassification.py +++ b/Experiments/TrainBasicClassification.py @@ -14,9 +14,12 @@ from fastai.callback.progress import CSVLogger +# + # Assign GPU -torch.cuda.set_device(1) +torch.cuda.set_device(2) + print("Running on GPU: " + str(torch.cuda.current_device())) +# - # Constants (same for all trials) VALID_PCT = 0.05 @@ -162,7 +165,7 @@ def main(): print("Model relative filename :", model_filename) # Checks if model exists and skip if it does (helps if this crashes) - if path.exists(model_filename): + if path.exists(DATASET_DIR / args.dataset_name / model_filename): continue log_filename = DATA_PATH_REL_TO_DATASET / f"{file_prefix}-trainlog-{rep}.csv" diff --git a/Experiments/TrainCmdClassification.py b/Experiments/TrainCmdClassification.py index 70a0a7c..c4bff7f 100644 --- a/Experiments/TrainCmdClassification.py +++ b/Experiments/TrainCmdClassification.py @@ -209,7 +209,7 @@ def main(): "model_arch", help="Model architecture (see code for options)" ) arg_parser.add_argument( - "dataset_name", help="Name of dataset to use (corrected-wander-full)" + "dataset_name", help="Name of dataset to use (handmade-full | corrected-wander-full)" ) arg_parser.add_argument( "--pretrained", action="store_true", help="Use pretrained model" diff --git a/Experiments/TrainPaneledClassification.py b/Experiments/TrainPaneledClassification.py new file mode 100644 index 0000000..9a2326b --- /dev/null +++ b/Experiments/TrainPaneledClassification.py @@ -0,0 +1,212 @@ +# --- +# jupyter: +# jupytext: +# formats: py:light +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.11.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +from argparse import ArgumentParser + +import matplotlib.pyplot as plt +import os.path +from os import path + +from fastai.vision.all import * +from fastai.callback.progress import CSVLogger +from torchvision import transforms + +# Assign GPU +torch.cuda.set_device(0) +print("Running on GPU: " + str(torch.cuda.current_device())) + +# Constants (same for all trials) +VALID_PCT = 0.05 +NUM_REPLICATES = 4 +NUM_EPOCHS = 8 +DATASET_DIR = Path("/raid/clark/summer2021/datasets") +MODEL_PATH_REL_TO_DATASET = Path("paneled_models") +DATA_PATH_REL_TO_DATASET = Path("paneled_data") +VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") + +compared_models = { + "resnet18": resnet18 +} + + +def get_pair(o): + curr_im_num = Path(o).name[:5] + if not int(curr_im_num): + prev_im_num = curr_im_num + else: + prev_im_num = int(curr_im_num)-1 + + prev_im = None + for item in Path(o).parent.ls(): + if isinstance(item.name[:5], str): + prev_im = Path(o) + break + if int(item.name[:5]) == prev_im_num: + prev_im = item + if prev_im is None: + prev_im = Path(o) + + assert prev_im != None + + img1 = Image.open(o).convert('RGB') + img2 = Image.open(prev_im).convert('RGB') + img1_t = transforms.ToTensor()(img1).unsqueeze_(0) + img2_t = transforms.ToTensor()(img2).unsqueeze_(0) + + new_shape = list(img1_t.shape) + new_shape[-2] = new_shape[-2] * 2 + img3_t = torch.zeros(new_shape) + + img3_t[:, :, :224, :] = img1_t + img3_t[:, :, 224:, :] = img2_t + + img3 = transforms.ToPILImage()(img3_t.squeeze_(0)) + + return np.array(img3) + + +def get_fig_filename(prefix: str, label: str, ext: str, rep: int) -> str: + fig_filename = f"{prefix}-{label}-{rep}.{ext}" + print(label, "filename :", fig_filename) + return fig_filename + + +def filename_to_class(filename: str) -> str: + angle = float(filename.split("_")[1].split(".")[0].replace("p", ".")) + if angle > 0: + return "left" + elif angle < 0: + return "right" + else: + return "forward" + + +def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: + + path = DATASET_DIR / dataset_name + + db = DataBlock( + blocks=(ImageBlock, CategoryBlock), + get_items=get_image_files, + get_x=get_pair, + get_y=filename_to_class, + splitter=RandomSplitter(valid_pct=VALID_PCT) + ) + + dls = db.dataloaders(path, bs=64) + + dls.show_batch() # type: ignore + plt.savefig(get_fig_filename(prefix, "batch", "pdf", 0)) + + return dls # type: ignore + + +def train_model( + dls: DataLoaders, + model_arch: str, + pretrained: bool, + logname: Path, + modelname: Path, + prefix: str, + rep: int, +): + learn = cnn_learner( + dls, + compared_models[model_arch], + metrics=accuracy, + pretrained=pretrained, + cbs=CSVLogger(fname=logname), + ) + + if pretrained: + learn.fine_tune(NUM_EPOCHS) + else: + learn.fit_one_cycle(NUM_EPOCHS) + + # The follwing line is necessary for pickling + learn.remove_cb(CSVLogger) + learn.export(modelname) + + learn.show_results() + plt.savefig(get_fig_filename(prefix, "results", "pdf", rep)) + + interp = ClassificationInterpretation.from_learner(learn) + interp.plot_top_losses(9, figsize=(15, 10)) + plt.savefig(get_fig_filename(prefix, "toplosses", "pdf", rep)) + + interp.plot_confusion_matrix(figsize=(10, 10)) + plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep)) + + +def main(): + + arg_parser = ArgumentParser("Train paneled classification networks.") + arg_parser.add_argument( + "model_arch", help="Model architecture (see code for options)" + ) + arg_parser.add_argument( + "dataset_name", help="Name of dataset to use (handmade-full | corrected-wander-full)" + ) + arg_parser.add_argument( + "--pretrained", action="store_true", help="Use pretrained model" + ) + + args = arg_parser.parse_args() + + # TODO: not using this (would require replacing first layer) + # rgb_instead_of_gray = True + + # Make dirs as needed + model_dir = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET + model_dir.mkdir(exist_ok=True) + print(f"Created model dir (or it already exists) : '{model_dir}'") + + data_dir = DATASET_DIR / args.dataset_name / DATA_PATH_REL_TO_DATASET + data_dir.mkdir(exist_ok=True) + print(f"Created data dir (or it already exists) : '{data_dir}'") + + file_prefix = "classification-" + args.model_arch + # file_prefix += "-rgb" if rgb_instead_of_gray else "-gray" + file_prefix += "-pretrained" if args.pretrained else "-notpretrained" + fig_filename_prefix = data_dir / file_prefix + + dls = prepare_dataloaders(args.dataset_name, fig_filename_prefix) + + # Train NUM_REPLICATES separate instances of this model and dataset + for rep in range(NUM_REPLICATES): + + model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pth" + print("Model relative filename :", model_filename) + + # Checks if model exists and skip if it does (helps if this crashes) + if path.exists(model_filename): + continue + + log_filename = DATASET_DIR / args.dataset_name / DATA_PATH_REL_TO_DATASET / f"{file_prefix}-trainlog-{rep}.csv" + print("Log relative filename :", log_filename) + + train_model( + dls, + args.model_arch, + args.pretrained, + log_filename, + model_filename, + fig_filename_prefix, + rep, + ) + + +if __name__ == "__main__": + main() diff --git a/Experiments/TrainRNNClassification.py b/Experiments/TrainRNNClassification.py index 55fc34f..476be90 100644 --- a/Experiments/TrainRNNClassification.py +++ b/Experiments/TrainRNNClassification.py @@ -14,19 +14,17 @@ # --- import matplotlib.pyplot as plt -import seaborn as sns import os.path from os import path from fastai.vision.all import * from fastai.callback.progress import CSVLogger -from torch.utils.data import Dataset sys.path.append("../Notebooks") import convLSTM as convLSTM # Assign GPU -torch.cuda.set_device(3) +torch.cuda.set_device(1) print("Running on GPU: " + str(torch.cuda.current_device())) # Constants (same for all trials) @@ -137,7 +135,7 @@ def train_model( def main(): - dataset_name = 'corrected-wander-full' + dataset_name = 'handmade-full' model_arch = "RNN" # Make dirs as needed diff --git a/Experiments/TrainStackedClassification.py b/Experiments/TrainStackedClassification.py new file mode 100644 index 0000000..b94f08d --- /dev/null +++ b/Experiments/TrainStackedClassification.py @@ -0,0 +1,208 @@ +# --- +# jupyter: +# jupytext: +# formats: py:light +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.11.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +from argparse import ArgumentParser + +import matplotlib.pyplot as plt +import os.path +from os import path + +from fastai.vision.all import * +from fastai.callback.progress import CSVLogger +from torchvision import transforms + +# Assign GPU +torch.cuda.set_device(0) +print("Running on GPU: " + str(torch.cuda.current_device())) + +# Constants (same for all trials) +VALID_PCT = 0.05 +NUM_REPLICATES = 1 +NUM_EPOCHS = 1 +DATASET_DIR = Path("/raid/clark/summer2021/datasets") +MODEL_PATH_REL_TO_DATASET = Path("stacked_models") +DATA_PATH_REL_TO_DATASET = Path("stacked_data") +VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") + +compared_models = { + "resnet18": resnet18 +} + + +def get_pair_2(o): + curr_im_num = Path(o).name[:5] + if not int(curr_im_num): + prev_im_num = curr_im_num + else: + prev_im_num = int(curr_im_num)-1 + + prev_im = None + for item in Path(o).parent.ls(): + if isinstance(item.name[:5], str): + prev_im = Path(o) + break + if int(item.name[:5]) == prev_im_num: + prev_im = item + if prev_im is None: + prev_im = Path(o) + assert prev_im != None + + img1 = Image.open(o).convert('RGB') + img2 = Image.open(prev_im).convert('RGB') + img1_arr = np.array(img1, dtype=np.uint8) + img2_arr = np.array(img2, dtype=np.uint8) + + new_shape = list(img1_arr.shape) + new_shape[-1] = new_shape[-1] * 2 + img3_arr = np.zeros(new_shape, dtype=np.uint8) + + img3_arr[:, :, :3] = img1_arr + img3_arr[:, :, 3:] = img2_arr + + return img3_arr.T.astype(np.float32) + + +def get_fig_filename(prefix: str, label: str, ext: str, rep: int) -> str: + fig_filename = f"{prefix}-{label}-{rep}.{ext}" + print(label, "filename :", fig_filename) + return fig_filename + + +def filename_to_class(filename: str) -> str: + angle = float(filename.split("_")[1].split(".")[0].replace("p", ".")) + if angle > 0: + return "left" + elif angle < 0: + return "right" + else: + return "forward" + + +def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: + + path = DATASET_DIR / dataset_name + + db = DataBlock( + blocks=((ImageBlock, ImageBlock), CategoryBlock), + get_items=get_image_files, + get_x=get_pair_2, + get_y=filename_to_class, + splitter=RandomSplitter(valid_pct=VALID_PCT) + ) + + dls = db.dataloaders(path, bs=64) + + return dls # type: ignore + + +def train_model( + dls: DataLoaders, + model_arch: str, + pretrained: bool, + logname: Path, + modelname: Path, + prefix: str, + rep: int, +): + learn = cnn_learner( + dls, + compared_models[model_arch], + metrics=accuracy, + pretrained=pretrained, + cbs=CSVLogger(fname=logname), + ) + + learn.model[0][0] = nn.Conv2d(6, 64, kernel_size=(7,7), stride=(2,2), padding=(3,3), bias=False) + + if pretrained: + learn.fine_tune(NUM_EPOCHS) + else: + learn.fit_one_cycle(NUM_EPOCHS) + + # The follwing line is necessary for pickling + learn.remove_cb(CSVLogger) + learn.export(modelname) + + learn.show_results() + plt.savefig(get_fig_filename(prefix, "results", "pdf", rep)) + + interp = ClassificationInterpretation.from_learner(learn) + interp.plot_top_losses(9, figsize=(15, 10)) + plt.savefig(get_fig_filename(prefix, "toplosses", "pdf", rep)) + + interp.plot_confusion_matrix(figsize=(10, 10)) + plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep)) + + +def main(): + + arg_parser = ArgumentParser("Train stacked classification networks.") + arg_parser.add_argument( + "model_arch", help="Model architecture (see code for options)" + ) + arg_parser.add_argument( + "dataset_name", help="Name of dataset to use (handmade-full | corrected-wander-full)" + ) + arg_parser.add_argument( + "--pretrained", action="store_true", help="Use pretrained model" + ) + + args = arg_parser.parse_args() + + # TODO: not using this (would require replacing first layer) + # rgb_instead_of_gray = True + + # Make dirs as needed + model_dir = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET + model_dir.mkdir(exist_ok=True) + print(f"Created model dir (or it already exists) : '{model_dir}'") + + data_dir = DATASET_DIR / args.dataset_name / DATA_PATH_REL_TO_DATASET + data_dir.mkdir(exist_ok=True) + print(f"Created data dir (or it already exists) : '{data_dir}'") + + file_prefix = "classification-" + args.model_arch + # file_prefix += "-rgb" if rgb_instead_of_gray else "-gray" + file_prefix += "-pretrained" if args.pretrained else "-notpretrained" + fig_filename_prefix = data_dir / file_prefix + + dls = prepare_dataloaders(args.dataset_name, fig_filename_prefix) + + # Train NUM_REPLICATES separate instances of this model and dataset + for rep in range(NUM_REPLICATES): + + model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pth" + print("Model relative filename :", model_filename) + + # Checks if model exists and skip if it does (helps if this crashes) + if path.exists(model_filename): + continue + + log_filename = DATASET_DIR / args.dataset_name / DATA_PATH_REL_TO_DATASET / f"{file_prefix}-trainlog-{rep}.csv" + print("Log relative filename :", log_filename) + + train_model( + dls, + args.model_arch, + args.pretrained, + log_filename, + model_filename, + fig_filename_prefix, + rep, + ) + + +if __name__ == "__main__": + main() From b48729883ba83430ff67799fd69d6c0fa0507542 Mon Sep 17 00:00:00 2001 From: Christy-Marchese Date: Wed, 18 Aug 2021 11:10:59 -0700 Subject: [PATCH 2/5] updated numbers for paneled and stacked classification --- Experiments/TrainPaneledClassification.py | 8 ++++---- Experiments/TrainStackedClassification.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Experiments/TrainPaneledClassification.py b/Experiments/TrainPaneledClassification.py index 9a2326b..cc730d7 100644 --- a/Experiments/TrainPaneledClassification.py +++ b/Experiments/TrainPaneledClassification.py @@ -42,18 +42,18 @@ def get_pair(o): - curr_im_num = Path(o).name[:5] - if not int(curr_im_num): + curr_im_num = Path(o).name[:6] + if int(curr_im_num) == 0: prev_im_num = curr_im_num else: prev_im_num = int(curr_im_num)-1 prev_im = None for item in Path(o).parent.ls(): - if isinstance(item.name[:5], str): + if isinstance(item.name[:6], str): prev_im = Path(o) break - if int(item.name[:5]) == prev_im_num: + if int(item.name[:6]) == prev_im_num: prev_im = item if prev_im is None: prev_im = Path(o) diff --git a/Experiments/TrainStackedClassification.py b/Experiments/TrainStackedClassification.py index b94f08d..8c479f7 100644 --- a/Experiments/TrainStackedClassification.py +++ b/Experiments/TrainStackedClassification.py @@ -29,8 +29,8 @@ # Constants (same for all trials) VALID_PCT = 0.05 -NUM_REPLICATES = 1 -NUM_EPOCHS = 1 +NUM_REPLICATES = 4 +NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") MODEL_PATH_REL_TO_DATASET = Path("stacked_models") DATA_PATH_REL_TO_DATASET = Path("stacked_data") @@ -42,18 +42,18 @@ def get_pair_2(o): - curr_im_num = Path(o).name[:5] - if not int(curr_im_num): + curr_im_num = Path(o).name[:6] + if int(curr_im_num) == 0: prev_im_num = curr_im_num else: prev_im_num = int(curr_im_num)-1 prev_im = None for item in Path(o).parent.ls(): - if isinstance(item.name[:5], str): + if isinstance(item.name[:6], str): prev_im = Path(o) break - if int(item.name[:5]) == prev_im_num: + if int(item.name[:6]) == prev_im_num: prev_im = item if prev_im is None: prev_im = Path(o) From 179494d99430baef73607505e0c0ae4d4a22a839 Mon Sep 17 00:00:00 2001 From: Christy-Marchese Date: Wed, 18 Aug 2021 15:04:40 -0700 Subject: [PATCH 3/5] Regression training scripts --- Experiments/RunCmdClassification.py | 4 +- Experiments/RunTrainPaneledClassification.py | 26 +-- Experiments/RunTrainRegression.py | 34 ++++ Experiments/RunTrainStackedClassification.py | 26 +-- Experiments/TrainCmdClassification.py | 15 +- Experiments/TrainPaneledClassification.py | 4 +- Experiments/TrainRegression.py | 196 +++++++++++++++++++ Experiments/TrainStackedClassification.py | 4 +- 8 files changed, 272 insertions(+), 37 deletions(-) create mode 100644 Experiments/RunTrainRegression.py create mode 100644 Experiments/TrainRegression.py diff --git a/Experiments/RunCmdClassification.py b/Experiments/RunCmdClassification.py index f343b8a..f17c9ac 100644 --- a/Experiments/RunCmdClassification.py +++ b/Experiments/RunCmdClassification.py @@ -16,7 +16,9 @@ from subprocess import run compared_models = [ - "resnet18", + "xresnext18", + "alexnet", + "densenet121", ] for model in compared_models: diff --git a/Experiments/RunTrainPaneledClassification.py b/Experiments/RunTrainPaneledClassification.py index da78a07..d07a699 100644 --- a/Experiments/RunTrainPaneledClassification.py +++ b/Experiments/RunTrainPaneledClassification.py @@ -16,19 +16,19 @@ from subprocess import run compared_models = [ - "resnet18", + "xresnext18", + "alexnet", + "densenet121", ] -for dataset in ["handmade-full", "corrected-wander-full"]: +for model in compared_models: - for model in compared_models: - - run( - [ - "python", - "TrainPaneledClassification.py", - model, - dataset, - "--pretrained", - ] - ) + run( + [ + "python", + "TrainPaneledClassification.py", + model, + "corrected-wander-full", + "--pretrained", + ] + ) diff --git a/Experiments/RunTrainRegression.py b/Experiments/RunTrainRegression.py new file mode 100644 index 0000000..152cd88 --- /dev/null +++ b/Experiments/RunTrainRegression.py @@ -0,0 +1,34 @@ +# --- +# jupyter: +# jupytext: +# formats: py:light +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.11.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +from subprocess import run + +compared_models = [ + "xresnext18", + "alexnet", + "densenet121", +] + +for model in compared_models: + + run( + [ + "python", + "TrainRegression.py", + model, + "corrected-wander-full", + "--pretrained", + ] + ) diff --git a/Experiments/RunTrainStackedClassification.py b/Experiments/RunTrainStackedClassification.py index 0dc6928..8242ed4 100644 --- a/Experiments/RunTrainStackedClassification.py +++ b/Experiments/RunTrainStackedClassification.py @@ -16,19 +16,19 @@ from subprocess import run compared_models = [ - "resnet18", + "xresnext18", + "alexnet", + "densenet121", ] -for dataset in ["handmade-full", "corrected-wander-full"]: +for model in compared_models: - for model in compared_models: - - run( - [ - "python", - "TrainStackedClassification.py", - model, - dataset, - "--pretrained", - ] - ) + run( + [ + "python", + "TrainStackedClassification.py", + model, + "corrected-wander-full", + "--pretrained", + ] + ) diff --git a/Experiments/TrainCmdClassification.py b/Experiments/TrainCmdClassification.py index c4bff7f..9a7d8a6 100644 --- a/Experiments/TrainCmdClassification.py +++ b/Experiments/TrainCmdClassification.py @@ -26,20 +26,22 @@ # - # Assign GPU -torch.cuda.set_device(2) +torch.cuda.set_device(3) print("Running on GPU: " + str(torch.cuda.current_device())) # Constants (same for all trials) VALID_PCT = 0.05 -NUM_REPLICATES = 1 -NUM_EPOCHS = 1 +NUM_REPLICATES = 4 +NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") MODEL_PATH_REL_TO_DATASET = Path("cmd_models") DATA_PATH_REL_TO_DATASET = Path("cmd_data") VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { - "resnet18": resnet18 + "xresnext18": xresnext18, + "alexnet": alexnet, + "densenet121": densenet121, } @@ -116,7 +118,7 @@ def __init__(self, arch: str, pretrained: bool): super(cmd_model, self).__init__() self.cnn = arch(pretrained=pretrained) - self.fc1 = nn.Linear(self.cnn.fc.out_features + 1, 512) + self.fc1 = nn.Linear(1000 + 1, 512) self.r1 = nn.ReLU(inplace=True) self.fc2 = nn.Linear(512, 3) @@ -167,9 +169,6 @@ def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: dls = DataLoaders.from_dsets(train_data, val_data) dls = dls.cuda() - #dls.show_batch() # type: ignore - plt.savefig(get_fig_filename(prefix, "batch", "pdf", 0)) - return dls # type: ignore diff --git a/Experiments/TrainPaneledClassification.py b/Experiments/TrainPaneledClassification.py index cc730d7..7f88004 100644 --- a/Experiments/TrainPaneledClassification.py +++ b/Experiments/TrainPaneledClassification.py @@ -37,7 +37,9 @@ VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { - "resnet18": resnet18 + "xresnext18": xresnext18, + "alexnet": alexnet, + "densenet121": densenet121, } diff --git a/Experiments/TrainRegression.py b/Experiments/TrainRegression.py new file mode 100644 index 0000000..b9babe1 --- /dev/null +++ b/Experiments/TrainRegression.py @@ -0,0 +1,196 @@ +# --- +# jupyter: +# jupytext: +# formats: py:light +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.11.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +from argparse import ArgumentParser + +import matplotlib.pyplot as plt +import os.path +from os import path + +from fastai.vision.all import * +from fastai.callback.progress import CSVLogger +from torchvision import transforms +from math import pi + +# Assign GPU +torch.cuda.set_device(0) +print("Running on GPU: " + str(torch.cuda.current_device())) + +# Constants (same for all trials) +VALID_PCT = 0.05 +NUM_REPLICATES = 4 +NUM_EPOCHS = 8 +DATASET_DIR = Path("/raid/clark/summer2021/datasets") +MODEL_PATH_REL_TO_DATASET = Path("regression_models") +DATA_PATH_REL_TO_DATASET = Path("regression_data") +VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") + +compared_models = { + "xresnext18": xresnext18, + "alexnet": alexnet, + "densenet121": densenet121, +} + + +def get_throttles(f): + split_name = f.name.split('_') + angle = float(split_name[1][:-4].replace("p", ".")) + if angle < 0: + return tensor([2.5, -2.5])#torch.stack((tensor(0.),tensor(-angle))) + elif angle > 0: + return tensor([-2.5, 2.5])#torch.stack((tensor(angle),tensor(0.))) + else: + return tensor([2.5, 2.5])#torch.stack((tensor(2.5),tensor(2.5))) + + +def angle_metric(preds, targs): + angle_true = targs[:, 1] - targs[:, 0] + angle_pred = preds[:, 1] - preds[:, 0] + return torch.where(torch.abs(angle_true - angle_pred) < 0.1, 1., 0.).mean() + + +def direction_metric(preds, targs): + angle_true = targs[:, 1] - targs[:, 0] + angle_pred = preds[:, 1] - preds[:, 0] + return torch.where( + torch.logical_or( + torch.sign(angle_pred) == torch.sign(angle_true), + torch.abs(angle_pred) < 0.1, + ), + 1.0, + 0.0, + ).mean() + + +def get_fig_filename(prefix: str, label: str, ext: str, rep: int) -> str: + fig_filename = f"{prefix}-{label}-{rep}.{ext}" + print(label, "filename :", fig_filename) + return fig_filename + + +def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: + + path = DATASET_DIR / dataset_name + + db = DataBlock( + blocks=(ImageBlock, RegressionBlock), + get_items=get_image_files, + get_y=get_throttles, + splitter=RandomSplitter(valid_pct=VALID_PCT), + ) + + dls = db.dataloaders(path, bs=64) + + return dls # type: ignore + + +def train_model( + dls: DataLoaders, + model_arch: str, + pretrained: bool, + logname: Path, + modelname: Path, + prefix: str, + rep: int, +): + learn = cnn_learner( + dls, + compared_models[model_arch], + y_range=(-100, 100), + metrics=[mse, angle_metric, direction_metric], + pretrained=pretrained, + cbs=CSVLogger(fname=logname), + ) + + if pretrained: + learn.fine_tune(NUM_EPOCHS) + else: + learn.fit_one_cycle(NUM_EPOCHS) + + # The follwing line is necessary for pickling + learn.remove_cb(CSVLogger) + learn.export(modelname) + + learn.show_results() + plt.savefig(get_fig_filename(prefix, "results", "pdf", rep)) + + interp = ClassificationInterpretation.from_learner(learn) + interp.plot_top_losses(9, figsize=(15, 10)) + plt.savefig(get_fig_filename(prefix, "toplosses", "pdf", rep)) + + interp.plot_confusion_matrix(figsize=(10, 10)) + plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep)) + + +def main(): + + arg_parser = ArgumentParser("Train regression networks.") + arg_parser.add_argument( + "model_arch", help="Model architecture (see code for options)" + ) + arg_parser.add_argument( + "dataset_name", help="Name of dataset to use (handmade-full | corrected-wander-full)" + ) + arg_parser.add_argument( + "--pretrained", action="store_true", help="Use pretrained model" + ) + + args = arg_parser.parse_args() + + # TODO: not using this (would require replacing first layer) + # rgb_instead_of_gray = True + + # Make dirs as needed + model_dir = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET + model_dir.mkdir(exist_ok=True) + print(f"Created model dir (or it already exists) : '{model_dir}'") + + data_dir = DATASET_DIR / args.dataset_name / DATA_PATH_REL_TO_DATASET + data_dir.mkdir(exist_ok=True) + print(f"Created data dir (or it already exists) : '{data_dir}'") + + file_prefix = "classification-" + args.model_arch + # file_prefix += "-rgb" if rgb_instead_of_gray else "-gray" + file_prefix += "-pretrained" if args.pretrained else "-notpretrained" + fig_filename_prefix = data_dir / file_prefix + + dls = prepare_dataloaders(args.dataset_name, fig_filename_prefix) + + # Train NUM_REPLICATES separate instances of this model and dataset + for rep in range(NUM_REPLICATES): + + model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pth" + print("Model relative filename :", model_filename) + + # Checks if model exists and skip if it does (helps if this crashes) + if path.exists(model_filename): + continue + + log_filename = DATASET_DIR / args.dataset_name / DATA_PATH_REL_TO_DATASET / f"{file_prefix}-trainlog-{rep}.csv" + print("Log relative filename :", log_filename) + + train_model( + dls, + args.model_arch, + args.pretrained, + log_filename, + model_filename, + fig_filename_prefix, + rep, + ) + + +if __name__ == "__main__": + main() diff --git a/Experiments/TrainStackedClassification.py b/Experiments/TrainStackedClassification.py index 8c479f7..f06b8da 100644 --- a/Experiments/TrainStackedClassification.py +++ b/Experiments/TrainStackedClassification.py @@ -37,7 +37,9 @@ VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { - "resnet18": resnet18 + "xresnext18": xresnext18, + "alexnet": alexnet, + "densenet121": densenet121, } From e0cbf4105bbfc57a93e3519e4231f9f06e0aa926 Mon Sep 17 00:00:00 2001 From: Christy-Marchese Date: Tue, 5 Oct 2021 21:04:34 -0700 Subject: [PATCH 4/5] TrainRegression.py --- Experiments/RunCmdClassification.py | 1 + Experiments/RunTrainPaneledClassification.py | 3 +- Experiments/RunTrainRegression.py | 3 +- Experiments/RunTrainStackedClassification.py | 3 +- Experiments/TrainCmdClassification.py | 3 +- Experiments/TrainPaneledClassification.py | 48 ++- Experiments/TrainRegression.py | 15 +- Experiments/TrainStackedClassification.py | 52 +-- Imitator/Imitate.py | 98 ++++-- Imitator/ImitateWrapper.py | 60 ++-- Imitator/RegressionImitator.py | 64 ++-- Imitator/imitate_wrapper_note.py | 345 ------------------- Imitator/plot_helper.py | 179 +++++++--- Mazes/validation_mazes8x8_bricks/maze_05.txt | 48 --- Mazes/validation_mazes8x8_bricks/maze_06.txt | 48 --- Mazes/validation_mazes8x8_bricks/maze_07.txt | 48 --- Mazes/validation_mazes8x8_bricks/maze_08.txt | 48 --- Mazes/validation_mazes8x8_bricks/maze_09.txt | 52 --- Mazes/validation_mazes8x8_bricks/maze_10.txt | 58 ---- Mazes/validation_mazes8x8_bricks/maze_11.txt | 58 ---- Mazes/validation_mazes8x8_bricks/maze_12.txt | 64 ---- Mazes/validation_mazes8x8_bricks/maze_13.txt | 50 --- Mazes/validation_mazes8x8_bricks/maze_14.txt | 46 --- Mazes/validation_mazes8x8_bricks/maze_15.txt | 50 --- Mazes/validation_mazes8x8_bricks/maze_16.txt | 60 ---- Mazes/validation_mazes8x8_bricks/maze_17.txt | 54 --- Mazes/validation_mazes8x8_bricks/maze_18.txt | 46 --- Mazes/validation_mazes8x8_bricks/maze_19.txt | 46 --- Mazes/validation_mazes8x8_bricks/maze_20.txt | 54 --- 29 files changed, 340 insertions(+), 1364 deletions(-) delete mode 100644 Imitator/imitate_wrapper_note.py delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_05.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_06.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_07.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_08.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_09.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_10.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_11.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_12.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_13.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_14.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_15.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_16.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_17.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_18.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_19.txt delete mode 100644 Mazes/validation_mazes8x8_bricks/maze_20.txt diff --git a/Experiments/RunCmdClassification.py b/Experiments/RunCmdClassification.py index f17c9ac..bea2ed3 100644 --- a/Experiments/RunCmdClassification.py +++ b/Experiments/RunCmdClassification.py @@ -16,6 +16,7 @@ from subprocess import run compared_models = [ + "xresnext50", "xresnext18", "alexnet", "densenet121", diff --git a/Experiments/RunTrainPaneledClassification.py b/Experiments/RunTrainPaneledClassification.py index d07a699..86e3b8e 100644 --- a/Experiments/RunTrainPaneledClassification.py +++ b/Experiments/RunTrainPaneledClassification.py @@ -16,8 +16,9 @@ from subprocess import run compared_models = [ - "xresnext18", "alexnet", + "xresnext50", + "xresnext18", "densenet121", ] diff --git a/Experiments/RunTrainRegression.py b/Experiments/RunTrainRegression.py index 152cd88..c477d24 100644 --- a/Experiments/RunTrainRegression.py +++ b/Experiments/RunTrainRegression.py @@ -16,9 +16,10 @@ from subprocess import run compared_models = [ - "xresnext18", "alexnet", + "xresnext18", "densenet121", + "xresnext50", ] for model in compared_models: diff --git a/Experiments/RunTrainStackedClassification.py b/Experiments/RunTrainStackedClassification.py index 8242ed4..915f31a 100644 --- a/Experiments/RunTrainStackedClassification.py +++ b/Experiments/RunTrainStackedClassification.py @@ -16,8 +16,9 @@ from subprocess import run compared_models = [ - "xresnext18", "alexnet", + "xresnext50", + "xresnext18", "densenet121", ] diff --git a/Experiments/TrainCmdClassification.py b/Experiments/TrainCmdClassification.py index 9a7d8a6..3a51751 100644 --- a/Experiments/TrainCmdClassification.py +++ b/Experiments/TrainCmdClassification.py @@ -26,7 +26,7 @@ # - # Assign GPU -torch.cuda.set_device(3) +torch.cuda.set_device(2) print("Running on GPU: " + str(torch.cuda.current_device())) # Constants (same for all trials) @@ -39,6 +39,7 @@ VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { + "xresnext50": xresnext50, "xresnext18": xresnext18, "alexnet": alexnet, "densenet121": densenet121, diff --git a/Experiments/TrainPaneledClassification.py b/Experiments/TrainPaneledClassification.py index 7f88004..e8d09e7 100644 --- a/Experiments/TrainPaneledClassification.py +++ b/Experiments/TrainPaneledClassification.py @@ -24,7 +24,7 @@ from torchvision import transforms # Assign GPU -torch.cuda.set_device(0) +torch.cuda.set_device(2) print("Running on GPU: " + str(torch.cuda.current_device())) # Constants (same for all trials) @@ -32,35 +32,28 @@ NUM_REPLICATES = 4 NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") -MODEL_PATH_REL_TO_DATASET = Path("paneled_models") -DATA_PATH_REL_TO_DATASET = Path("paneled_data") +MODEL_PATH_REL_TO_DATASET = Path("paneled_models1") +DATA_PATH_REL_TO_DATASET = Path("paneled_data1") VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { - "xresnext18": xresnext18, "alexnet": alexnet, + "xresnext50": xresnext50, + "xresnext18": xresnext18, "densenet121": densenet121, } +img_dir = Path("/raid/clark/summer2021/datasets/corrected-wander-full/") +img_filenames = list(img_dir.glob("*.png")) +img_filenames.sort() def get_pair(o): - curr_im_num = Path(o).name[:6] - if int(curr_im_num) == 0: - prev_im_num = curr_im_num - else: - prev_im_num = int(curr_im_num)-1 - - prev_im = None - for item in Path(o).parent.ls(): - if isinstance(item.name[:6], str): - prev_im = Path(o) - break - if int(item.name[:6]) == prev_im_num: - prev_im = item - if prev_im is None: - prev_im = Path(o) - - assert prev_im != None + curr_im_num = int(Path(o).name[:6]) + prev_im_num = curr_im_num if curr_im_num == 0 else curr_im_num - 1 + prev_im = img_filenames[prev_im_num] + + #print(curr_im_num, prev_im_num) + #print(o, prev_im) img1 = Image.open(o).convert('RGB') img2 = Image.open(prev_im).convert('RGB') @@ -102,13 +95,12 @@ def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: db = DataBlock( blocks=(ImageBlock, CategoryBlock), get_items=get_image_files, - get_x=get_pair, - get_y=filename_to_class, - splitter=RandomSplitter(valid_pct=VALID_PCT) + splitter=RandomSplitter(valid_pct=VALID_PCT), + get_y=lambda x: filename_to_class(str(x)), + get_x=get_pair ) dls = db.dataloaders(path, bs=64) - dls.show_batch() # type: ignore plt.savefig(get_fig_filename(prefix, "batch", "pdf", 0)) @@ -140,7 +132,7 @@ def train_model( # The follwing line is necessary for pickling learn.remove_cb(CSVLogger) learn.export(modelname) - +""" learn.show_results() plt.savefig(get_fig_filename(prefix, "results", "pdf", rep)) @@ -149,7 +141,7 @@ def train_model( plt.savefig(get_fig_filename(prefix, "toplosses", "pdf", rep)) interp.plot_confusion_matrix(figsize=(10, 10)) - plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep)) + plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep))""" def main(): @@ -189,7 +181,7 @@ def main(): # Train NUM_REPLICATES separate instances of this model and dataset for rep in range(NUM_REPLICATES): - model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pth" + model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pkl" print("Model relative filename :", model_filename) # Checks if model exists and skip if it does (helps if this crashes) diff --git a/Experiments/TrainRegression.py b/Experiments/TrainRegression.py index b9babe1..541f7bf 100644 --- a/Experiments/TrainRegression.py +++ b/Experiments/TrainRegression.py @@ -25,7 +25,7 @@ from math import pi # Assign GPU -torch.cuda.set_device(0) +torch.cuda.set_device(3) print("Running on GPU: " + str(torch.cuda.current_device())) # Constants (same for all trials) @@ -33,11 +33,12 @@ NUM_REPLICATES = 4 NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") -MODEL_PATH_REL_TO_DATASET = Path("regression_models") -DATA_PATH_REL_TO_DATASET = Path("regression_data") +MODEL_PATH_REL_TO_DATASET = Path("regression_models1") +DATA_PATH_REL_TO_DATASET = Path("regression_data1") VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { + "xresnext50": xresnext50, "xresnext18": xresnext18, "alexnet": alexnet, "densenet121": densenet121, @@ -108,7 +109,7 @@ def train_model( learn = cnn_learner( dls, compared_models[model_arch], - y_range=(-100, 100), + y_range=(-180, 180), metrics=[mse, angle_metric, direction_metric], pretrained=pretrained, cbs=CSVLogger(fname=logname), @@ -122,7 +123,7 @@ def train_model( # The follwing line is necessary for pickling learn.remove_cb(CSVLogger) learn.export(modelname) - +""" learn.show_results() plt.savefig(get_fig_filename(prefix, "results", "pdf", rep)) @@ -131,7 +132,7 @@ def train_model( plt.savefig(get_fig_filename(prefix, "toplosses", "pdf", rep)) interp.plot_confusion_matrix(figsize=(10, 10)) - plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep)) + plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep))""" def main(): @@ -171,7 +172,7 @@ def main(): # Train NUM_REPLICATES separate instances of this model and dataset for rep in range(NUM_REPLICATES): - model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pth" + model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pkl" print("Model relative filename :", model_filename) # Checks if model exists and skip if it does (helps if this crashes) diff --git a/Experiments/TrainStackedClassification.py b/Experiments/TrainStackedClassification.py index f06b8da..dd56e4c 100644 --- a/Experiments/TrainStackedClassification.py +++ b/Experiments/TrainStackedClassification.py @@ -24,7 +24,7 @@ from torchvision import transforms # Assign GPU -torch.cuda.set_device(0) +torch.cuda.set_device(1) print("Running on GPU: " + str(torch.cuda.current_device())) # Constants (same for all trials) @@ -32,34 +32,26 @@ NUM_REPLICATES = 4 NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") -MODEL_PATH_REL_TO_DATASET = Path("stacked_models") -DATA_PATH_REL_TO_DATASET = Path("stacked_data") +MODEL_PATH_REL_TO_DATASET = Path("stacked_models1") +DATA_PATH_REL_TO_DATASET = Path("stacked_data1") VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { - "xresnext18": xresnext18, "alexnet": alexnet, + "xresnext50": xresnext50, + "xresnext18": xresnext18, "densenet121": densenet121, } +img_dir = Path("/raid/clark/summer2021/datasets/corrected-wander-full/") +img_filenames = list(img_dir.glob("*.png")) +img_filenames.sort() + def get_pair_2(o): - curr_im_num = Path(o).name[:6] - if int(curr_im_num) == 0: - prev_im_num = curr_im_num - else: - prev_im_num = int(curr_im_num)-1 - - prev_im = None - for item in Path(o).parent.ls(): - if isinstance(item.name[:6], str): - prev_im = Path(o) - break - if int(item.name[:6]) == prev_im_num: - prev_im = item - if prev_im is None: - prev_im = Path(o) - assert prev_im != None + curr_im_num = int(Path(o).name[:6]) + prev_im_num = curr_im_num if curr_im_num == 0 else curr_im_num - 1 + prev_im = img_filenames[prev_im_num] img1 = Image.open(o).convert('RGB') img2 = Image.open(prev_im).convert('RGB') @@ -100,7 +92,7 @@ def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: blocks=((ImageBlock, ImageBlock), CategoryBlock), get_items=get_image_files, get_x=get_pair_2, - get_y=filename_to_class, + get_y=lambda x: filename_to_class(str(x)), splitter=RandomSplitter(valid_pct=VALID_PCT) ) @@ -126,8 +118,16 @@ def train_model( cbs=CSVLogger(fname=logname), ) - learn.model[0][0] = nn.Conv2d(6, 64, kernel_size=(7,7), stride=(2,2), padding=(3,3), bias=False) - + out_channels = learn.model[0][0][0].out_channels + kernel_size = learn.model[0][0][0].kernel_size + stride = learn.model[0][0][0].stride + padding = learn.model[0][0][0].padding + if (model_arch == "alexnet"): + learn.model[0][0][0] = nn.Conv2d(6, out_channels, kernel_size=kernel_size, stride=stride, padding=padding) + else: + bias = learn.model[0][0][0].bias + learn.model[0][0][0] = nn.Conv2d(6, out_channels, kernel_size=kernel_size, stride=stride, padding=padding, bias=bias) + if pretrained: learn.fine_tune(NUM_EPOCHS) else: @@ -136,7 +136,7 @@ def train_model( # The follwing line is necessary for pickling learn.remove_cb(CSVLogger) learn.export(modelname) - +""" learn.show_results() plt.savefig(get_fig_filename(prefix, "results", "pdf", rep)) @@ -145,7 +145,7 @@ def train_model( plt.savefig(get_fig_filename(prefix, "toplosses", "pdf", rep)) interp.plot_confusion_matrix(figsize=(10, 10)) - plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep)) + plt.savefig(get_fig_filename(prefix, "confusion", "pdf", rep))""" def main(): @@ -185,7 +185,7 @@ def main(): # Train NUM_REPLICATES separate instances of this model and dataset for rep in range(NUM_REPLICATES): - model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pth" + model_filename = DATASET_DIR / args.dataset_name / MODEL_PATH_REL_TO_DATASET / f"{file_prefix}-{rep}.pkl" print("Model relative filename :", model_filename) # Checks if model exists and skip if it does (helps if this crashes) diff --git a/Imitator/Imitate.py b/Imitator/Imitate.py index f141959..414e845 100644 --- a/Imitator/Imitate.py +++ b/Imitator/Imitate.py @@ -17,7 +17,11 @@ sys.path.append("../Notebooks") # from RNN_classes_funcs_Marchese import * # from cmd_classes_funcs_Marchese import * -# For Christy's cmd models +sys.path.append("../Experiments") +from TrainRNNClassification import * +from TrainCmdClassification import * +from TrainStackedClassification import * +from TrainPaneledClassification import * def parent_to_deg(f): parent = parent_label(f) @@ -74,32 +78,35 @@ def get_label(o): def get_pair_2(o): - curr_im_num = Path(o).name[:5] - if not int(curr_im_num): + curr_im_num = Path(o).name[:6] + if int(curr_im_num) == 0: prev_im_num = curr_im_num else: - prev_im_num = int(curr_im_num) - 1 - + prev_im_num = int(curr_im_num)-1 + prev_im = None for item in Path(o).parent.ls(): - if int(item.name[:5]) == prev_im_num: + if isinstance(item.name[:6], str): + prev_im = Path(o) + break + if int(item.name[:6]) == prev_im_num: prev_im = item if prev_im is None: prev_im = Path(o) assert prev_im != None - - img1 = Image.open(o).convert("RGB") - img2 = Image.open(prev_im).convert("RGB") + + img1 = Image.open(o).convert('RGB') + img2 = Image.open(prev_im).convert('RGB') img1_arr = np.array(img1, dtype=np.uint8) img2_arr = np.array(img2, dtype=np.uint8) - + new_shape = list(img1_arr.shape) new_shape[-1] = new_shape[-1] * 2 img3_arr = np.zeros(new_shape, dtype=np.uint8) img3_arr[:, :, :3] = img1_arr img3_arr[:, :, 3:] = img2_arr - + return img3_arr.T.astype(np.float32) @@ -118,6 +125,25 @@ def stacked_input(prev_im, curr_im): return stacked_im.T.astype(np.float32) +def paneled_input(prev_im, curr_im): + if prev_im is None: + prev_im = curr_im + + img1_t = transforms.ToTensor()(prev_im).unsqueeze_(0) + img2_t = transforms.ToTensor()(curr_im).unsqueeze_(0) + + new_shape = list(img1_t.shape) + new_shape[-2] = new_shape[-2] * 2 + img3_t = torch.zeros(new_shape) + + img3_t[:, :, :224, :] = img1_t + img3_t[:, :, 224:, :] = img2_t + + img3 = transforms.ToPILImage()(img3_t.squeeze_(0)) + + return np.array(img3) + + def reg_predict(pred_coords): # print(f"type: {type(pred_coords[1])} ") # print(f"pred_coord[1]: {pred_coords} ") @@ -156,9 +182,9 @@ def animate(image_frames, name, dir_name): os.mkdir(dir_name) else: os.system(dir_name) - save_path = os.path.abspath(dir_name) - name = str(name).split("/")[-1][:-4] - fig, ax = plt.subplots() +# save_path = os.path.abspath(dir_name) +# name = str(name).split("/")[-1][:-4] +# fig, ax = plt.subplots() # ln = plt.imshow(image_frames[0]) # def init(): @@ -242,13 +268,18 @@ def train_model( def main(argv): -# torch.cuda.set_device(1) + compared_models = { + "xresnext50": xresnext50, + "xresnext18": xresnext18, + "alexnet": alexnet, + "densenet121": densenet121, + } if torch.cuda.is_available(): - print("Using GPU") device = torch.device('cuda') - torch.cuda.set_device(0) + torch.cuda.set_device(3) else: device = torch.device('cpu') + maze = argv[0] if len(argv) > 0 else "../Mazes/maze01.txt" model = argv[1] if len(argv) > 1 else "../Models/auto-gen-c.pkl" show_freq = int(argv[2]) if len( @@ -266,12 +297,17 @@ def main(argv): world = PycastWorld(224, 224, maze) - if model_type == "cmd" or model_type == "rnn": - model_inf = ConvRNN() + if model_type == "cmd": + map_name = model.split("-")[3] + print(map_name) + model_inf = cmd_model(compared_models[map_name], True) model_inf.load_state_dict(torch.load(model)) else: path = Path("../") - model_inf = load_learner(model, cpu=False) + print("Model: " + model) + model_inf = load_learner(model) +# model_inf = torch.load(model, "cuda:3") +# if "classification-resnet50-pretrained-0.pkl" in model_inf.eval() prev_move = None @@ -286,7 +322,7 @@ def main(argv): stuck = False # Initialize maximum number of steps in case the robot travels in a # completely incorrect direction - max_steps = 3500 #np.random.randint(20, 40 + 1) + max_steps = 3500 # Initialize Maze Check maze_rvs, _, _, maze_directions, _ = read_maze_file(maze) @@ -304,7 +340,9 @@ def main(argv): # Convert image_data and give to network if model_type == "c": if stacked: - move = model_inf.predict(stacked_input(prev_image_data, image_data))[0] + with model_inf.no_bar(): + #print(model_inf.predict(paneled_input(prev_image_data, image_data))) + move = model_inf.predict(stacked_input(prev_image_data, image_data))[0] else: with model_inf.no_bar(): move = model_inf.predict(image_data)[0] @@ -312,6 +350,7 @@ def main(argv): if stacked: pred_coords, _, _ = model_inf.predict(stacked_input(prev_image_data, image_data)) else: +# image_data = torch.from_numpy(image_data) pred_coords, _, _ = model_inf.predict(image_data) move = reg_predict(pred_coords) elif model_type == "cmd": @@ -326,19 +365,20 @@ def main(argv): for i in range(output.size()[0]): # Getting the predicted most probable move action_index = torch.argmax(output[i]) - move = 'left' if action_index == 0 else 'right' if action_index == 1 else 'straight' + move = 'left' if action_index == 0 else 'forward' if action_index == 1 else 'right' else: # is there any reason for us to believe batch sizes can be empty? move = 'straight' elif model_type == "rnn": model_inf.eval() - img = (tensor(image_data)/255).permute(2, 0, 1).unsqueeze(0).unsqueeze(0) - output = model_inf(img) +# img = (tensor(image_data)/255).permute(2, 0, 1).unsqueeze(0).unsqueeze(0) + move = model_inf.predict(image_data)[0] +# output = model_inf(img) # Assuming we always get batches - for i in range(output.size()[0]): - # Getting the predicted most probable move - action_index = torch.argmax(output[i]) - move = 'left' if action_index == 0 else 'right' if action_index == 1 else 'straight' +# for i in range(output.size()[0]): +# # Getting the predicted most probable move +# action_index = torch.argmax(output[i]) +# move = 'left' if action_index == 0 else 'right' if action_index == 1 else 'straight' if move == "left" and prev_move == "right": move = "straight" diff --git a/Imitator/ImitateWrapper.py b/Imitator/ImitateWrapper.py index ea47899..9b92127 100644 --- a/Imitator/ImitateWrapper.py +++ b/Imitator/ImitateWrapper.py @@ -40,39 +40,49 @@ # assume running from Imitator dir def main(): - num_mazes = int(sys.argv[1]) if len(sys.argv) > 1 else 1 - model_dir = '/raid/clark/summer2021/datasets/wander-full/models' +# if torch.cuda.is_available(): +# device = torch.device('cuda') +# torch.cuda.set_device(3) +# else: +# device = torch.device('cpu') + + num_mazes = 20 + model_dir = '/raid/clark/summer2021/datasets/corrected-wander-full/regression_models1' models = os.listdir(model_dir) +# models = list(filter(lambda x: "-notpretrained" in x, models)) models.sort() for i, m in enumerate(models): - models[i] = (model_dir + '/' + m, 'c', 'n', 'n') + models[i] = (model_dir + '/' + m, 'c', 'n', 'y') #model type, stacked, regression - maze_dir = "../Mazes/" + maze_dir = "../Mazes/validation_mazes8x8" + mazes = os.listdir(maze_dir) + mazes.sort() + mazes = list(filter(lambda x: "maze" in x, mazes)) now = datetime.now().strftime("%d-%m-%Y_%H-%M") - subdir = f"{num_mazes}_mazes_test_{now}" - maze_sub_dir = os.path.join(maze_dir, subdir) - os.mkdir(maze_sub_dir) +# subdir = f"{num_mazes}_mazes_test_{now}" +# maze_sub_dir = os.path.join(maze_dir, subdir) +# os.mkdir(maze_sub_dir) dir_name = f"diagnostics-{now}" - print("In AutoWrapper dir name: " + dir_name) +# print("In AutoWrapper dir name: " + dir_name) min_size, max_size = 8, 14 model_names = [Path(m_path).name for m_path, _, _, _ in models] data = {model_name: [] for model_name in model_names} completion_data = {model_name: [] for model_name in model_names} - for i in range(num_mazes): - size = 8#random.randint(min_size, max_size) - maze_file = os.path.join(maze_sub_dir, f"maze_{i+1}.txt") - - print(f"Creating maze {i+1} with size {size}") - os.system( - f"python3 ../MazeGen/MazeGen.py --width {size} --height {size} --out > {maze_file}" - ) - + for maze in mazes: + maze_file = "../Mazes/validation_mazes8x8/" + maze for j, m in enumerate(models): +# print("GPU: " + str(torch.cuda.current_device())) +# if (j >= 4 and j < 28) or (j>=32): +# device = torch.device('cuda') +# torch.cuda.set_device(2) +# else: +# device = torch.device('cuda') +# torch.cuda.set_device(1) model, model_type, stacked, regression = m input_args = [maze_file, model, 17, model_type, stacked, dir_name] - print(f"Testing model {j} on maze {i}") + print(f"Testing model {j} on {maze}") if regression == 'y': num_frames, success, completion_per = RegressionImitator.main(input_args) data[Path(model).name].append(num_frames) @@ -85,15 +95,21 @@ def main(): # Generate plots # Make new directory for plots - os.system(dir_name) - save_path = os.path.abspath(dir_name) +# os.system(dir_name) +# save_path = os.path.abspath(dir_name) # Make Bar Plot - mazes = [f"maze_{i+1}" for i in range(num_mazes)] - clean_names = list(map(get_network_name, model_names)) +# mazes = [f"maze_{i+1}" for i in range(num_mazes)] stepdata = get_df(data, mazes) cdata = get_df(completion_data, mazes) + stepdata.to_csv(dir_name + "/regression_step.csv") # + cdata.to_csv(dir_name + "/regression_percentage.csv") + + clean_names = list(map(get_network_name, model_names)) +# stepdata = get_df(data, mazes) +# cdata = get_df(completion_data, mazes) + # make step bar ax = plot_bars(stepdata, "Steps", clean_names) ax.figure.savefig(os.path.join(save_path, f"step_barchart_{now}.png")) diff --git a/Imitator/RegressionImitator.py b/Imitator/RegressionImitator.py index aa0f5a2..5c94516 100644 --- a/Imitator/RegressionImitator.py +++ b/Imitator/RegressionImitator.py @@ -22,6 +22,8 @@ from matplotlib.animation import FuncAnimation from IPython.display import HTML import time +sys.path.append("../Experiments") +from TrainRegression import * def get_deg(f): @@ -70,37 +72,43 @@ def animate(image_frames, name, dir_name): os.mkdir(dir_name) else: os.system(dir_name) - save_path = os.path.abspath(dir_name) - name = str(name).split("/")[-1][:-4] - fig, ax = plt.subplots() - ln = plt.imshow(image_frames[0]) +# save_path = os.path.abspath(dir_name) +# name = str(name).split("/")[-1][:-4] +# fig, ax = plt.subplots() +# ln = plt.imshow(image_frames[0]) - def init(): - ln.set_data(image_frames[0]) - return [ln] +# def init(): +# ln.set_data(image_frames[0]) +# return [ln] - def update(frame): - ln.set_array(frame) - return [ln] +# def update(frame): +# ln.set_array(frame) +# return [ln] - ani = FuncAnimation(fig, update, image_frames, init_func=init) - ani.save(os.path.join(save_path, name + "_" + str(now) + ".mp4")) +# ani = FuncAnimation(fig, update, image_frames, init_func=init) +# ani.save(os.path.join(save_path, name + "_" + str(now) + ".mp4")) # def add_img_frame(frame): def main(argv): + device = torch.device('cuda') + torch.cuda.set_device(1) + maze = argv[0] if len(argv) > 0 else "../Mazes/maze01.txt" model = argv[1] if len(argv) > 1 else "../Models/auto-gen-c.pkl" show_freq = int(argv[2]) if len(argv) > 2 else 0 # frequency to show frames directory_name = argv[5] if len(argv) > 5 else "tmp_diagnostics" print("DIR NAME: " + directory_name) - env = PycastWorldEnv(maze, 320, 240) + env = PycastWorldEnv(maze, 224, 224) path = Path("../") observation = env.reset() +# model_inf = torch.load(model, map_location=torch.device('cuda')) model_inf = load_learner(model) +# model_inf.load_state_dict(torch.load(model, map_location=torch.device('cuda')), strict=False) + model_inf.eval() frame = 0 frame_freq = 5 num_static = 0 @@ -120,6 +128,7 @@ def main(argv): _, maze_path = bfs_dist_maze(maze_rvs, start_x, start_y, end_x, end_y) on_path = is_on_path(maze_path, int(env.world.x()), int(env.world.y())) + print("Predicting...") while not env.world.at_goal() and num_static < 5 and on_path: # Get image image_data = np.array(env.world) @@ -141,12 +150,12 @@ def main(argv): num_static += 1 else: maze_path.remove((int(prev_x), int(prev_y))) - num_static = 0 + num_static = 0 prev_x = curr_x prev_y = curr_y - if frame % frame_freq == 0: - animation_frames.append(image_data.copy()) - on_path = is_on_path(maze_path, int(env.world.x()), int(env.world.y())) +# if frame % frame_freq == 0: +# animation_frames.append(image_data.copy()) + on_path = is_on_path(maze_path, int(curr_x), int(curr_y)) frame += 1 if frame == max_steps: print("Exceeds step limit") @@ -161,16 +170,16 @@ def main(argv): prev_pred = pred_angle if show_freq != 0 and frame % show_freq == 0: - if curr_x == prev_x and curr_y == prev_y: + if int(curr_x) == int(prev_x) and int(curr_y) == int(prev_y): num_static += 1 else: maze_path.remove((int(prev_x), int(prev_y))) - num_static = 0 + num_static = 0 prev_x = curr_x prev_y = curr_y - if frame % frame_freq == 0: - animation_frames.append(image_data.copy()) - on_path = is_on_path(maze_path, int(env.world.x()), int(env.world.y())) +# if frame % frame_freq == 0: +# animation_frames.append(image_data.copy()) + on_path = is_on_path(maze_path, int(curr_x), int(curr_y)) frame += 1 if frame == max_steps: print("Exceeds step limit") @@ -192,17 +201,18 @@ def main(argv): curr_x, curr_y = round(env.world.x(), 5), round(env.world.y(), 5) if show_freq != 0 and frame % show_freq == 0: - if curr_x == prev_x and curr_y == prev_y: + if int(curr_x) == int(prev_x) and int(curr_y) == int(prev_y): num_static += 1 else: maze_path.remove((int(prev_x), int(prev_y))) - num_static = 0 + num_static = 0 prev_x = curr_x prev_y = curr_y - if frame % frame_freq == 0: - animation_frames.append(image_data.copy()) - on_path = is_on_path(maze_path, int(env.world.x()), int(env.world.y())) +# if frame % frame_freq == 0: +# animation_frames.append(image_data.copy()) + on_path = is_on_path(maze_path, int(curr_x), int(curr_y)) frame += 1 + prev_image_data = image_data if frame == max_steps: print("Exceeds step limit") break diff --git a/Imitator/imitate_wrapper_note.py b/Imitator/imitate_wrapper_note.py deleted file mode 100644 index 11b60fb..0000000 --- a/Imitator/imitate_wrapper_note.py +++ /dev/null @@ -1,345 +0,0 @@ -# --- -# jupyter: -# jupytext: -# formats: ipynb,py:percent -# text_representation: -# extension: .py -# format_name: percent -# format_version: '1.3' -# jupytext_version: 1.11.4 -# kernelspec: -# display_name: Python 3 (ipykernel) -# language: python -# name: python3 -# --- - -# %% -# --- -# jupyter: -# jupytext: -# cell_metadata_filter: -all -# formats: ipynb,py:light -# text_representation: -# extension: .py -# format_name: light -# format_version: '1.5' -# jupytext_version: 1.11.4 -# kernelspec: -# display_name: Python 3 (ipykernel) -# language: python -# name: python3 -# --- - -from datetime import datetime -import matplotlib.pyplot as plt -import matplotlib.ticker as mtick -import numpy as np -import os -from pathlib import Path -import sys -import Imitate -from Imitate import * -import RegressionImitator -from RegressionImitator import * -import pandas -colors = [ - "tab:blue", - "tab:orange", - "tab:green", - "tab:red", - "tab:purple", - "tab:brown", - "tab:pink", -] - -# %% -# assume running from Imitator dir -num_mazes = 2 -model_dir = '/raid/clark/summer2021/datasets/wander-full/models' -models = os.listdir(model_dir) -models.sort() -for i, m in enumerate(models): - models[i] = (model_dir + '/' + m, 'c', 'n', 'n') - -maze_dir = "../Mazes/" -now = datetime.now().strftime("%d-%m-%Y_%H-%M") -subdir = f"{num_mazes}_mazes_test_{now}" -maze_sub_dir = os.path.join(maze_dir, subdir) -os.mkdir(maze_sub_dir) -dir_name = f"diagnostics-{now}" -print("In AutoWrapper dir name: " + dir_name) - -min_size, max_size = 8, 14 - -model_names = [Path(m_path).name for m_path, _, _, _ in models] -data = {model_name: [] for model_name in model_names} -completion_data = {model_name: [] for model_name in model_names} -for i in range(num_mazes): - size = 8#random.randint(min_size, max_size) - maze_file = os.path.join(maze_sub_dir, f"maze_{i+1}.txt") - - print(f"Creating maze {i+1} with size {size}") - os.system( - f"python3 ../MazeGen/MazeGen.py --width {size} --height {size} --out > {maze_file}" - ) - - for j, m in enumerate(models): - model, model_type, stacked, regression = m - input_args = [maze_file, model, 17, model_type, stacked, dir_name] - print(f"Testing model {j} on maze {i}") - if regression == 'y': - num_frames, success, completion_per = RegressionImitator.main(input_args) - data[Path(model).name].append(num_frames) - completion_data[Path(model).name].append(completion_per) - else: - num_frames, success, completion_per = Imitate.main(input_args) - data[Path(model).name].append(num_frames) - completion_data[Path(model).name].append(completion_per) - -# Generate plots - -# Make new directory for plots -os.system(dir_name) -save_path = os.path.abspath(dir_name) - - -# %% [markdown] -# # Bar Plot Code - -# %% -def get_network_name(m): - return m.split('-')[1] - - -# %% -def index_one(num): - return num[0] - - -# %% -mazes = [f"maze_{i+1}" for i in range(num_mazes)] - -# %% -clean_names = list(map(get_network_name, model_names)) - - -# %% -def get_df(data_dict): - df = pd.DataFrame.from_dict(data_dict) - df = df.assign(Maze=mazes) - df = df.T - df.columns = df.iloc[-1] - df = df.drop(df.index[-1]) - # df['Network'] = df.index - df = df.reset_index() - df.rename(columns={'index':'Network'}, inplace=True) - df['std'] = df[df.columns[1:]].std(axis=1) - df['mean'] = df[df.columns[1:-1]].mean(axis=1) - # df = df.assign(lower_error=1.96*df['std']) - df = df.assign(error=1.96*df['std']/np.sqrt(num_mazes)) - return df - - -# %% -stepdata = get_df(data) -stepdata - -# %% -cdata = get_df(completion_data) -cdata - - -# %% -def get_error(df): - ci_bounds = df['error'].to_numpy() - return ci_bounds - - -# %% -def get_colors(num_unique_mazes) -> list: - color_labels = [] - for i in range(num_unique_mazes): - color = colors[i % len(colors)] - for i in range(4): - color_labels.append(color) - return color_labels - - -# %% -def plot_bars(df, metric): - full_names = list(df["Network"]) - clean_names = list(map(get_network_name, full_names)) - unique_names = list(set(clean_names)) - sparse_labels = [] - - for i in range(0, len(clean_names)): - if i % 4 == 0: - sparse_labels.append(clean_names[i]) - else: - sparse_labels.append("") - - color_labels = get_colors(len(unique_names)) - ci_bounds = get_error(df) - max_error = max(df["error"]) - increment = 5 - fig, ax = plt.subplots(figsize=(16, 9)) - - y_lab = "Average Steps Needed Over Averaged Mazes" - - - x = np.arange(len(clean_names)) - width = 0.65 - vals = list(df["mean"]) - - if metric == "Completion": - ax.yaxis.set_major_formatter(mtick.PercentFormatter()) - y_lab = "Average Completion Over Averaged Mazes" - ax.set_yticks(np.arange(0, 100, 10)) - else: - ax.set_yticks(np.arange(0, max(vals), 500)) - - ax.bar( - x, - vals, - yerr=ci_bounds, - color=color_labels, - align="center", - alpha=0.5, - ecolor="black", - capsize=2, - ) - ax.set_xticks(x) - - ax.set_xticklabels(labels=sparse_labels, rotation=45) - # ax.legend() - # Axis styling. - ax.spines["top"].set_visible(False) - ax.spines["right"].set_visible(False) - ax.spines["left"].set_visible(False) - ax.spines["bottom"].set_color("#DDDDDD") - ax.tick_params(bottom=False, left=False) - ax.set_axisbelow(True) - ax.yaxis.grid(True, color="#EEEEEE") - ax.xaxis.grid(False) - - ax.set_xlabel("Network", labelpad=15) - ax.set_ylabel(y_lab, labelpad=15) - ax.set_title(f"{metric} Navigated per Network Replicate") - return ax - -# %% -ax = plot_bars(stepdata, "Steps") - -# %% -ax = plot_bars(cdata, "Completion") - -# %% -cdata - -# %% [markdown] -# # Scatter Plot Code - -# %% -data_dir = "/raid/clark/summer2021/datasets/uniform-full/data" - - -# %% -def get_csv(file): - return "csv" in file - - -# %% -def get_losses(csv_files, data_dir, loss_type): - training_losses = [] - for c in csv_files: - df = pandas.read_csv(data_dir + "/" + c) - training_losses.append(min(df[loss_type])) - return training_losses - - -# %% -def merge_loss_data(data_dir, df, loss_type, average=False): - data_files = os.listdir(data_dir) - data_files.sort() - csvs = list(filter(get_csv, data_files)) - losses = get_losses(csvs, data_dir, loss_type) - means = df['mean'] - names = clean_names - - if average: - losses = np.array(losses).reshape(-1,4).mean(axis=1) - means = np.array(means).reshape(-1,4).mean(axis=1) - names = list(set(clean_names)) - - df = pandas.DataFrame() - df = df.assign(Network = names) - df = df.assign(losses = losses) - df = df.assign(mean_steps = means) - return df - - -# %% -def plot_average_scatter(df): - fig, ax = plt.subplots(figsize=(16, 9)) - x = list(df["losses"]) - y = list(df["mean_steps"]) - ax.scatter(x, y, s=200, c=df.losses, alpha=.5) - ax.set_xlabel("Training Loss") - ax.set_ylabel("Steps Averaged Over Replicates") - ax.spines['top'].set_visible(False) - ax.spines['right'].set_visible(False) - ax.spines['left'].set_visible(False) - ax.spines['bottom'].set_color('#DDDDDD') - ax.set_title("Averaged Steps Taken Over Training Loss per Model") - for i, label in enumerate(list(df['Network'])): - ax.annotate(label, (x[i], y[i])) - return ax - - -# %% -avg_df = merge_loss_data(data_dir, stepdata, "valid_loss", True) -ax = plot_average_scatter(avg_df) -ax.set_title("Averaged Steps Taken Over Valid Loss Per Model") -ax.set_xlabel("Valid Loss") - -# %% -avg_df = merge_loss_data(data_dir, stepdata, "valid_loss", False) -ax = plot_average_scatter(avg_df) -ax.set_xlabel("Valid Loss") -ax.set_title("Averaged Steps Taken Over Valid Loss Per Model") -ax.set_ylabel("Steps Taken Averaged Over Mazes") - -# %% -tlosses_df = merge_loss_data(data_dir, stepdata, "train_loss", True) -ax = plot_average_scatter(tlosses_df) - -# %% -tlosses_df = merge_loss_data(data_dir, stepdata, "train_loss", False) -ax = plot_average_scatter(tlosses_df) -ax.set_ylabel("Steps Taken Averaged Over Mazes") - -# %% [markdown] -# # Boxplot Code - -# %% -stepdata - -# %% -all_data = [] -fig, ax = plt.subplots(figsize=(16, 9)) -for m in mazes: - x = list(stepdata[m]) - all_data.append(x) -ax.boxplot(all_data, labels=mazes) -ax.set_xlabel("Mazes") -ax.set_ylabel("Steps") -ax.spines['top'].set_visible(False) -ax.spines['right'].set_visible(False) -ax.spines['left'].set_visible(False) -ax.spines['bottom'].set_color('#DDDDDD') -ax.set_title("Distribution of Steps per Maze") -# for i, label in enumerate(list(df['Network'])): -# ax.annotate(label, (x[i], y[i])) -# return ax - -# %% diff --git a/Imitator/plot_helper.py b/Imitator/plot_helper.py index 62d3c5c..5aba85d 100644 --- a/Imitator/plot_helper.py +++ b/Imitator/plot_helper.py @@ -10,27 +10,66 @@ import RegressionImitator from RegressionImitator import * import pandas +import seaborn as sns colors = [ "tab:blue", "tab:orange", - "tab:green", - "tab:red", "tab:purple", + "tab:red", + "tab:green", "tab:brown", "tab:pink", ] def get_network_name(m): name = m.split("-")[1] - return ( - name.capitalize() - .replace("net", "Net") - .replace("resnext", "ResNext") - .replace("deep", "Deep") - .replace("deeper", "Deeper") - .replace("_res", "_Res") - ) + if name[0:3] == "xse": + name = ( + name.replace("xse", "X-SE") + .replace("_res", "-Res") + .replace("net", "Net") + .replace("next", "NeXt") + ) + elif name[0] == "x": + name = ( + name.capitalize() + .replace("net", "Net") + .replace("resnext", "ResNeXt") + .replace("res", "-Res") + ) + elif "squeeze" in name: + name = name.capitalize().replace("_", "-").replace("net", "Net") + elif "vgg" in name: + name = name.replace("vgg", "VGG").replace("bn", "BN").replace("_", "-") + elif "dense" in name: + name = name.capitalize().replace("net", "Net") + elif name[0:3] == "res": + name = name.capitalize().replace("net", "Net") + elif "alex" in name: + name = name.capitalize().replace("net", "Net") + + if "deep" in name and "deeper" not in name: + name = name.replace("_deep", "b") + elif "deeper" in name: + name = name.replace("_deeper", "c") + elif "RNN" in name: + name = "" + else: + name = name + "a" + + if ( + ("Squeeze" in name) + or ("VGG" in name) + or ("ResNext" in name and "SE" not in name) + or ("ResNet" in name and "SE" in name) + or ("Dense" in name) + or ("Alex" in name) + or ("ResNet" in name and "SE" not in name and "X-" not in name) + ): + name = name[:-1] + + return name def get_clean_names(m): return m.split("-")[1] @@ -66,9 +105,11 @@ def get_colors(num_unique_mazes) -> list: return color_labels def plot_bars(df, metric): + matplotlib.rcParams.update({'font.size': 12}) + full_names = list(df["Network"]) clean_names = list(map(get_network_name, full_names)) - unique_names = list(set(clean_names)) + unique_names = list(pd.unique(clean_names)) sparse_labels = [] for i in range(0, len(clean_names)): @@ -81,7 +122,7 @@ def plot_bars(df, metric): ci_bounds = get_error(df) max_error = max(df["error"]) increment = 5 - fig, ax = plt.subplots(figsize=(16, 9)) + fig, ax = plt.subplots(figsize=(12, 12)) y_lab = "Average Steps Needed Over Averaged Mazes" x = np.arange(len(clean_names)) @@ -89,27 +130,27 @@ def plot_bars(df, metric): vals = list(df["mean"]) if metric == "Completion": - ax.yaxis.set_major_formatter(mtick.PercentFormatter()) + ax.xaxis.set_major_formatter(mtick.PercentFormatter()) y_lab = "Average Completion Over Averaged Mazes" - ax.set_yticks(np.arange(0, 100, 10)) - ax.set_ylim(bottom = 0.0, top = 100.0) + ax.set_xticks(np.arange(0, 100, 10)) + ax.set_xlim(left = 0.0, right = 100.0) else: - ax.set_yticks(np.arange(0, max(vals), 200)) - ax.set_ylim(bottom = 0.0, top = max(vals)) + ax.set_xticks(np.arange(0, max(vals), 200)) + ax.set_xlim(left = 0.0, right = max(vals)) - ax.bar( + ax.barh( x, vals, - yerr=ci_bounds, + xerr=ci_bounds, color=color_labels, align="center", alpha=0.75, ecolor="grey", capsize=2, ) - ax.set_xticks(x) + ax.set_yticks(x) # ax.set_yticks(np.arange(0, max(vals) + max_error, increment)) - ax.set_xticklabels(labels=sparse_labels, rotation=45) + ax.set_yticklabels(labels=sparse_labels) # ax.legend() # Axis styling. ax.spines["top"].set_visible(False) @@ -118,11 +159,11 @@ def plot_bars(df, metric): ax.spines["bottom"].set_color("#DDDDDD") ax.tick_params(bottom=False, left=False) ax.set_axisbelow(True) - ax.yaxis.grid(True, color="#EEEEEE") - ax.xaxis.grid(False) + ax.xaxis.grid(True, color="#EEEEEE") + ax.yaxis.grid(False) - ax.set_xlabel("Network", labelpad=15) - ax.set_ylabel(y_lab, labelpad=15) + ax.set_xlabel("Percentage Completed", labelpad=15) + ax.set_ylabel("Architecture", labelpad=15) ax.set_title(f"{metric} Navigated per Network Replicate") return ax @@ -130,47 +171,93 @@ def plot_bars(df, metric): def get_csv(file): return "csv" in file +def get_petrained(file): + return "-pretrained" in file + +def get_nonpetrained(file): + return "-notpretrained" in file + def get_losses(csv_files, data_dir, loss_type): training_losses = [] for c in csv_files: + if c == "classification-resnet18-pretrained-trainlog-0.csv": + training_losses.append(0.0) + continue df = pandas.read_csv(data_dir + "/" + c) if len(df) == 0: training_losses.append(0.0) else: - training_losses.append(min(df["valid_loss"])) + if loss_type == "time": + training_losses.append(min(df[loss_type])) + elif loss_type == "accuracy": + training_losses.append(max(df[loss_type])) + else: + training_losses.append(min(df[loss_type])) return training_losses -def merge_loss_data(data_dir, df, loss_type, clean_names, average=False): +def merge_loss_data(data_dir, df, loss_type, model_type, average=False): data_files = os.listdir(data_dir) data_files.sort() csvs = list(filter(get_csv, data_files)) + if model_type == "pretrained": + csvs = list(filter(get_petrained, csvs)) + elif model_type == "rnn": + csvs = csvs + elif model_type == "cmd": + csvs = csvs + else: + csvs = list(filter(get_nonpetrained, csvs)) losses = get_losses(csvs, data_dir, loss_type) means = df['mean'] - names = clean_names + names = list(map(get_network_name, df['Network'])) if average: losses = np.array(losses).reshape(-1,4).mean(axis=1) means = np.array(means).reshape(-1,4).mean(axis=1) - names = list(set(clean_names)) + names = list(pd.unique(names)) df = pandas.DataFrame() - df = df.assign(Network = names) + df = df.assign(clean_names = names) df = df.assign(losses = losses) - df = df.assign(mean_steps = means) + df = df.assign(mean_completion = means) return df -def plot_average_scatter(df): - fig, ax = plt.subplots(figsize=(16, 9)) - x = list(df["losses"]) - y = list(df["mean_steps"]) - ax.scatter(x, y, s=200, c=df.losses, alpha=.5) - ax.set_xlabel("Training Loss") - ax.set_ylabel("Steps Averaged Over Replicates") - ax.spines['top'].set_visible(False) - ax.spines['right'].set_visible(False) - ax.spines['left'].set_visible(False) - ax.spines['bottom'].set_color('#DDDDDD') - ax.set_title("Averaged Steps Taken Over Training Loss per Model") - for i, label in enumerate(list(df['Network'])): - ax.annotate(label, (x[i], y[i])) - return ax \ No newline at end of file +def plot_average_scatter(df): + custom_params = {"axes.spines.right": False, "axes.spines.top": False} + sns.set_theme(context='paper', style='whitegrid', font_scale=1, rc=custom_params) +# matplotlib.rcParams.update({'font.size': 12}) +# sns.set_theme() +# sns.set_context("paper") + fig = plt.gcf() + fig.set_size_inches(12, 9) + sns.scatterplot(data=df, x="losses", y="mean_completion", hue="clean_names", style="clean_names", s=200) + plt.legend(bbox_to_anchor=(1.10, 1), borderaxespad=0) + x = list(df['losses']) + y = list(df['mean_completion']) + for i, label in enumerate(list(df['clean_names'])): + plt.annotate(label, (x[i], y[i])) + return plt + +def clean_maze_name(m): + return m[:-4].capitalize().replace("_", " ") + +def plot_boxplot(df, mazes): + all_data = [] + for m in mazes: + x = list(df[m]) + all_data.append(x) + all_data = pd.DataFrame(all_data).T + all_data.columns = mazes + all_data = pd.DataFrame(all_data.stack()) + all_data.reset_index(level=1, inplace=True) + all_data.columns = ['maze', 'percentage'] + clean_mazes = list(map(clean_maze_name, list(all_data['maze']))) + all_data = all_data.assign(maze=clean_mazes) + + custom_params = {"axes.spines.right": False, "axes.spines.top": False} + sns.set_theme(context='paper', style='whitegrid', font_scale=1, rc=custom_params) + fig = plt.gcf() + fig.set_size_inches(17, 9) + sns.swarmplot(x="maze", y="percentage", data=all_data) + plt.ylim=(0, None) + return plt diff --git a/Mazes/validation_mazes8x8_bricks/maze_05.txt b/Mazes/validation_mazes8x8_bricks/maze_05.txt deleted file mode 100644 index 75b6525..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_05.txt +++ /dev/null @@ -1,48 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 5 -2 0 2 3 2 2 2 0 2 2 2 2 2 2 2 0 2 -2 0 2 0 0 0 3 0 2 0 0 0 0 0 0 0 2 -2 3 2 0 2 0 2 0 2 0 2 2 2 2 2 2 2 -2 0 0 0 4 0 0 0 4 0 0 0 0 0 2 0 2 -2 0 2 2 2 4 2 2 2 2 2 2 2 0 2 0 2 -3 0 0 0 0 0 2 0 2 0 2 0 0 0 2 0 2 -2 2 2 3 2 0 2 0 2 0 2 0 2 2 2 0 2 -2 0 2 0 0 0 4 0 2 0 0 0 2 0 0 0 2 -2 3 2 0 2 2 2 0 2 2 2 2 2 2 2 0 2 -2 0 0 0 4 0 0 0 0 0 2 0 0 0 0 0 2 -2 0 2 4 2 0 2 2 2 0 2 0 2 0 2 0 2 -3 0 0 0 2 0 2 0 2 0 2 0 2 0 2 0 2 -2 2 2 0 2 0 2 0 2 0 2 2 2 0 2 0 2 -2 0 0 0 4 0 2 0 0 0 0 0 0 0 2 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.EAST -3 1 Dir.NORTH -3 3 Dir.WEST -1 3 Dir.NORTH -1 5 Dir.EAST -3 5 Dir.NORTH -3 7 Dir.EAST -5 7 Dir.NORTH -5 9 Dir.WEST -3 9 Dir.WEST -1 9 Dir.NORTH -1 11 Dir.EAST -3 11 Dir.NORTH -3 13 Dir.EAST -5 13 Dir.SOUTH -5 11 Dir.EAST -7 11 Dir.NORTH -7 13 Dir.NORTH -7 15 Dir.EAST -9 15 Dir.EAST -11 15 Dir.EAST -13 15 Dir.EAST -15 15 Dir.EAST diff --git a/Mazes/validation_mazes8x8_bricks/maze_06.txt b/Mazes/validation_mazes8x8_bricks/maze_06.txt deleted file mode 100644 index d594a52..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_06.txt +++ /dev/null @@ -1,48 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 5 -2 0 2 2 2 0 2 0 2 2 2 0 2 0 2 0 2 -2 0 2 0 0 0 0 0 2 0 2 0 0 0 2 0 2 -2 0 2 2 2 2 2 2 2 0 2 3 2 2 2 0 2 -2 0 2 0 0 0 2 0 0 0 2 0 0 0 3 0 2 -2 0 2 2 2 0 2 2 2 0 2 0 2 0 2 0 2 -2 0 0 0 2 0 0 0 2 0 2 0 2 0 0 0 4 -2 0 2 2 2 2 2 0 2 0 2 0 2 4 2 2 2 -2 0 0 0 0 0 0 0 2 0 3 0 0 0 2 0 2 -2 2 2 3 2 2 2 2 2 0 2 2 2 0 2 0 2 -2 0 2 0 0 0 3 0 0 0 0 0 2 0 2 0 2 -2 3 2 0 2 0 2 2 2 2 2 3 2 0 2 0 2 -2 0 0 0 4 0 0 0 0 0 3 0 0 0 4 0 2 -2 0 2 2 2 4 2 2 2 0 2 0 2 2 2 0 2 -2 0 0 0 0 0 0 0 2 0 0 0 4 0 0 0 2 -2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.EAST -3 3 Dir.NORTH -3 5 Dir.EAST -5 5 Dir.SOUTH -5 3 Dir.EAST -7 3 Dir.EAST -9 3 Dir.SOUTH -9 1 Dir.EAST -11 1 Dir.NORTH -11 3 Dir.EAST -13 3 Dir.NORTH -13 5 Dir.NORTH -13 7 Dir.WEST -11 7 Dir.NORTH -11 9 Dir.NORTH -11 11 Dir.EAST -13 11 Dir.SOUTH -13 9 Dir.EAST -15 9 Dir.NORTH -15 11 Dir.NORTH -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_07.txt b/Mazes/validation_mazes8x8_bricks/maze_07.txt deleted file mode 100644 index 3c6c7b1..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_07.txt +++ /dev/null @@ -1,48 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 5 -2 0 2 2 2 2 2 2 2 2 2 2 2 0 2 0 2 -2 0 2 0 2 0 0 0 0 0 2 0 2 0 0 0 2 -2 0 2 0 2 0 2 0 2 0 2 0 2 3 2 0 2 -2 0 2 0 0 0 2 0 2 0 0 0 2 0 0 0 4 -2 0 2 0 2 2 2 0 2 2 2 3 2 0 2 2 2 -2 0 2 0 2 0 2 0 0 0 2 0 0 0 4 0 2 -2 0 2 0 2 0 2 2 2 0 2 0 2 4 2 0 2 -2 0 2 0 0 0 2 0 0 0 3 0 0 0 2 0 2 -2 0 2 2 2 2 2 0 2 3 2 2 2 0 2 4 2 -2 0 0 0 2 0 0 0 2 0 0 0 3 0 0 0 2 -2 2 2 0 2 3 2 2 2 0 2 0 2 2 2 0 2 -2 0 0 0 2 0 0 0 0 0 4 0 0 0 3 0 2 -2 2 2 2 2 0 2 2 2 2 2 4 2 0 2 0 2 -2 0 0 0 0 0 4 0 0 0 0 0 2 0 0 0 4 -2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 -1 1 Dir.EAST -3 1 Dir.EAST -5 1 Dir.NORTH -5 3 Dir.EAST -7 3 Dir.EAST -9 3 Dir.NORTH -9 5 Dir.EAST -11 5 Dir.SOUTH -11 3 Dir.EAST -13 3 Dir.SOUTH -13 1 Dir.EAST -15 1 Dir.NORTH -15 3 Dir.NORTH -15 5 Dir.WEST -13 5 Dir.NORTH -13 7 Dir.WEST -11 7 Dir.NORTH -11 9 Dir.EAST -13 9 Dir.NORTH -13 11 Dir.EAST -15 11 Dir.NORTH -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_08.txt b/Mazes/validation_mazes8x8_bricks/maze_08.txt deleted file mode 100644 index faf05e7..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_08.txt +++ /dev/null @@ -1,48 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 3 2 2 2 2 2 2 2 2 2 3 2 2 2 5 2 -2 0 0 0 0 0 0 0 3 0 0 0 0 0 3 0 5 -2 0 2 4 2 2 2 0 2 2 2 0 2 0 2 0 2 -3 0 0 0 2 0 0 0 0 0 3 0 2 0 0 0 4 -2 3 2 0 2 2 2 4 2 0 2 0 2 4 2 2 2 -2 0 0 0 4 0 0 0 2 0 0 0 4 0 0 0 2 -2 0 2 2 2 0 2 0 2 4 2 2 2 2 2 0 2 -2 0 2 0 0 0 2 0 0 0 0 0 2 0 0 0 2 -2 0 2 0 2 2 2 2 2 2 2 0 2 0 2 2 2 -2 0 2 0 2 0 0 0 0 0 2 0 0 0 2 0 2 -2 0 2 0 2 2 2 0 2 2 2 2 2 2 2 0 2 -2 0 2 0 0 0 2 0 0 0 0 0 0 0 0 0 2 -2 0 2 2 2 0 2 0 2 2 2 0 2 2 2 0 2 -2 0 0 0 2 0 2 0 2 0 0 0 2 0 0 0 2 -2 0 2 2 2 0 2 2 2 0 2 2 2 0 2 2 2 -2 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.NORTH -1 5 Dir.NORTH -1 7 Dir.NORTH -1 9 Dir.NORTH -1 11 Dir.EAST -3 11 Dir.NORTH -3 13 Dir.WEST -1 13 Dir.NORTH -1 15 Dir.EAST -3 15 Dir.EAST -5 15 Dir.EAST -7 15 Dir.SOUTH -7 13 Dir.EAST -9 13 Dir.SOUTH -9 11 Dir.EAST -11 11 Dir.NORTH -11 13 Dir.NORTH -11 15 Dir.EAST -13 15 Dir.SOUTH -13 13 Dir.EAST -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_09.txt b/Mazes/validation_mazes8x8_bricks/maze_09.txt deleted file mode 100644 index df4e5e7..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_09.txt +++ /dev/null @@ -1,52 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 5 -2 0 2 0 2 2 2 4 2 2 2 0 2 2 2 0 2 -2 0 3 0 0 0 0 0 2 0 2 0 0 0 0 0 4 -2 0 2 3 2 2 2 0 2 0 2 4 2 2 2 0 2 -2 0 2 0 0 0 3 0 2 0 0 0 2 0 2 0 2 -2 0 2 0 2 0 2 0 2 4 2 0 2 0 2 0 2 -2 0 2 0 2 0 3 0 0 0 2 0 2 0 2 0 2 -2 3 2 0 2 0 2 2 2 0 2 0 2 0 2 2 2 -2 0 0 0 4 0 0 0 0 0 4 0 2 0 0 0 2 -2 0 2 0 2 4 2 2 2 0 2 2 2 2 2 0 2 -2 0 2 0 2 0 0 0 2 0 2 0 0 0 2 0 2 -2 0 2 0 2 0 2 0 2 2 2 0 2 0 2 0 2 -2 0 2 0 2 0 2 0 0 0 0 0 2 0 0 0 2 -2 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.NORTH -1 5 Dir.NORTH -1 7 Dir.EAST -3 7 Dir.NORTH -3 9 Dir.NORTH -3 11 Dir.EAST -5 11 Dir.SOUTH -5 9 Dir.SOUTH -5 7 Dir.EAST -7 7 Dir.EAST -9 7 Dir.NORTH -9 9 Dir.WEST -7 9 Dir.NORTH -7 11 Dir.NORTH -7 13 Dir.WEST -5 13 Dir.WEST -3 13 Dir.NORTH -3 15 Dir.EAST -5 15 Dir.EAST -7 15 Dir.EAST -9 15 Dir.EAST -11 15 Dir.SOUTH -11 13 Dir.EAST -13 13 Dir.EAST -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_10.txt b/Mazes/validation_mazes8x8_bricks/maze_10.txt deleted file mode 100644 index 842978f..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_10.txt +++ /dev/null @@ -1,58 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 5 -2 0 2 2 2 2 2 0 2 2 2 2 2 0 2 0 2 -2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 2 -2 3 2 2 2 0 2 2 2 2 2 2 2 2 2 0 2 -2 0 0 0 0 0 0 0 0 0 3 0 0 0 2 0 2 -2 0 2 4 2 2 2 2 2 0 2 2 2 0 2 0 2 -3 0 0 0 0 0 4 0 0 0 2 0 0 0 2 0 2 -2 2 2 0 2 2 2 0 2 3 2 2 2 0 2 0 2 -2 0 2 0 4 0 0 0 2 0 0 0 3 0 2 0 2 -2 3 2 0 2 0 2 3 2 0 2 0 2 2 2 0 2 -2 0 0 0 4 0 0 0 0 0 4 0 0 0 0 0 4 -2 0 2 2 2 4 2 2 2 2 2 4 2 2 2 2 2 -3 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 2 -2 2 2 2 2 0 2 0 2 2 2 2 2 2 2 0 2 -2 0 0 0 0 0 4 0 2 0 0 0 0 0 0 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.EAST -3 1 Dir.EAST -5 1 Dir.NORTH -5 3 Dir.WEST -3 3 Dir.WEST -1 3 Dir.NORTH -1 5 Dir.EAST -3 5 Dir.NORTH -3 7 Dir.NORTH -3 9 Dir.WEST -1 9 Dir.NORTH -1 11 Dir.EAST -3 11 Dir.EAST -5 11 Dir.EAST -7 11 Dir.EAST -9 11 Dir.SOUTH -9 9 Dir.WEST -7 9 Dir.SOUTH -7 7 Dir.WEST -5 7 Dir.SOUTH -5 5 Dir.EAST -7 5 Dir.EAST -9 5 Dir.NORTH -9 7 Dir.EAST -11 7 Dir.SOUTH -11 5 Dir.EAST -13 5 Dir.EAST -15 5 Dir.NORTH -15 7 Dir.NORTH -15 9 Dir.NORTH -15 11 Dir.NORTH -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_11.txt b/Mazes/validation_mazes8x8_bricks/maze_11.txt deleted file mode 100644 index 08b19fc..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_11.txt +++ /dev/null @@ -1,58 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 5 -2 0 2 2 2 0 2 4 2 2 2 4 2 0 2 0 2 -2 0 0 0 3 0 0 0 4 0 0 0 2 0 0 0 4 -2 2 2 2 2 2 2 0 2 0 2 0 2 4 2 4 2 -2 0 0 0 0 0 3 0 0 0 3 0 0 0 0 0 2 -2 0 2 2 2 0 2 2 2 3 2 0 2 2 2 0 2 -2 0 0 0 2 0 0 0 0 0 2 0 0 0 2 0 2 -2 2 2 0 2 2 2 2 2 0 2 2 2 2 2 0 2 -2 0 0 0 2 0 0 0 2 0 0 0 0 0 2 0 2 -2 0 2 2 2 0 2 3 2 2 2 2 2 0 2 0 2 -2 0 0 0 2 0 2 0 0 0 0 0 3 0 0 0 2 -2 2 2 0 2 3 2 0 2 2 2 0 2 2 2 0 2 -2 0 0 0 2 0 0 0 4 0 2 0 0 0 3 0 2 -2 2 2 2 2 0 2 2 2 0 2 4 2 0 2 0 2 -2 0 0 0 0 0 4 0 0 0 0 0 2 0 0 0 4 -2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 -1 1 Dir.EAST -3 1 Dir.EAST -5 1 Dir.NORTH -5 3 Dir.EAST -7 3 Dir.NORTH -7 5 Dir.EAST -9 5 Dir.EAST -11 5 Dir.SOUTH -11 3 Dir.EAST -13 3 Dir.SOUTH -13 1 Dir.EAST -15 1 Dir.NORTH -15 3 Dir.NORTH -15 5 Dir.NORTH -15 7 Dir.NORTH -15 9 Dir.NORTH -15 11 Dir.WEST -13 11 Dir.WEST -11 11 Dir.NORTH -11 13 Dir.WEST -9 13 Dir.SOUTH -9 11 Dir.WEST -7 11 Dir.NORTH -7 13 Dir.WEST -5 13 Dir.NORTH -5 15 Dir.EAST -7 15 Dir.EAST -9 15 Dir.EAST -11 15 Dir.EAST -13 15 Dir.SOUTH -13 13 Dir.EAST -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_12.txt b/Mazes/validation_mazes8x8_bricks/maze_12.txt deleted file mode 100644 index 291bcc8..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_12.txt +++ /dev/null @@ -1,64 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 3 2 2 2 2 2 2 2 2 2 2 2 3 2 5 2 -2 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 5 -2 0 2 2 2 4 2 2 2 2 2 0 2 0 2 4 2 -3 0 0 0 0 0 2 0 0 0 2 0 3 0 0 0 2 -2 0 2 3 2 0 2 0 2 4 2 0 2 3 2 0 2 -2 0 2 0 0 0 4 0 0 0 2 0 2 0 0 0 4 -2 3 2 0 2 2 2 0 2 0 2 0 2 0 2 0 2 -2 0 0 0 4 0 0 0 3 0 0 0 2 0 2 0 2 -2 0 2 2 2 2 2 0 2 2 2 3 2 0 2 4 2 -2 0 0 0 0 0 2 0 0 0 3 0 3 0 0 0 2 -2 0 2 2 2 0 2 4 2 0 2 2 2 2 2 0 2 -2 0 2 0 0 0 2 0 0 0 0 0 0 0 0 0 4 -2 0 2 0 2 2 2 2 2 4 2 2 2 2 2 0 2 -2 0 2 0 2 0 0 0 0 0 0 0 2 0 2 0 2 -2 0 2 0 2 0 2 2 2 2 2 2 2 0 2 0 2 -2 0 2 0 0 0 2 0 0 0 0 0 0 0 0 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.NORTH -1 5 Dir.NORTH -1 7 Dir.NORTH -1 9 Dir.EAST -3 9 Dir.NORTH -3 11 Dir.EAST -5 11 Dir.NORTH -5 13 Dir.WEST -3 13 Dir.WEST -1 13 Dir.NORTH -1 15 Dir.EAST -3 15 Dir.EAST -5 15 Dir.EAST -7 15 Dir.EAST -9 15 Dir.EAST -11 15 Dir.SOUTH -11 13 Dir.SOUTH -11 11 Dir.SOUTH -11 9 Dir.WEST -9 9 Dir.NORTH -9 11 Dir.WEST -7 11 Dir.SOUTH -7 9 Dir.SOUTH -7 7 Dir.EAST -9 7 Dir.SOUTH -9 5 Dir.EAST -11 5 Dir.EAST -13 5 Dir.EAST -15 5 Dir.NORTH -15 7 Dir.WEST -13 7 Dir.NORTH -13 9 Dir.NORTH -13 11 Dir.EAST -15 11 Dir.NORTH -15 13 Dir.WEST -13 13 Dir.NORTH -13 15 Dir.EAST -15 15 Dir.EAST diff --git a/Mazes/validation_mazes8x8_bricks/maze_13.txt b/Mazes/validation_mazes8x8_bricks/maze_13.txt deleted file mode 100644 index 2e022e8..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_13.txt +++ /dev/null @@ -1,50 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 5 2 -2 0 0 0 0 0 2 0 0 0 3 0 0 0 0 0 5 -2 2 2 0 2 0 2 0 2 0 2 0 2 2 2 0 2 -2 0 0 0 2 0 2 0 2 0 0 0 4 0 2 0 2 -2 3 2 2 2 2 2 0 2 4 2 2 2 0 2 0 2 -2 0 0 0 0 0 0 0 4 0 0 0 0 0 2 0 2 -2 0 2 2 2 2 2 4 2 2 2 2 2 0 2 0 2 -2 0 4 0 0 0 0 0 2 0 0 0 0 0 2 0 2 -2 0 2 0 2 3 2 0 2 0 2 2 2 2 2 0 2 -3 0 0 0 2 0 0 0 4 0 2 0 0 0 2 0 2 -2 3 2 3 2 0 2 2 2 2 2 0 2 0 2 0 2 -2 0 0 0 0 0 4 0 0 0 0 0 2 0 0 0 2 -2 0 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 -2 0 2 0 0 0 0 0 2 0 0 0 0 0 0 0 2 -2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.NORTH -1 5 Dir.EAST -3 5 Dir.EAST -5 5 Dir.NORTH -5 7 Dir.EAST -7 7 Dir.NORTH -7 9 Dir.WEST -5 9 Dir.WEST -3 9 Dir.SOUTH -3 7 Dir.WEST -1 7 Dir.NORTH -1 9 Dir.NORTH -1 11 Dir.EAST -3 11 Dir.EAST -5 11 Dir.EAST -7 11 Dir.NORTH -7 13 Dir.NORTH -7 15 Dir.EAST -9 15 Dir.SOUTH -9 13 Dir.EAST -11 13 Dir.NORTH -11 15 Dir.EAST -13 15 Dir.EAST -15 15 Dir.EAST diff --git a/Mazes/validation_mazes8x8_bricks/maze_14.txt b/Mazes/validation_mazes8x8_bricks/maze_14.txt deleted file mode 100644 index a80c450..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_14.txt +++ /dev/null @@ -1,46 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 5 -2 0 2 0 2 4 2 2 2 2 2 0 2 2 2 0 2 -2 0 3 0 0 0 2 0 0 0 0 0 0 0 0 0 4 -2 0 2 3 2 0 2 0 2 2 2 4 2 2 2 0 2 -2 0 2 0 0 0 4 0 0 0 2 0 0 0 2 0 2 -2 0 2 0 2 2 2 2 2 2 2 2 2 0 2 2 2 -2 0 2 0 2 0 0 0 2 0 0 0 2 0 0 0 2 -2 3 2 0 2 0 2 0 2 0 2 0 2 2 2 0 2 -2 0 0 0 4 0 2 0 0 0 2 0 2 0 0 0 2 -2 0 2 4 2 0 2 2 2 2 2 0 2 0 2 2 2 -3 0 0 0 2 0 0 0 0 0 2 0 2 0 2 0 2 -2 3 2 0 2 0 2 2 2 2 2 0 2 0 2 0 2 -2 0 0 0 4 0 2 0 0 0 0 0 2 0 0 0 2 -2 0 2 2 2 0 2 0 2 2 2 2 2 2 2 0 2 -2 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.EAST -3 3 Dir.NORTH -3 5 Dir.WEST -1 5 Dir.NORTH -1 7 Dir.EAST -3 7 Dir.NORTH -3 9 Dir.NORTH -3 11 Dir.EAST -5 11 Dir.NORTH -5 13 Dir.WEST -3 13 Dir.NORTH -3 15 Dir.EAST -5 15 Dir.EAST -7 15 Dir.EAST -9 15 Dir.EAST -11 15 Dir.SOUTH -11 13 Dir.EAST -13 13 Dir.EAST -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_15.txt b/Mazes/validation_mazes8x8_bricks/maze_15.txt deleted file mode 100644 index 92084df..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_15.txt +++ /dev/null @@ -1,50 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 5 2 -2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 5 -2 0 2 2 2 2 2 2 2 0 2 0 2 4 2 0 2 -2 0 0 0 0 0 2 0 0 0 3 0 0 0 2 0 2 -2 2 2 2 2 0 2 0 2 2 2 2 2 0 2 0 2 -2 0 0 0 0 0 2 0 0 0 2 0 2 0 2 0 2 -2 0 2 2 2 2 2 2 2 0 2 0 2 0 2 4 2 -2 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 2 -2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 0 2 -2 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 2 -2 0 2 3 2 2 2 2 2 2 2 2 2 3 2 0 2 -2 0 2 0 0 0 0 0 3 0 2 0 2 0 0 0 4 -2 3 2 0 2 2 2 0 2 0 2 0 2 0 2 2 2 -2 0 0 0 4 0 0 0 2 0 0 0 2 0 2 0 2 -2 0 2 2 2 0 2 3 2 2 2 2 2 0 2 0 2 -2 0 0 0 2 0 0 0 0 0 0 0 0 0 4 0 2 -2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.EAST -3 3 Dir.NORTH -3 5 Dir.EAST -5 5 Dir.EAST -7 5 Dir.SOUTH -7 3 Dir.WEST -5 3 Dir.SOUTH -5 1 Dir.EAST -7 1 Dir.EAST -9 1 Dir.EAST -11 1 Dir.EAST -13 1 Dir.NORTH -13 3 Dir.NORTH -13 5 Dir.EAST -15 5 Dir.NORTH -15 7 Dir.NORTH -15 9 Dir.WEST -13 9 Dir.NORTH -13 11 Dir.NORTH -13 13 Dir.WEST -11 13 Dir.NORTH -11 15 Dir.EAST -13 15 Dir.EAST -15 15 Dir.EAST diff --git a/Mazes/validation_mazes8x8_bricks/maze_16.txt b/Mazes/validation_mazes8x8_bricks/maze_16.txt deleted file mode 100644 index a68b794..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_16.txt +++ /dev/null @@ -1,60 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 5 -2 0 2 4 2 2 2 0 2 2 2 2 2 2 2 0 2 -3 0 0 0 2 0 0 0 0 0 0 0 0 0 3 0 2 -2 0 2 0 2 2 2 4 2 2 2 2 2 0 2 0 2 -2 0 3 0 0 0 0 0 2 0 0 0 2 0 2 0 2 -2 0 2 2 2 2 2 0 2 0 2 0 2 0 2 0 2 -2 0 0 0 0 0 2 0 2 0 2 0 2 0 0 0 4 -2 2 2 2 2 2 2 0 2 4 2 0 2 4 2 0 2 -2 0 0 0 0 0 3 0 0 0 2 0 0 0 2 0 2 -2 0 2 2 2 0 2 3 2 0 2 0 2 2 2 0 2 -2 0 2 0 2 0 2 0 0 0 4 0 0 0 0 0 2 -2 3 2 0 2 0 2 0 2 2 2 4 2 0 2 2 2 -2 0 0 0 3 0 3 0 0 0 0 0 2 0 2 0 2 -2 0 2 0 2 0 2 2 2 2 2 0 2 0 2 0 2 -2 0 2 0 0 0 0 0 0 0 0 0 4 0 0 0 2 -2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.EAST -3 3 Dir.SOUTH -3 1 Dir.EAST -5 1 Dir.EAST -7 1 Dir.EAST -9 1 Dir.EAST -11 1 Dir.NORTH -11 3 Dir.WEST -9 3 Dir.WEST -7 3 Dir.NORTH -7 5 Dir.EAST -9 5 Dir.NORTH -9 7 Dir.WEST -7 7 Dir.NORTH -7 9 Dir.NORTH -7 11 Dir.WEST -5 11 Dir.WEST -3 11 Dir.NORTH -3 13 Dir.WEST -1 13 Dir.NORTH -1 15 Dir.EAST -3 15 Dir.EAST -5 15 Dir.EAST -7 15 Dir.SOUTH -7 13 Dir.EAST -9 13 Dir.EAST -11 13 Dir.EAST -13 13 Dir.SOUTH -13 11 Dir.SOUTH -13 9 Dir.EAST -15 9 Dir.NORTH -15 11 Dir.NORTH -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_17.txt b/Mazes/validation_mazes8x8_bricks/maze_17.txt deleted file mode 100644 index b4f3275..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_17.txt +++ /dev/null @@ -1,54 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 5 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 -2 0 2 2 2 2 2 0 2 4 2 2 2 2 2 0 2 -2 0 0 0 0 0 3 0 0 0 2 0 0 0 0 0 2 -2 2 2 0 2 2 2 2 2 0 2 2 2 2 2 4 2 -2 0 2 0 2 0 0 0 2 0 4 0 0 0 0 0 2 -2 0 2 2 2 0 2 0 2 0 2 0 2 2 2 0 2 -2 0 2 0 0 0 2 0 3 0 0 0 2 0 2 0 2 -2 0 2 0 2 2 2 0 2 0 2 3 2 0 2 0 2 -2 0 0 0 2 0 2 0 2 0 2 0 0 0 2 0 2 -2 2 2 2 2 0 2 0 2 0 2 0 2 0 2 0 2 -2 0 0 0 0 0 0 0 2 0 0 0 2 0 2 0 2 -2 0 2 3 2 2 2 3 2 2 2 2 2 2 2 0 2 -2 0 2 0 0 0 3 0 0 0 0 0 0 0 3 0 2 -2 0 2 0 2 0 2 0 2 2 2 2 2 0 2 0 2 -2 0 0 0 4 0 0 0 4 0 0 0 0 0 0 0 4 -2 2 2 2 2 4 2 2 2 2 2 2 2 4 2 2 2 -1 1 Dir.EAST -3 1 Dir.NORTH -3 3 Dir.EAST -5 3 Dir.SOUTH -5 1 Dir.EAST -7 1 Dir.NORTH -7 3 Dir.EAST -9 3 Dir.EAST -11 3 Dir.EAST -13 3 Dir.SOUTH -13 1 Dir.EAST -15 1 Dir.NORTH -15 3 Dir.NORTH -15 5 Dir.NORTH -15 7 Dir.NORTH -15 9 Dir.NORTH -15 11 Dir.WEST -13 11 Dir.WEST -11 11 Dir.SOUTH -11 9 Dir.WEST -9 9 Dir.NORTH -9 11 Dir.NORTH -9 13 Dir.WEST -7 13 Dir.NORTH -7 15 Dir.EAST -9 15 Dir.EAST -11 15 Dir.EAST -13 15 Dir.EAST -15 15 Dir.EAST diff --git a/Mazes/validation_mazes8x8_bricks/maze_18.txt b/Mazes/validation_mazes8x8_bricks/maze_18.txt deleted file mode 100644 index 2536d74..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_18.txt +++ /dev/null @@ -1,46 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 0 0 2 0 0 0 0 0 0 0 0 0 2 0 5 -2 2 2 0 2 0 2 2 2 2 2 0 2 3 2 0 2 -2 0 0 0 2 0 2 0 0 0 2 0 2 0 0 0 4 -2 0 2 2 2 0 2 0 2 2 2 0 2 0 2 4 2 -2 0 0 0 0 0 2 0 2 0 0 0 3 0 0 0 2 -2 0 2 2 2 2 2 0 2 0 2 3 2 2 2 0 2 -2 0 0 0 0 0 0 0 2 0 2 0 0 0 0 0 4 -2 2 2 2 2 2 2 2 2 0 2 0 2 2 2 4 2 -2 0 0 0 0 0 2 0 0 0 3 0 0 0 0 0 2 -2 0 2 2 2 0 2 0 2 0 2 2 2 3 2 0 2 -2 0 0 0 2 0 2 0 2 0 0 0 2 0 0 0 4 -2 2 2 0 2 0 2 0 2 2 2 0 2 0 2 2 2 -2 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 2 -2 0 2 2 2 2 2 2 2 2 2 2 2 0 2 0 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.EAST -3 1 Dir.EAST -5 1 Dir.EAST -7 1 Dir.EAST -9 1 Dir.EAST -11 1 Dir.EAST -13 1 Dir.NORTH -13 3 Dir.NORTH -13 5 Dir.EAST -15 5 Dir.NORTH -15 7 Dir.WEST -13 7 Dir.WEST -11 7 Dir.NORTH -11 9 Dir.EAST -13 9 Dir.EAST -15 9 Dir.NORTH -15 11 Dir.WEST -13 11 Dir.NORTH -13 13 Dir.EAST -15 13 Dir.NORTH -15 15 Dir.NORTH diff --git a/Mazes/validation_mazes8x8_bricks/maze_19.txt b/Mazes/validation_mazes8x8_bricks/maze_19.txt deleted file mode 100644 index 050b17d..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_19.txt +++ /dev/null @@ -1,46 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 3 2 2 2 2 2 2 2 3 2 2 2 5 2 -2 0 2 0 0 0 0 0 0 0 3 0 0 0 0 0 5 -2 0 2 0 2 2 2 4 2 0 2 0 2 2 2 2 2 -2 0 3 0 0 0 0 0 2 0 0 0 4 0 0 0 2 -2 0 2 2 2 3 2 0 2 4 2 2 2 0 2 0 2 -2 0 0 0 2 0 0 0 4 0 0 0 2 0 2 0 2 -2 0 2 0 2 0 2 2 2 0 2 0 2 0 2 0 2 -2 0 2 0 2 0 2 0 0 0 2 0 0 0 2 0 2 -2 0 2 3 2 0 2 0 2 2 2 2 2 2 2 0 2 -2 0 2 0 0 0 4 0 0 0 0 0 0 0 2 0 2 -2 3 2 0 2 2 2 2 2 2 2 2 2 2 2 0 2 -2 0 0 0 4 0 0 0 0 0 2 0 0 0 0 0 2 -2 0 2 2 2 0 2 2 2 0 2 0 2 2 2 0 2 -2 0 2 0 0 0 0 0 2 0 2 0 0 0 2 0 2 -2 0 2 2 2 2 2 0 2 0 2 2 2 0 2 0 2 -2 0 0 0 0 0 0 0 2 0 0 0 0 0 2 0 2 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 1 Dir.NORTH -1 3 Dir.NORTH -1 5 Dir.EAST -3 5 Dir.NORTH -3 7 Dir.EAST -5 7 Dir.NORTH -5 9 Dir.NORTH -5 11 Dir.EAST -7 11 Dir.NORTH -7 13 Dir.WEST -5 13 Dir.WEST -3 13 Dir.NORTH -3 15 Dir.EAST -5 15 Dir.EAST -7 15 Dir.EAST -9 15 Dir.SOUTH -9 13 Dir.EAST -11 13 Dir.NORTH -11 15 Dir.EAST -13 15 Dir.EAST -15 15 Dir.EAST diff --git a/Mazes/validation_mazes8x8_bricks/maze_20.txt b/Mazes/validation_mazes8x8_bricks/maze_20.txt deleted file mode 100644 index 002e7bb..0000000 --- a/Mazes/validation_mazes8x8_bricks/maze_20.txt +++ /dev/null @@ -1,54 +0,0 @@ -6 -../Textures/Tiles074_2K_Color1024.png -../Textures/Plaster001_2K_Color1024.png -../Textures/Bricks051_2K_Color1024.png -../Textures/arrow-right-bricks-long.png -../Textures/arrow-left-bricks-long.png -../Textures/goal.png -17 17 -2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 2 -2 0 2 0 0 0 0 0 0 0 0 0 0 0 2 0 5 -2 0 2 0 2 2 2 2 2 2 2 0 2 0 2 0 2 -2 0 0 0 2 0 0 0 0 0 0 0 2 0 2 0 2 -2 2 2 2 2 0 2 2 2 2 2 2 2 0 2 0 2 -2 0 0 0 0 0 2 0 2 0 0 0 0 0 2 0 2 -2 2 2 3 2 2 2 0 2 0 2 2 2 2 2 0 2 -2 0 2 0 0 0 0 0 3 0 2 0 0 0 0 0 2 -2 0 2 0 2 2 2 0 2 0 2 2 2 0 2 0 2 -2 0 2 0 4 0 0 0 2 0 0 0 0 0 2 0 2 -2 0 2 0 2 0 2 3 2 2 2 2 2 3 2 0 2 -2 0 2 0 2 0 0 0 0 0 0 0 3 0 0 0 4 -2 0 2 0 2 4 2 2 2 2 2 0 2 0 2 4 2 -2 0 3 0 0 0 2 0 0 0 2 0 3 0 0 0 2 -2 0 2 2 2 0 2 2 2 0 2 0 2 2 2 0 2 -2 0 0 0 0 0 4 0 0 0 2 0 0 0 0 0 4 -2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 -1 1 Dir.EAST -3 1 Dir.EAST -5 1 Dir.NORTH -5 3 Dir.WEST -3 3 Dir.NORTH -3 5 Dir.NORTH -3 7 Dir.NORTH -3 9 Dir.EAST -5 9 Dir.EAST -7 9 Dir.SOUTH -7 7 Dir.WEST -5 7 Dir.SOUTH -5 5 Dir.EAST -7 5 Dir.EAST -9 5 Dir.EAST -11 5 Dir.SOUTH -11 3 Dir.SOUTH -11 1 Dir.EAST -13 1 Dir.EAST -15 1 Dir.NORTH -15 3 Dir.WEST -13 3 Dir.NORTH -13 5 Dir.EAST -15 5 Dir.NORTH -15 7 Dir.NORTH -15 9 Dir.NORTH -15 11 Dir.NORTH -15 13 Dir.NORTH -15 15 Dir.NORTH From ed9b92143d3eb1c5a25900419ead517f93f8c315 Mon Sep 17 00:00:00 2001 From: Christy-Marchese Date: Sat, 9 Oct 2021 18:48:01 -0700 Subject: [PATCH 5/5] updating imitator --- Experiments/TrainPaneledClassification.py | 10 +++++----- Experiments/TrainStackedClassification.py | 10 +++++----- Imitator/ImitateWrapper.py | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Experiments/TrainPaneledClassification.py b/Experiments/TrainPaneledClassification.py index e8d09e7..a1d3115 100644 --- a/Experiments/TrainPaneledClassification.py +++ b/Experiments/TrainPaneledClassification.py @@ -32,8 +32,8 @@ NUM_REPLICATES = 4 NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") -MODEL_PATH_REL_TO_DATASET = Path("paneled_models1") -DATA_PATH_REL_TO_DATASET = Path("paneled_data1") +MODEL_PATH_REL_TO_DATASET = Path("paneled_models2") +DATA_PATH_REL_TO_DATASET = Path("paneled_data2") VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { @@ -78,8 +78,8 @@ def get_fig_filename(prefix: str, label: str, ext: str, rep: int) -> str: return fig_filename -def filename_to_class(filename: str) -> str: - angle = float(filename.split("_")[1].split(".")[0].replace("p", ".")) +def filename_to_class(filename) -> str: + angle = float(str(filename).split("_")[1].split(".")[0].replace("p", ".")) if angle > 0: return "left" elif angle < 0: @@ -96,7 +96,7 @@ def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: blocks=(ImageBlock, CategoryBlock), get_items=get_image_files, splitter=RandomSplitter(valid_pct=VALID_PCT), - get_y=lambda x: filename_to_class(str(x)), + get_y=filename_to_class, get_x=get_pair ) diff --git a/Experiments/TrainStackedClassification.py b/Experiments/TrainStackedClassification.py index dd56e4c..14a0c11 100644 --- a/Experiments/TrainStackedClassification.py +++ b/Experiments/TrainStackedClassification.py @@ -32,8 +32,8 @@ NUM_REPLICATES = 4 NUM_EPOCHS = 8 DATASET_DIR = Path("/raid/clark/summer2021/datasets") -MODEL_PATH_REL_TO_DATASET = Path("stacked_models1") -DATA_PATH_REL_TO_DATASET = Path("stacked_data1") +MODEL_PATH_REL_TO_DATASET = Path("stacked_models2") +DATA_PATH_REL_TO_DATASET = Path("stacked_data2") VALID_MAZE_DIR = Path("../Mazes/validation_mazes8x8/") compared_models = { @@ -74,8 +74,8 @@ def get_fig_filename(prefix: str, label: str, ext: str, rep: int) -> str: return fig_filename -def filename_to_class(filename: str) -> str: - angle = float(filename.split("_")[1].split(".")[0].replace("p", ".")) +def filename_to_class(filename) -> str: + angle = float(str(filename).split("_")[1].split(".")[0].replace("p", ".")) if angle > 0: return "left" elif angle < 0: @@ -92,7 +92,7 @@ def prepare_dataloaders(dataset_name: str, prefix: str) -> DataLoaders: blocks=((ImageBlock, ImageBlock), CategoryBlock), get_items=get_image_files, get_x=get_pair_2, - get_y=lambda x: filename_to_class(str(x)), + get_y=filename_to_class, splitter=RandomSplitter(valid_pct=VALID_PCT) ) diff --git a/Imitator/ImitateWrapper.py b/Imitator/ImitateWrapper.py index 9b92127..9b5d388 100644 --- a/Imitator/ImitateWrapper.py +++ b/Imitator/ImitateWrapper.py @@ -47,12 +47,12 @@ def main(): # device = torch.device('cpu') num_mazes = 20 - model_dir = '/raid/clark/summer2021/datasets/corrected-wander-full/regression_models1' + model_dir = '/raid/clark/summer2021/datasets/corrected-wander-full/stacked_models2' models = os.listdir(model_dir) # models = list(filter(lambda x: "-notpretrained" in x, models)) models.sort() for i, m in enumerate(models): - models[i] = (model_dir + '/' + m, 'c', 'n', 'y') #model type, stacked, regression + models[i] = (model_dir + '/' + m, 'c', 'y', 'n') #model type, stacked, regression maze_dir = "../Mazes/validation_mazes8x8" mazes = os.listdir(maze_dir) @@ -103,8 +103,8 @@ def main(): stepdata = get_df(data, mazes) cdata = get_df(completion_data, mazes) - stepdata.to_csv(dir_name + "/regression_step.csv") # - cdata.to_csv(dir_name + "/regression_percentage.csv") + stepdata.to_csv(dir_name + "/stacked_step.csv") # + cdata.to_csv(dir_name + "/stacked_percentage.csv") clean_names = list(map(get_network_name, model_names)) # stepdata = get_df(data, mazes)