import json import os import numpy as np from PIL import Image import app_lib.defaults as defaults from app_lib.test import get_testing_config, test assets_dir = "assets" image_dir = os.path.join(assets_dir, "images") results_dir = os.path.join(assets_dir, "results") os.makedirs(results_dir, exist_ok=True) testing_config = get_testing_config( significance_level=defaults.SIGNIFICANCE_LEVEL_VALUE, tau_max=defaults.TAU_MAX_VALUE, r=defaults.R_VALUE, ) image_presets = json.load(open(os.path.join(assets_dir, "image_presets.json"))) for _image_name, _image_presets in image_presets.items(): _image_name = f"{_image_name}.jpg" _image_path = os.path.join(image_dir, _image_name) _image = Image.open(_image_path) _class_name = _image_presets["class_name"] _concepts = _image_presets["concepts"] _cardinality = defaults.CARDINALITY_VALUE _results = test( testing_config, _image, _class_name, _concepts, _cardinality, defaults.DATASET_NAME, defaults.MODEL_NAME, with_streamlit=False, ) np.save( os.path.join(results_dir, _image_name.split(".")[0]), _results, allow_pickle=True, )