def getArguments(parser): "Provides additional validation of the arguments collected by argparse." args = parser.parse_args() # check mutual exlusive and reaquired arguments if args.lmodel and args.smodel: parser.error('only one of --load-model and --save-model can be supplied, as they decide on whether to apply the application or the training mode') if not args.lmodel and not args.smodel: parser.error('exactly one of --load-model or --save-model has to be supplied') # application mode if args.lmodel: if not os.path.isfile(args.lmodel): parser.error('the supplied model file {} does not exist'.format(args.lmodel)) if not args.simages: parser.error('--save-images must be supplied when running the application mode') # training mode if args.smodel: if not args.landmarkp in ('L2', 'L3', 'L4'): args.landmarkp = sequenceOfIntegersGeAscendingStrict(args.landmarkp) if not 'auto' == args.stdspace: args.stdspace = sequenceOfIntegersGeAscendingStrict(args.stdspace) if not args.force and os.path.isfile(args.smodel): parser.error('the target model file {} already exists'.format(args.smodel)) # others if args.simages: if not os.path.isdir(args.simages): parser.error('--save-images must be a valid directory') if args.masks and len(args.masks) != len(args.images): parser.error('the same number of masks must be passed to --masks as images have been supplied') return args