forked from fcakyon/small-object-detection-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict_evaluate_analyse.py
123 lines (114 loc) · 3.38 KB
/
predict_evaluate_analyse.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from pathlib import Path
from sahi.predict import predict
from sahi.scripts.coco_error_analysis import analyse
from sahi.scripts.coco_evaluation import evaluate
MODEL_PATH = ""
MODEL_CONFIG_PATH = ""
EVAL_IMAGES_FOLDER_DIR = ""
EVAL_DATASET_JSON_PATH = ""
INFERENCE_SETTING = "XVIEW_SAHI_FI_PO"
EXPORT_VISUAL = False
############ dont change below #############
INFERENCE_SETTING_TO_PARAMS = {
"XVIEW_SAHI": {
"no_standard_prediction": True,
"no_sliced_prediction": False,
"slice_size": 400,
"overlap_ratio": 0,
},
"XVIEW_SAHI_PO": {
"no_standard_prediction": True,
"no_sliced_prediction": False,
"slice_size": 400,
"overlap_ratio": 0.25,
},
"XVIEW_SAHI_FI": {
"no_standard_prediction": False,
"no_sliced_prediction": False,
"slice_size": 400,
"overlap_ratio": 0,
},
"XVIEW_SAHI_FI_PO": {
"no_standard_prediction": False,
"no_sliced_prediction": False,
"slice_size": 400,
"overlap_ratio": 0.25,
},
"VISDRONE_FI": {
"no_standard_prediction": False,
"no_sliced_prediction": True,
"slice_size": 640,
"overlap_ratio": 0,
},
"VISDRONE_SAHI": {
"no_standard_prediction": True,
"no_sliced_prediction": False,
"slice_size": 640,
"overlap_ratio": 0,
},
"VISDRONE_SAHI_PO": {
"no_standard_prediction": True,
"no_sliced_prediction": False,
"slice_size": 640,
"overlap_ratio": 0.25,
},
"VISDRONE_SAHI_FI": {
"no_standard_prediction": False,
"no_sliced_prediction": False,
"slice_size": 640,
"overlap_ratio": 0,
},
"VISDRONE_SAHI_FI_PO": {
"no_standard_prediction": False,
"no_sliced_prediction": False,
"slice_size": 640,
"overlap_ratio": 0.25,
},
}
setting_params = INFERENCE_SETTING_TO_PARAMS[INFERENCE_SETTING]
result = predict(
model_type="mmdet",
model_path=MODEL_PATH,
model_config_path=MODEL_CONFIG_PATH,
model_confidence_threshold=0.01,
model_device="cuda:0",
model_category_mapping=None,
model_category_remapping=None,
source=EVAL_IMAGES_FOLDER_DIR,
no_standard_prediction=setting_params["no_standard_prediction"],
no_sliced_prediction=setting_params["no_sliced_prediction"],
image_size=None,
slice_height=setting_params["slice_size"],
slice_width=setting_params["slice_size"],
overlap_height_ratio=setting_params["overlap_ratio"],
overlap_width_ratio=setting_params["overlap_ratio"],
postprocess_type="NMS",
postprocess_match_metric="IOU",
postprocess_match_threshold=0.5,
postprocess_class_agnostic=False,
novisual=not EXPORT_VISUAL,
dataset_json_path=EVAL_DATASET_JSON_PATH,
project="runs/predict_eval_analyse",
name=INFERENCE_SETTING,
visual_bbox_thickness=None,
visual_text_size=None,
visual_text_thickness=None,
visual_export_format="png",
verbose=1,
return_dict=True,
force_postprocess_type=True,
)
result_json_path = str(Path(result["export_dir"]) / "result.json")
evaluate(
dataset_json_path=EVAL_DATASET_JSON_PATH,
result_json_path=result_json_path,
classwise=True,
max_detections=500,
return_dict=False,
)
analyse(
dataset_json_path=EVAL_DATASET_JSON_PATH,
result_json_path=result_json_path,
max_detections=500,
return_dict=False,
)