File size: 1,433 Bytes
0a3edb6 | 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 | import collections, glob, random, sys
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
sys.path.insert(0, "scripts")
from render_png import draw
from functional import sample, window, thput, MACH, C
from measure import CONFIGS
views = sample(sorted(glob.glob(sys.argv[1])), int(sys.argv[2]), nudge=True)
cfg, out = CONFIGS[sys.argv[3]], sys.argv[4]
fails = []
for i, (r, lab, x0, y0) in enumerate(views):
w, why = window(r, lab, x0, y0, cfg)
if thput(w) <= 0:
fails.append((i, w, why, r, x0, y0))
print(len(fails), "of", len(views), "deliver nothing")
pick = random.Random(7).sample(fails, 12)
fig, axes = plt.subplots(3, 4, figsize=(40, 33))
for ax, (i, w, why, r, x0, y0) in zip(axes.flat, pick):
kinds = collections.Counter(f"{k} {h.split(' (')[0]}" for k, h in why.markers.values())
masked = collections.Counter(n for n, x, y, wd, h in r.masked if x < x0 + 30 and x + wd > x0 and y < y0 + 30 and y + h > y0)
lines = [f"#{i}: delivers nothing" + (" (has machines)" if np.isin(w[C[0]], list(MACH)).any() else "")]
lines.append(("markers: " + ", ".join(f"{n} {k}" for k, n in kinds.most_common(3))) if kinds else "no markers")
lines.append(("masked: " + ", ".join(f"{n} {k}" for k, n in masked.most_common(3))) if masked else "nothing masked")
draw(w, ax, "\n".join(lines))
ax.title.set_fontsize(19)
fig.savefig(out, dpi=55, bbox_inches="tight")
|