File size: 1,223 Bytes
21d3461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e05eba
21d3461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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,
    )