Skip to content

Commit 52664f5

Browse files
author
Corey Adams
committed
Added a check on the aux file such that if it is not a real file, it is set to None and doesn't get used. This protects against an incorrect default argument.
1 parent 2bac59b commit 52664f5

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

bin/exec.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def add_core_configuration(self, parser):
358358

359359
return parser
360360

361+
361362
def add_io_arguments(self, parser):
362363

363364
# data_directory = "/lus/theta-fs0/projects/datascience/cadams/datasets/SBND/H5/cosmic_tagging/"
@@ -370,6 +371,12 @@ def add_io_arguments(self, parser):
370371
default = data_directory + "cosmic_tagging_train.h5",
371372
help = "IO Input File")
372373

374+
parser.add_argument('--aux-file',
375+
type = str,
376+
default = data_directory + "cosmic_tagging_test.h5",
377+
help = "IO Aux Input File, or output file in inference mode")
378+
379+
373380
parser.add_argument('--start-index',
374381
type = int,
375382
default = 0,
@@ -380,14 +387,6 @@ def add_io_arguments(self, parser):
380387
default = 2,
381388
help = "Number of images in the minibatch size")
382389

383-
# IO PARAMETERS FOR AUX INPUT:
384-
parser.add_argument('--aux-file',
385-
type = str,
386-
# default = None,
387-
default = data_directory + "cosmic_tagging_test.h5",
388-
help = "IO Aux Input File, or output file in inference mode")
389-
390-
391390
parser.add_argument('--aux-iteration',
392391
type = int,
393392
default = 10,

src/utils/core/trainercore.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,23 @@ def _initialize_io(self, color=None):
5858

5959
if self.args.mode == "build_net": return
6060

61+
# Check that the training file exists:
62+
if not os.path.isfile(self.args.file):
63+
raise Exception(f"Can not continue with file {self.args.file} - does not exist.")
64+
if not os.path.isfile(self.args.aux_file):
65+
if self.args.mode == "train":
66+
self.print("WARNING: Aux file does not exist. Setting to None for training")
67+
self.args.aux_file = None
68+
else:
69+
raise Exception("Writing of output currently not supported but will be soon.")
70+
6171
self._train_data_size = self.larcv_fetcher.prepare_cosmic_sample(
6272
"train", self.args.file, self.args.minibatch_size, color)
6373

6474
if self.args.aux_file is not None:
6575
# Check if the file exists:
66-
if os.path.isfile(self.args.aux_file):
67-
self._aux_data_size = self.larcv_fetcher.prepare_cosmic_sample(
68-
"aux", self.args.aux_file, self.args.minibatch_size, color)
76+
self._aux_data_size = self.larcv_fetcher.prepare_cosmic_sample(
77+
"aux", self.args.aux_file, self.args.minibatch_size, color)
6978

7079
def build_lr_schedule(self, learning_rate_schedule = None):
7180
# Define the learning rate sequence:

0 commit comments

Comments
 (0)