From feaf96417aa8a0748195381e32885bf96e8f4ea6 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 30 May 2026 15:25:22 +0200 Subject: [PATCH] [faces_sub_image] - add --load_model and --do_train CLI args Reconstruction always runs. Default: load saved weights, skip training. Co-Authored-By: Claude Sonnet 4.6 --- src/tests/test_faces_sub_image.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/tests/test_faces_sub_image.py b/src/tests/test_faces_sub_image.py index e9141f5..fb8348d 100644 --- a/src/tests/test_faces_sub_image.py +++ b/src/tests/test_faces_sub_image.py @@ -146,28 +146,39 @@ def show_image_reconstruction(model: TestModel, img_path: str): if __name__ == '__main__': + from argparse import ArgumentParser + ap = ArgumentParser() + ap.add_argument('--load_model', type=lambda s: s.lower() != 'false', default=True, + help='Load saved model weights (default: true)') + ap.add_argument('--do_train', type=lambda s: s.lower() != 'false', default=False, + help='Train the model (default: false)') + args = ap.parse_args() + prj_name = 'faces_sub_image' work_dir = 'results' model = TestModel(prj_name, work_dir) model.init(0.001) - model.load() - print(f'Loading patches from {N_IMAGES} images...') - train_patches = load_patches(DATA_DIR, N_IMAGES) - print(f'Training on {train_patches.shape[0]} patches ({N_VIS}-dim each)') + if args.load_model: + model.load() - model.train(train_patches) - model.save() + if args.do_train: + print(f'Loading patches from {N_IMAGES} images...') + train_patches = load_patches(DATA_DIR, N_IMAGES) + print(f'Training on {train_patches.shape[0]} patches ({N_VIS}-dim each)') + model.train(train_patches) + model.save() # Show learned weight filters show_filters(model.unit1) # Show patch-level reconstructions on held-out images + print('Loading test patches...') test_patches = load_patches(DATA_DIR, n_images=N_IMAGES + 10) - test_patches = test_patches[train_patches.shape[0]:] # use only unseen patches + test_patches = test_patches[N_IMAGES * 80:] # approximate held-out offset if test_patches.shape[0] < 10: - test_patches = train_patches + test_patches = load_patches(DATA_DIR, n_images=10) show_reconstructions(model, test_patches) # Show full image reconstruction