| |
| """ |
| tools/ptv3_plot_cards_0920.py —— 只画图,不读取任何文件 |
| - 把指标硬编码在 data 里,生成 base/quant 单卡片 + 对比卡片 |
| - 输出:--out-dir / 默认 exp/summary_0920/plots_0920_cards |
| """ |
|
|
| import argparse |
| from pathlib import Path |
| import matplotlib |
| matplotlib.use("Agg") |
| import matplotlib.pyplot as plt |
|
|
| def draw_card_png(dataset: str, tag: str, info: dict, out_png: Path): |
| plt.figure(figsize=(10.5, 6.5)) |
| ax = plt.gca(); ax.axis("off") |
| miou = info.get("miou") |
| rows = [ |
| ["Dataset", dataset.upper()], |
| ["Variant", tag.upper()], |
| ["mIoU (%)", "-" if miou is None else f"{(miou*100):.2f}"], |
| ["Avg Weight Bit", "-" if info.get("avg_bit") is None else f"{info['avg_bit']:.3f}"], |
| ["Quant Ratio (%)", "-" if info.get("qratio") is None else f"{info['qratio']:.2f}"], |
| ] |
| table = ax.table(cellText=rows, colLabels=["Metric","Value"], loc="center", cellLoc="center") |
| table.auto_set_font_size(False); table.set_fontsize(18); table.scale(1.4, 2.0) |
| for (r,c),cell in table.get_celld().items(): |
| if r==0: cell.set_text_props(weight='bold') |
| ax.set_title(f"{dataset.upper()} - {tag.upper()} (0920)", fontsize=28, fontweight="bold", pad=20) |
| plt.tight_layout() |
| out_png.parent.mkdir(parents=True, exist_ok=True) |
| plt.savefig(out_png, dpi=220, bbox_inches="tight") |
| plt.close() |
| print(f"[card] {out_png}") |
|
|
| def draw_compare_png(dataset: str, base_info: dict, quant_info: dict, out_png: Path): |
| plt.figure(figsize=(12, 6.5)) |
| ax = plt.gca(); ax.axis("off") |
| b = base_info.get("miou"); q = quant_info.get("miou") |
| delta = None if (b is None or q is None) else ((q - b) * 100) |
| fmt_bit = lambda v: "-" if v is None else f"{v:.3f}" |
| bit_base, bit_quant = fmt_bit(base_info.get("avg_bit")), fmt_bit(quant_info.get("avg_bit")) |
| qratio_s = "-" if quant_info.get("qratio") is None else f"{quant_info['qratio']:.2f}" |
| rows = [ |
| ["Dataset", dataset.upper()], |
| ["mIoU BASE (%)", "-" if b is None else f"{b*100:.2f}"], |
| ["mIoU QUANT (%)", "-" if q is None else f"{q*100:.2f}"], |
| ["Δ mIoU (pp)", "-" if delta is None else f"{delta:+.2f}"], |
| ["Avg Bit (BASE/QUANT)", f"{bit_base} / {bit_quant}"], |
| ["Quant Ratio (QUANT %)", qratio_s], |
| ] |
| table = ax.table(cellText=rows, colLabels=["Metric","Value"], loc="center", cellLoc="center") |
| table.auto_set_font_size(False); table.set_fontsize(18); table.scale(1.6, 2.0) |
| for (r,c),cell in table.get_celld().items(): |
| if r==0: cell.set_text_props(weight='bold') |
| ax.set_title(f"{dataset.upper()} - BASE vs QUANT (0920)", fontsize=28, fontweight="bold", pad=20) |
| plt.tight_layout() |
| out_png.parent.mkdir(parents=True, exist_ok=True) |
| plt.savefig(out_png, dpi=220, bbox_inches="tight") |
| plt.close() |
| print(f"[compare] {out_png}") |
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--out-dir", default="exp/summary_0920/plots_0920_cards") |
| args = ap.parse_args() |
| out_dir = Path(args.out_dir); out_dir.mkdir(parents=True, exist_ok=True) |
|
|
| |
| data = { |
| "nuscenes": { |
| "base": {"miou": 0.2598, "avg_bit": 32.0, "qratio": 0.0}, |
| "quant": {"miou": 0.6264, "avg_bit": 2.058, "qratio": 99.81}, |
| }, |
| "scannet": { |
| "base": {"miou": 0.1836, "avg_bit": 32.0, "qratio": 0.0}, |
| "quant": {"miou": 0.2450, "avg_bit": 2.125, "qratio": 99.58}, |
| }, |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
|
|
| for ds, kinds in data.items(): |
| |
| for tag in ("base","quant"): |
| if tag in kinds: |
| out = out_dir / f"{ds}_{tag}_0920.png" |
| draw_card_png(ds, tag, kinds[tag], out) |
| |
| if "base" in kinds and "quant" in kinds: |
| out_cmp = out_dir / f"{ds}_compare_0920.png" |
| draw_compare_png(ds, kinds["base"], kinds["quant"], out_cmp) |
|
|
| if __name__ == "__main__": |
| main() |
|
|