FeilongTang commited on
Commit
75f6cf2
Β·
1 Parent(s): b5599e7

Uniform baseline: same N frames as codec, equal per-frame allocation

Browse files

Before, uniform baseline sampled budget // grid_size *full* frames,
which often collapsed to 1 frame when the budget couldn't afford two
whole grids. The chart then looked lopsided β€” codec hit the budget
while uniform plateaued well below it.

Now both methods sample the same N frames at the same timestamps; the
patch budget is split equally per frame for the uniform side
(budget // N each, remainder distributed). Both curves end exactly at
the budget reference line, and the visual contrast becomes 'where the
patches go' (saliency-skewed vs equal-height steps) instead of 'how
many uniform frames fit'.

Chart : 16 paired step jumps; codec uneven, uniform flat-height.
JSON : 'uniform_baseline.frames' = sample_frames; 'patches_per_frame'
= budget // N (and the explanation text reflects the new
semantic).
Subtitle clarified.

Files changed (1) hide show
  1. app.py +37 -17
app.py CHANGED
@@ -621,13 +621,21 @@ def make_charts(
621
  codec_total = int(codec_cum[-1]) if codec_cum else 0
622
  xx_c, yy_c = _step(times, codec_cum)
623
 
624
- n_uniform = max(1, int(total_patches_budget // max(1, grid_size)))
625
- uni_times = (
626
- [duration * 0.5] if n_uniform == 1
627
- else list(np.linspace(0.0, duration, n_uniform))
628
- )
629
- uni_cum = list(np.cumsum([grid_size] * n_uniform))
 
 
 
 
 
 
 
630
  uni_total = int(uni_cum[-1]) if uni_cum else 0
 
631
  xx_u, yy_u = _step(uni_times, uni_cum)
632
 
633
  # ─── Plot ───────────────────────────────────────────────────────────
@@ -812,7 +820,12 @@ def process(
812
 
813
  hb, wb = grids[0].shape
814
  grid_size = int(grids[0].shape[0] * grids[0].shape[1]) if grids else 0
815
- n_uniform = max(1, int(int(total_patches) // max(1, grid_size)))
 
 
 
 
 
816
  info = {
817
  "input": meta,
818
  "params": {
@@ -845,12 +858,17 @@ def process(
845
  },
846
  "uniform_baseline": {
847
  "frames": int(n_uniform),
848
- "patches_per_frame": int(grid_size),
849
- "total_patches": int(n_uniform * grid_size),
850
  "explanation": (
851
- "Same patch budget spent on whole frames sampled uniformly in "
852
- "time β€” every patch in those frames kept, vs codec's selective "
853
- "concentration on high-saliency patches."
 
 
 
 
 
854
  ),
855
  },
856
  "resized_frame_size": f"{tw}x{th}",
@@ -1385,11 +1403,13 @@ with gr.Blocks(**_BLOCK_KW) as demo:
1385
  with gr.Group(elem_classes="ovc-card ovc-card-primary"):
1386
  gr.Markdown("### Cumulative patches over time")
1387
  gr.Markdown(
1388
- "<small>Same total patch budget. <b>Indigo</b>: codec "
1389
- "saliency cumulative count β€” rises in bursts on high-"
1390
- "energy moments. <b>Cyan (dashed)</b>: uniform sampling "
1391
- "baseline β€” equal-height steps at evenly-spaced times. "
1392
- "Both end near the dotted <b>budget</b> reference line.</small>"
 
 
1393
  )
1394
  chart_out = gr.Plot(label="", show_label=False)
1395
 
 
621
  codec_total = int(codec_cum[-1]) if codec_cum else 0
622
  xx_c, yy_c = _step(times, codec_cum)
623
 
624
+ # Uniform baseline: same N frames as codec (at the same timestamps),
625
+ # but the patch budget is split equally across them. Both curves now
626
+ # reach the same budget β€” what differs is *which* patches each method
627
+ # picks within each frame (saliency vs equal-allocation).
628
+ n_uniform = len(times) if times else 1
629
+ budget_int = int(total_patches_budget)
630
+ if n_uniform > 0 and budget_int > 0:
631
+ base = budget_int // n_uniform
632
+ rem = budget_int - base * n_uniform
633
+ uni_per_step = [base + (1 if i < rem else 0) for i in range(n_uniform)]
634
+ else:
635
+ uni_per_step = []
636
+ uni_cum = list(np.cumsum(uni_per_step)) if uni_per_step else []
637
  uni_total = int(uni_cum[-1]) if uni_cum else 0
638
+ uni_times = times if times else [duration * 0.5]
639
  xx_u, yy_u = _step(uni_times, uni_cum)
640
 
641
  # ─── Plot ───────────────────────────────────────────────────────────
 
820
 
821
  hb, wb = grids[0].shape
822
  grid_size = int(grids[0].shape[0] * grids[0].shape[1]) if grids else 0
823
+ # Uniform baseline samples the SAME number of frames as codec, evenly
824
+ # spaced in time; the budget is split equally across them.
825
+ n_uniform = max(1, len(fids))
826
+ uniform_per_frame = (
827
+ int(int(total_patches)) // n_uniform if n_uniform > 0 else 0
828
+ )
829
  info = {
830
  "input": meta,
831
  "params": {
 
858
  },
859
  "uniform_baseline": {
860
  "frames": int(n_uniform),
861
+ "patches_per_frame": int(uniform_per_frame),
862
+ "total_patches": int(uniform_per_frame * n_uniform),
863
  "explanation": (
864
+ "Same N frames as codec, evenly spaced in time. The patch "
865
+ "budget is split equally per frame ({budget} Γ· {n} = "
866
+ "{per}); the codec, by contrast, concentrates the same "
867
+ "budget on high-saliency patches across those frames."
868
+ ).format(
869
+ budget=int(total_patches),
870
+ n=int(n_uniform),
871
+ per=int(uniform_per_frame),
872
  ),
873
  },
874
  "resized_frame_size": f"{tw}x{th}",
 
1403
  with gr.Group(elem_classes="ovc-card ovc-card-primary"):
1404
  gr.Markdown("### Cumulative patches over time")
1405
  gr.Markdown(
1406
+ "<small>Same number of sampled frames and the same total "
1407
+ "patch budget for both methods. <b>Indigo</b>: codec "
1408
+ "saliency β€” rises in bursts where the frames carry more "
1409
+ "information. <b>Cyan (dashed)</b>: uniform baseline β€” "
1410
+ "the same budget split equally per frame, so each step "
1411
+ "has the same height. Both curves end exactly at the "
1412
+ "dotted <b>budget</b> reference line.</small>"
1413
  )
1414
  chart_out = gr.Plot(label="", show_label=False)
1415