|
a |
|
b/utils/plotting.py |
|
|
1 |
import matplotlib.pyplot as plt |
|
|
2 |
import numpy as np |
|
|
3 |
import pandas as pd |
|
|
4 |
from scipy.stats import linregress, iqr |
|
|
5 |
|
|
|
6 |
|
|
|
7 |
def get_best_epoch_from_id_split(df): |
|
|
8 |
mean_ious_per_epoch = [np.mean(df[df["epoch"] == i]["iou"]) for i in np.unique(df["epoch"])] |
|
|
9 |
return np.argmax(mean_ious_per_epoch) |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
def plot_std_iou_correlation(df, best=True): |
|
|
13 |
iou_std = [] |
|
|
14 |
iou_avg = [] |
|
|
15 |
for i in np.unique(df["id"]): |
|
|
16 |
id_df = df[df["id"] == i] |
|
|
17 |
id_best_epoch = get_best_epoch_from_id_split(id_df) |
|
|
18 |
if best: |
|
|
19 |
ious = id_df[id_df["epoch"] == id_best_epoch]["iou"] |
|
|
20 |
iou_std.append(np.std(ious)) |
|
|
21 |
iou_avg.append(np.mean(ious)) |
|
|
22 |
else: |
|
|
23 |
iou_std.append(np.nanstd(id_df[id_df["iou"] > 0.01]["iou"])) |
|
|
24 |
iou_avg.append(np.nanmean(id_df[id_df["iou"] > 0.01]["iou"])) |
|
|
25 |
|
|
|
26 |
plt.scatter(iou_std, iou_avg) |
|
|
27 |
print(iou_avg) |
|
|
28 |
result = linregress(iou_std, iou_avg) |
|
|
29 |
m, c, r, p, se = result |
|
|
30 |
print(result) |
|
|
31 |
x = np.linspace(np.min(iou_std), np.max(iou_std), 100) |
|
|
32 |
plt.plot(x, m * x + c, label="R = {}".format(r)) |
|
|
33 |
plt.legend() |
|
|
34 |
plt.ylabel("Mean of IoUs") |
|
|
35 |
plt.xlabel("StDev of IoUs") |
|
|
36 |
plt.show() |
|
|
37 |
|
|
|
38 |
|
|
|
39 |
def compare_variances(baseline_df, stresstest_df): |
|
|
40 |
baseline_mean_ious = [] |
|
|
41 |
stresstest_mean_ious = [] |
|
|
42 |
for id in np.unique(stresstest_df["id"]): |
|
|
43 |
baseline_ious = baseline_df[baseline_df["id"] == id]["iou"] |
|
|
44 |
stresstest_ious = stresstest_df[stresstest_df["id"] == id]["iou"] |
|
|
45 |
baseline_mean_ious.append(np.mean(baseline_ious)) |
|
|
46 |
stresstest_mean_ious.append(np.mean(stresstest_ious)) |
|
|
47 |
plt.hist(baseline_mean_ious, alpha=0.5, label=f"Baseline; iqr={iqr(baseline_mean_ious)}") |
|
|
48 |
plt.hist(stresstest_mean_ious, alpha=0.5, label=f"Stresstest; iqr={iqr(stresstest_mean_ious)}") |
|
|
49 |
plt.legend() |
|
|
50 |
plt.xlabel("Mean IoU") |
|
|
51 |
plt.ylabel("P(Mean IoU)") |
|
|
52 |
|
|
|
53 |
# plt.show() |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
if __name__ == '__main__': |
|
|
57 |
df = pd.read_csv("logs/ious.log") |
|
|
58 |
# df_untrained = pd.read_csv("logs/no-pretrain-ious.log") |
|
|
59 |
df_etis = pd.read_csv("logs/etis-ious.log") |
|
|
60 |
df_etis_stresstest = pd.read_csv("logs/etis-stresstest-results.log") |
|
|
61 |
df_kvasir_stresstest = pd.read_csv("logs/stresstest-results.log") |
|
|
62 |
df_kvasir = pd.read_csv("logs/kvasir-baseline.log") |
|
|
63 |
df_untrained = pd.read_csv("logs/kvasir-no-pretrain-baseline.log") |
|
|
64 |
# plot_std_iou_correlation(df, best=True) |
|
|
65 |
# plot_std_iou_correlation(df_untrained, best=True) |
|
|
66 |
# plot_std_iou_correlation(df_stresstest, best=False) |
|
|
67 |
# compare_variances(df_etis, df_etis_stresstest) |
|
|
68 |
# compare_variances(df, df_kvasir_stresstest) |
|
|
69 |
compare_variances(df_kvasir, df_untrained) |
|
|
70 |
plt.show() |
|
|
71 |
|
|
|
72 |
plot_std_iou_correlation(df_untrained, best=False) |
|
|
73 |
plot_std_iou_correlation(df, best=False) |
|
|
74 |
|
|
|
75 |
# compare_variances(df, df) |
|
|
76 |
# ious = df["iou"] |
|
|
77 |
# stds = [] |
|
|
78 |
# mean_ious = [] |
|
|
79 |
# for i in np.unique(df["id"]): |
|
|
80 |
# plt.hist(ious[df["id"] == i][df["epoch"] == 175], alpha=0.5, bins=np.linspace(0, 1, 25), label=i, density=True) |
|
|
81 |
# mean_ious.append(np.mean(ious[df["id"] == i][df["epoch"] == 175])) |
|
|
82 |
# stds.append(np.std(ious[df["id"] == i][df["epoch"] == 175])) |
|
|
83 |
# # plt.legend() |
|
|
84 |
# plt.tight_layout() |
|
|
85 |
# plt.show() |
|
|
86 |
# print(stds) |
|
|
87 |
# plt.hist(stds) |
|
|
88 |
# plt.show() |
|
|
89 |
# |
|
|
90 |
# plt.scatter(stds, mean_ious) |
|
|
91 |
# m, c, r, p, se = linregress(stds, mean_ious) |
|
|
92 |
# print(m, c) |
|
|
93 |
# plt.xlabel("Standard deviation") |
|
|
94 |
# plt.ylabel("IoU") |
|
|
95 |
# plt.show() |