Vapoursynth GRLIR Resize: Difference between revisions

From wiki.selur.net
Jump to navigation Jump to search
New filter page (via create-page on MediaWiki MCP Server)
 
Update to current Hybrid behaviour; code as <pre> (via update-page on MediaWiki MCP Server)
 
Line 35: Line 35:
== Example ==
== Example ==
Default settings on a 10-bit YUV 4:2:0 source (640x356), resized to 1280x712:
Default settings on a 10-bit YUV 4:2:0 source (640x356), resized to 1280x712:
<syntaxhighlight lang="python">
<pre>
clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=2) # add borders to achieve mod 8 (vsGRLIR) - 640x360
clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=2) # add borders to achieve mod 8 (vsGRLIR) - 640x360
# adjusting color space from YUV420P10 to RGBS for vsGRLIR
# adjusting color space from YUV420P10 to RGBS for vsGRLIR
Line 45: Line 45:
# resizing 2560x1424 to 1280x712
# resizing 2560x1424 to 1280x712
clip = core.fmtc.resample(clip, w=1280, h=712, kernel="spline64", interlaced=False, interlacedd=False)
clip = core.fmtc.resample(clip, w=1280, h=712, kernel="spline64", interlaced=False, interlacedd=False)
</syntaxhighlight>
</pre>


== How Hybrid calls it ==
== How Hybrid calls it ==

Latest revision as of 09:50, 16 November 2026

GRLIR upscales with the super-resolution models of GRL, a transformer-based image restoration network that models image hierarchies at several scales. It is one of the resizers of Vapoursynth Resizer, runs on an NVIDIA GPU through PyTorch and is slow.

Filtering → Vapoursynth → Frame → Resize

GRLIR controls in Hybrid
GRLIR controls in Hybrid

What it does

Every frame is enlarged by the factor of the chosen model. Blind Image SR is meant for real-world degradations; the Classical Image SR models were trained on clean bicubic downscaling. Hybrid resizes the result to the exact output size afterwards.

Requirements

  • Windows, Hybrid's torch add-on and an NVIDIA GPU with CUDA.

Settings

Control Parameter Range / values Hybrid default Meaning
Model model Blind Image SR (4×), Classical Image SR (scale 2), (scale 3), (scale 4) Blind Image SR Network and upscale factor.
GPU ID device_index 0 – 4 0 CUDA device.
Streams num_streams 1 – 64 1 Number of CUDA streams.
Tile (x/y) tile_w, tile_h 0 – 8192 0 / 0 Splits the frame into tiles to save GPU memory; 0 = no tiling.
Tile pad tile_pad 0 – 64 16 Overlap of the tiles; only with tiling. Changing the model while tiling sets 16 (Blind) or 32 (Classical).
FP16 – on/off off Half precision (16-bit float clip); faster and needs less memory.
CUDA Graph cuda_graphs on/off off Uses CUDA graphs.
Resizer – point, rect, linear, cubic, lanczos, blackman, blackmanminlobe, spline36, spline64, spline144, spline, gauss, sinc spline64 Kernel that brings the result to the exact output size.

Example

Default settings on a 10-bit YUV 4:2:0 source (640x356), resized to 1280x712:

clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=2) # add borders to achieve mod 8 (vsGRLIR) - 640x360
# adjusting color space from YUV420P10 to RGBS for vsGRLIR
clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_in_s="limited", range_s="full")
# resizing using GRLIR
from vsgrlir import grlir
clip = grlir(clip, model=0) # scale: 4 - 2560x1440
clip = core.std.Crop(clip=clip, left=0, right=0, top=8, bottom=8) # removing added borders from mod requirement (vsGRLIR) -  2560x1424
# resizing 2560x1424 to 1280x712
clip = core.fmtc.resample(clip, w=1280, h=712, kernel="spline64", interlaced=False, interlacedd=False)

How Hybrid calls it

  • Selected with Resize enabled and Resizer set to GRLIR (see Vapoursynth Resizer).
  • The clip is converted to 32-bit float RGB (16-bit float with FP16) and padded to mod 8; afterwards the padding × the model's factor is cropped.
  • The output is input × the model's factor (2, 3 or 4). If that differs from the target, fmtconv resizes it with the Resizer kernel to the exact size. With separately filtered fields the target height is halved.
  • The model is always written, and so is the tile pad while tiling is on; GPU ID, streams, tiles and CUDA Graph only when they differ from the defaults.
  • The restoration models of GRL (deblurring, denoising, JPEG) are in the separate GRLIR filter.

Background

GRL

GRL (Li et al., CVPR 2023, "Efficient and Explicit Modelling of Image Hierarchies for Image Restoration") combines regional, local and global attention so that the network sees structure at several distances at once. The classical super-resolution models are the small variants; the blind model is a base-size network.

vs-grlir

HolyWu's vs-grlir runs GRL in VapourSynth with PyTorch. Without an explicit tile pad it uses 16 for the blind model and 32 for the classical ones.

Sources