""" Main function to control the simulator flow by selecting which preprocess function to run. Users should fill in the "pre_type" field in the input JSON with the preprocess function that they wish to run. The value in the field should be in a format similar to a Python import. For example, if your function is called "my_func" in the Python file "my_file", you should put "my_file.my_func" in the "pre_type" field in the JSON. The function should be in your app folder: app/user_app/my_file. The preprocess function should return a list of numpy arrays in channel last format (1, h, w, c) and a dictionary of values to pass to the postprocess. """ import importlib import sys import traceback import python_flow.common.directory_manager as dm def preprocess_main(config, prev_output=None): """Main function that calls the appropriate preprocess function. Arguments: config: TestConfig class that holds the user's input config and options prev_output: Output passed in from a previous stage needed for this preprocess """ if config["pre"]["pre_bypass"]: print("Bypassing preprocess") return None, None try: # Get function in python import format (with dots) function = config["pre"]["pre_type"].replace("/", ".") module, function_name = function.rsplit(".", 1) preprocess = importlib.import_module(module) pre_func = getattr(preprocess, function_name) with dm.DirectoryManager("bin"): results = pre_func(config, prev_output) except (ModuleNotFoundError, AttributeError) as error: traceback.print_exc() sys.exit(f"\n{error}. Please check {function} in your input JSON " f"{config['flow']['input_json']}.") return results