Skip to content

Commit 84b1d44

Browse files
authored
[fix] modify dictionary key values ​​for class-wise complexity calculations (#14)
* [fix] modify dictionary key values ​​for class-wise calculations * [formatting] isort and black
1 parent c7896c7 commit 84b1d44

File tree

1 file changed

+25
-50
lines changed

1 file changed

+25
-50
lines changed

utils/compute_overall_kmac_per_px.py

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@
3838

3939

4040
def generate_csv_classwise_image_gmac(dataset_name, result_path, list_of_classwise_seq):
41-
prefix = "mpeg-oiv6"
4241
seq_wise_results = []
43-
cls_wise_results = []
4442
for cls_seqs in list_of_classwise_seq:
45-
complexity_lst_class_wise = []
46-
seq_name = f"{prefix}-{cls_seqs}"
43+
seq_name = f"mpeg-oiv6-{cls_seqs}"
4744
base_path = f"{result_path}/{seq_name}"
4845
qps = [
4946
f
@@ -55,6 +52,10 @@ def generate_csv_classwise_image_gmac(dataset_name, result_path, list_of_classwi
5552
complexity_dict = {"Dataset": seq_name, "pp": idx}
5653
comp_path = f"{base_path}/{qp}/evaluation/summary_complexity.csv"
5754
summary_path = f"{base_path}/{qp}/evaluation/summary.csv"
55+
56+
if not (os.path.exists(summary_path) or os.path.exists(summary_path)):
57+
continue
58+
5859
with open(summary_path, mode="r", newline="", encoding="utf-8") as file:
5960
reader = csv.DictReader(file)
6061
data = [row for row in reader][0]
@@ -69,63 +70,42 @@ def generate_csv_classwise_image_gmac(dataset_name, result_path, list_of_classwi
6970
for k, v in kmac_per_pixels.items():
7071
complexity_dict[k] = v
7172

72-
complexity_lst_class_wise.append(complexity_dict)
7373
seq_wise_results.append(complexity_dict)
7474

75-
# class-wise calculation
76-
nn_part1_lst, ft_reduction_lst, ft_restoration_lst, nn_part2_lst = (
77-
[],
78-
[],
79-
[],
80-
[],
81-
)
82-
for seq_data in complexity_lst_class_wise:
83-
nn_part1_lst.append(seq_data["nn_part1"])
84-
ft_reduction_lst.append(seq_data["feature reduction"])
85-
ft_restoration_lst.append(seq_data["feature restoration"])
86-
nn_part2_lst.append(seq_data["nn_part2"])
87-
88-
cls_wise_result = {
89-
"Dataset": f"{seq_name}-avg",
90-
"pp": 0,
91-
"qp": 0,
92-
"nn_part1": sum(nn_part1_lst) / len(nn_part1_lst),
93-
"feature reduction": sum(ft_reduction_lst) / len(ft_reduction_lst),
94-
"feature restoration": sum(ft_restoration_lst) / len(ft_restoration_lst),
95-
"nn_part2": sum(nn_part2_lst) / len(nn_part2_lst),
96-
}
97-
98-
cls_wise_results.append(cls_wise_result)
99-
100-
results = pd.DataFrame(seq_wise_results + cls_wise_results)
101-
102-
return results
75+
return pd.DataFrame(seq_wise_results)
10376

10477

10578
def generate_csv_classwise_video_gmac(
10679
dataset_name, result_path, list_of_classwise_seq, seq_lst
10780
):
108-
if dataset_name == "SFU":
109-
prefix = "sfu-hw"
110-
else:
111-
prefix = "mpeg"
11281

113-
seq_wise_results = []
114-
cls_wise_results = []
82+
seq_base_path = [
83+
f
84+
for f in os.listdir(result_path)
85+
if os.path.isdir(os.path.join(result_path, f))
86+
]
87+
88+
seq_wise_results, cls_wise_results = [], []
11589
for cls_seqs in list_of_classwise_seq:
11690
for cls_name, seqs in cls_seqs.items():
11791
complexity_lst_class_wise = []
118-
for seq in seqs:
119-
seq_name = [seq_name for seq_name in seq_lst if seq in seq_name][0]
120-
base_path = f"{result_path}/{prefix}-{seq_name}_val"
92+
93+
seq_path = [
94+
next(name for name in seq_base_path if s in name)
95+
for s in seqs
96+
if any(s in name for name in seq_base_path)
97+
]
98+
99+
for seq in seq_path:
100+
base_path = f"{result_path}/{seq}"
121101
qps = [
122102
f
123103
for f in os.listdir(base_path)
124104
if os.path.isdir(os.path.join(base_path, f))
125105
]
126106
qps = sorted(qps)
127107
for idx, qp in enumerate(qps):
128-
complexity_dict = {"Dataset": seq_name, "pp": idx}
108+
complexity_dict = {"Dataset": seq, "pp": idx}
129109
comp_path = f"{base_path}/{qp}/evaluation/summary_complexity.csv"
130110
summary_path = f"{base_path}/{qp}/evaluation/summary.csv"
131111
with open(
@@ -152,7 +132,7 @@ def generate_csv_classwise_video_gmac(
152132
seq_wise_results.append(complexity_dict)
153133

154134
# class-wise calculation
155-
for idx in range(4):
135+
for idx in range(len(qps)):
156136
(
157137
nn_part1_lst,
158138
ft_reduction_lst,
@@ -298,7 +278,7 @@ def generate_csv_classwise_video_gmac(
298278
)
299279
elif args.dataset_name == "HIEVE":
300280
hieve_1080p = {"HIEVE-1080P": ["13", "16"]}
301-
hieve_720p = {"HIEVE-720P": ["2", "17", "18"]}
281+
hieve_720p = {"HIEVE-720P": ["17", "18", "2"]}
302282
seq_list = [
303283
"13_1920x1080_30",
304284
"16_1920x1080_30",
@@ -309,12 +289,7 @@ def generate_csv_classwise_video_gmac(
309289
output_df = generate_csv_classwise_video_gmac(
310290
args.dataset_name, args.result_path, [hieve_1080p, hieve_720p], seq_list
311291
)
312-
# sort for FCM template - comply with the template provided in wg04n00459
313292

314-
sorterIndex = dict(zip(seq_list, range(len(seq_list))))
315-
output_df["ds_rank"] = output_df["Dataset"].map(sorterIndex)
316-
output_df.sort_values(["ds_rank", "qp"], ascending=[True, True], inplace=True)
317-
output_df.drop(columns=["ds_rank"], inplace=True)
318293
else:
319294
raise NotImplementedError
320295

0 commit comments

Comments
 (0)