Commit Graph
4 Commits
Author SHA1 Message Date
WildAi 84a9908387 Round 9: the owner's keep-fix3 (five paste-stage fixes)
Implements the owner's .dev/docs/keep-fix3.txt precisely:

- Fix 1.1: a frame with no detected face (affine None) short-circuits
  the fallback paste to the upscaled background - no vendored
  paste_faces_to_input_image on a face-less frame; paste_bar threaded
  into _batched_paste; the canvas/chunk buffers alias when every frame
  is batched (no copy); progress.update(1) added to the skipped rows.
- Fix 1.2: the grayscale eligibility filter is gone - the device blend
  pastes a gray frame with the same tensor logic; _batched_paste gains
  stage_bar and forwards it into all three paste modes.
- Fix 2.1: _paste_chunk_roi is one vectorized GPU tail - the faces and
  the parse masks warp to the full canvas in one warp_affine_batch call
  each (grid_sample), one-tensor alpha blend, the vendored quantizing
  tail over the whole-canvas maximum; the per-face ROI machinery
  (warp_face_roi, fixed-point terms, ROI patch transfers) is gone from
  the single-face path.  warp_face_roi stays live for the multi-face
  sibling _paste_chunk_faces.  Pixel change owner-authorized; the
  retired transfer counters are disclosed in the dated docstring.
- Fix 2.2: device_output_mode - CUDA never returns "host": full while
  the whole batch's canvas fits the budget, else always chunked (the
  OOM handler is the net, the owner-authorized trade); non-CUDA keeps
  "host".
- Fix 2.3: paste_faces_batch_chunked ticks the stage bar per completed
  GPU group; paste_faces_batch does the same per chunk (the full/host
  modes) - nobody ticks twice, the bar totals num_input_frames exactly
  on every path; the multi-face groups get no tick (the multiface
  stage owns its bar).

The single-face sequence golden is re-captured (owner-authorized
pixels); the paste equivalence and cadence pins are reworked to the
measured behavior with dated docstrings.

Gate: 555 passed, 6 skipped, 7 deselected, 0 failed (baseline 552).
2026-10-31 00:13:46 +03:00
WildAi 8c10bc5118 Round 6: the owner's six GPU optimizations (keep-fix1)
Opt 1 - the fused crop loops warp on the device (crop_faces_batch per
source-shape group) instead of one cv2.warpAffine per row.
Opt 2 - warp_face_roi uploads its four terms once and composes
x_full/y_full on the device; the fixed-point math is unchanged (bitwise).
Opt 3 - bgr_u8_batch_to_normalized runs in float32 end to end and
_gaussian_smooth convolves in float32; the float64 transient is gone.
Opt 4 - the Lanczos axis matrices are cached per (in_size, out_size); the
cache holds device-free numpy, so one entry serves both devices.
Opt 5 - the aligned single-image path restores on the device
(_restore_aligned_torch): no detection, no vendored img2tensor tail, no
vendored paste.  The io schema is untouched.
Opt 6 - the chunk loops no longer call _soft_empty_cache(); the release
stays in the finally blocks and in the OOM handler.

The two sequence golden fixtures are re-captured (the owner's documented
override of the capture tool's do-not-rerun warning) - Opt 1 and Opt 3
change pixels by design.  The image fixtures are unchanged.

Tier-1 gate: 534 passed, 6 skipped, 7 deselected, 0 failed.
2026-10-30 01:46:08 +03:00
WildAi a612061fcd perf(paste): paste faces on ROI-sized device data
The paste stage spent its host time on three full-canvas passes per frame. The face warp now runs on the device with cv2's own fixed-point convention (the matrix inversion of warpAffine, the 1/1024 pre-scale, the 1/32 tap grid, the (+512)>>10 rounding), the mask warp reuses the one batched grid sliced to the face ROI, and the blend and the quantizing tail run inside that ROI. The frame-global maximum branch is kept: a near-black frame falls back to the full-canvas path, which stays bit-exact by construction.

Measured over 48 frames at 720p on CUDA: the paste call's process CPU time falls 20% (38.74 -> 30.92 ms/frame), the host-device transfers shrink 6.66x (the blended canvas download by 85%), and the result is bit-identical to the full-canvas path on the smooth and the noise corpus, at interior and edge-touching ROIs.
2026-10-26 18:23:29 +03:00
WildAi 4770354f25 feat(video): run the sequence pipeline read-once, affine-once, batched on the device
process_image_sequence converts the batch once, detects per frame while capturing the frames the detector saw (the read_image products, including the min(h,w)<512 upscale), estimates each affine once with the vendored call, crops with cv2.warpAffine (decision D2: the uint8-bound warp stays bit-exact; the batched grid_sample helper stays parked and pinned), normalizes the whole crop batch on the device, keeps the KEEP chunk contract byte-identical, converts the restored faces with one batched tensor2img, pastes through the batched paste with the vendored fallback, and stacks the output in one transfer. The paste canvas is the detection frame, so small frames keep the base's upscaled canvas (the round-1 QA defect F1, fixed and pinned). A failed affine degrades to the neutral crop with a warning instead of crashing like the base. Progress still reports num_frames * 4 in the four families. Pins: the read-once/affine-once/chunk-contract AST guards, the progress contract, and the new end-to-end base-vs-shipped suite (tests/test_gpu_sequence_e2e.py) with the real vendored helper - measured drift 0/255 on the vendored branch, 1/255 on the batched branch.
2026-10-26 08:04:00 +03:00