41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""
|
|
Main function to control the simulator flow by selecting which postprocess function to run.
|
|
|
|
Users should fill in the "post_type" field in the input JSON with the postprocess
|
|
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 "post_type" field in the JSON. The function should be in your app
|
|
folder: app/user_app/my_file.
|
|
|
|
The postprocess function should return anything that the user wishes to use.
|
|
"""
|
|
import importlib
|
|
import sys
|
|
import traceback
|
|
|
|
def postprocess_main(config, pre_data, inf_results):
|
|
"""Main function that calls the appropriate postprocess function.
|
|
|
|
Arguments:
|
|
config: TestConfig class that holds the user's input config and options
|
|
pre_data: Dictionary of values passed from preprocess function
|
|
inf_results: NumPy array resulting from inference
|
|
"""
|
|
if config["post"]["post_bypass"]:
|
|
print("Bypassing postprocess")
|
|
return None
|
|
|
|
try:
|
|
# Get function in python import format (with dots)
|
|
function = config["post"]["post_type"].replace("/", ".")
|
|
module, function_name = function.rsplit(".", 1)
|
|
postprocess = importlib.import_module(module)
|
|
post_func = getattr(postprocess, function_name)
|
|
results = post_func(config, pre_data, inf_results)
|
|
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
|