1 import numpy as np
   2 import matplotlib.pyplot as plt
   3 from scipy.interpolate import make_interp_spline
   4 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten
   5 setup_style()
   6 
   7 models = ['Ours', 'ViT-B', 'ViT-L', 'ResNet-50', 'ResNet-101', 'DeiT-S', 'Swin-T', 'EfficientNet']
   8 flops = np.array([4.2, 17.6, 61.6, 4.1, 7.8, 4.6, 4.5, 0.4])
   9 acc = np.array([92.3, 91.2, 92.0, 89.5, 90.8, 90.1, 91.5, 88.2])
  10 params = np.array([25, 86, 307, 25, 44, 22, 28, 5])
  11 
  12 fig, ax = plt.subplots(figsize=(8, 5.5))
  13 
  14 # Iso-efficiency contours (acc/flops = const)
  15 flops_grid = np.linspace(0.1, 70, 200)
  16 for eff in [5, 10, 20, 40]:
  17     acc_iso = eff * np.sqrt(flops_grid)
  18     mask = acc_iso <= 96
  19     ax.plot(flops_grid[mask], acc_iso[mask], '-', color=COLORS['grid'], linewidth=0.6, alpha=0.5)
  20 ax.text(65, 86, 'iso-efficiency\ncurves', fontsize=6.5, color=COLORS['grid'], ha='right', style='italic')
  21 
  22 # Scatter bubbles
  23 for i, model in enumerate(models):
  24     c = PALETTE[0] if model == 'Ours' else PALETTE[2]
  25     alpha = 1.0 if model == 'Ours' else 0.55
  26     s = params[i] * 3
  27     ax.scatter(flops[i], acc[i], s=s, color=c, alpha=alpha, edgecolor='white',
  28                linewidth=1, zorder=3)
  29     offset = (8, 8) if model not in ['ViT-L', 'EfficientNet'] else (-15, -12)
  30     ax.annotate(model, xy=(flops[i], acc[i]), xytext=offset, textcoords='offset points',
  31                 fontsize=8, fontweight='bold' if model == 'Ours' else 'normal',
  32                 color=PALETTE[0] if model == 'Ours' else 'grey')
  33 
  34 # Ours highlight ring
  35 ours_idx = models.index('Ours')
  36 ax.scatter(flops[ours_idx], acc[ours_idx], s=params[ours_idx] * 3 + 120, facecolor='none',
  37            edgecolor=PALETTE[0], linewidth=2.5, zorder=4)
  38 
  39 # Pareto frontier
  40 # Find Pareto-optimal points (lower flops, higher acc)
  41 pareto_mask = np.ones(len(models), dtype=bool)
  42 for i in range(len(models)):
  43     for j in range(len(models)):
  44         if i != j and flops[j] <= flops[i] and acc[j] >= acc[i] and (
  45                 flops[j] < flops[i] or acc[j] > acc[i]):
  46             pareto_mask[i] = False
  47             break
  48 
  49 pareto_flops = flops[pareto_mask]
  50 pareto_acc = acc[pareto_mask]
  51 sort_idx = np.argsort(pareto_flops)
  52 pareto_flops = pareto_flops[sort_idx]
  53 pareto_acc = pareto_acc[sort_idx]
  54 
  55 # Smooth Pareto line
  56 if len(pareto_flops) >= 3:
  57     f_smooth = np.linspace(pareto_flops.min(), pareto_flops.max(), 100)
  58     try:
  59         spl = make_interp_spline(pareto_flops, pareto_acc, k=min(3, len(pareto_flops) - 1))
  60         a_smooth = spl(f_smooth)
  61         ax.plot(f_smooth, a_smooth, '-', color=PALETTE[0], linewidth=1.5, alpha=0.6,
  62                 label='Pareto frontier')
  63     except Exception:
  64         ax.plot(pareto_flops, pareto_acc, '-', color=PALETTE[0], linewidth=1.5, alpha=0.6,
  65                 label='Pareto frontier')
  66 else:
  67     ax.plot(pareto_flops, pareto_acc, '-', color=PALETTE[0], linewidth=1.5, alpha=0.6,
  68             label='Pareto frontier')
  69 
  70 # "Better" direction arrow
  71 ax.annotate('', xy=(1, 94), xytext=(15, 87),
  72             arrowprops=dict(arrowstyle='->', color=COLORS['up'], lw=2, connectionstyle='arc3,rad=0.1'))
  73 ax.text(5, 93.5, 'Better', fontsize=10, fontweight='bold', color=COLORS['up'],
  74         style='italic', rotation=15)
  75 
  76 # Bubble size legend
  77 for ps in [10, 50, 200]:
  78     ax.scatter([], [], s=ps * 3, color=COLORS['ref_line'], alpha=0.3, edgecolor='white', label=f'{ps}M params')
  79 
  80 ax.set_xlabel('GFLOPs', fontsize=11)
  81 ax.set_ylabel('Top-1 Accuracy (%)', fontsize=11)
  82 ax.legend(frameon=False, labelspacing=0.35, handlelength=1.6, fontsize=8, loc='lower right', title='Model Size')
  83 ax.spines['top'].set_visible(False)
  84 ax.spines['right'].set_visible(False)
  85 ax.grid(alpha=0.15, linestyle='--')
  86 fig.tight_layout()
  87 save_fig(fig, 'figures/fig_efficiency.pdf')