-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_test.py
More file actions
55 lines (44 loc) · 1.72 KB
/
unit_test.py
File metadata and controls
55 lines (44 loc) · 1.72 KB
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
48
49
50
51
52
53
54
55
import argparse
import sys
from image_classification.inference import (
DEFAULT_IMAGE_SIZE,
load_model,
predict_probability,
probability_to_label,
)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Quick benchmark validation on two images")
parser.add_argument("--indoor", required=True, help="Expected indoor image path")
parser.add_argument("--outdoor", required=True, help="Expected outdoor image path")
parser.add_argument(
"--model-path",
default="./training_1/saved_model",
help="Path to saved model directory/file",
)
parser.add_argument("--threshold", type=float, default=0.5, help="Decision threshold")
parser.add_argument(
"--image-size",
type=int,
nargs=2,
default=list(DEFAULT_IMAGE_SIZE),
metavar=("HEIGHT", "WIDTH"),
help="Input image size used by the model",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
model = load_model(args.model_path)
image_size = tuple(args.image_size)
indoor_prob = predict_probability(model, args.indoor, image_size)
outdoor_prob = predict_probability(model, args.outdoor, image_size)
indoor_pred = probability_to_label(indoor_prob, args.threshold)
outdoor_pred = probability_to_label(outdoor_prob, args.threshold)
print(f"indoor_image_p_outdoor={indoor_prob:.4f} predicted={indoor_pred}")
print(f"outdoor_image_p_outdoor={outdoor_prob:.4f} predicted={outdoor_pred}")
passed = indoor_pred == "indoor" and outdoor_pred == "outdoor"
if not passed:
print("benchmark_result=FAIL")
sys.exit(1)
print("benchmark_result=PASS")
if __name__ == "__main__":
main()