Skip to content

Commit

Permalink
yaml path cli
Browse files Browse the repository at this point in the history
  • Loading branch information
fishingguy456 committed Jun 23, 2022
1 parent 6729aa5 commit 67ef10d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 15 additions & 11 deletions imgtools/autopipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self,
train_size=1.0,
random_state=42,
read_yaml_label_names=False,
ignore_missing_regex=False):
ignore_missing_regex=False,
roi_yaml_path=""):
"""Initialize the pipeline.
Parameters
Expand Down Expand Up @@ -105,15 +106,17 @@ def __init__(self,
self.random_state = random_state
self.label_names = {}
self.ignore_missing_regex = ignore_missing_regex

roi_path = pathlib.Path(self.input_directory, "roi_names.yaml").as_posix()

if os.path.exists(roi_path):
with open(roi_path, "r") as f:
try:
self.label_names = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)

roi_path = pathlib.Path(self.input_directory, "roi_names.yaml").as_posix() if roi_yaml_path == "" else roi_yaml_path
if read_yaml_label_names:
if os.path.exists(roi_yaml_path):
with open(roi_path, "r") as f:
try:
self.label_names = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)
else:
raise FileNotFoundError(f"No file named roi_names.yaml found at {roi_path}. If you did not intend on creating ROI regexes, run the CLI without --read_yaml_label_names")

if not isinstance(self.label_names, dict):
raise ValueError("roi_names.yaml must parse as a dictionary")
Expand Down Expand Up @@ -442,7 +445,8 @@ def main():
train_size=args.train_size,
random_state=args.random_state,
read_yaml_label_names=args.read_yaml_label_names,
ignore_missing_regex=args.ignore_missing_regex)
ignore_missing_regex=args.ignore_missing_regex,
roi_yaml_path=args.roi_yaml_path)

print(f'starting AutoPipeline...')
pipeline.run()
Expand Down
5 changes: 4 additions & 1 deletion imgtools/utils/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def parser():
help="Whether to read the label names from roi_names.yaml in the input directory.")

parser.add_argument("--ignore_missing_regex", default=False, action="store_true",
help="Whether to ignore patients with no ROI regex's that match the given ones. Will throw an error on patients without matches if this is not set.")
help="Whether to ignore patients with no ROI regexes that match the given ones. Will throw an error on patients without matches if this is not set.")

parser.add_argument("--roi_yaml_path", type=str,
help="Path to the YAML file defining ROI regexes")

return parser.parse_known_args()[0]

0 comments on commit 67ef10d

Please sign in to comment.