basicsr.archs.basicvsrpp_arch

class basicsr.archs.basicvsrpp_arch.BasicVSRPlusPlus(mid_channels=64, num_blocks=7, max_residue_magnitude=10, is_low_res_input=True, spynet_path=None, cpu_cache_length=100)[source]

Bases: Module

BasicVSR++ network structure. Support either x4 upsampling or same size output. Since DCN is used in this model, it can only be used with CUDA enabled. If CUDA is not enabled, feature alignment will be skipped. Besides, we adopt the official DCN implementation and the version of torch need to be higher than 1.9. Paper:

BasicVSR++: Improving Video Super-Resolution with Enhanced Propagation and Alignment

Parameters
  • mid_channels (int, optional) – Channel number of the intermediate features. Default: 64.

  • num_blocks (int, optional) – The number of residual blocks in each propagation branch. Default: 7.

  • max_residue_magnitude (int) – The maximum magnitude of the offset residue (Eq. 6 in paper). Default: 10.

  • is_low_res_input (bool, optional) – Whether the input is low-resolution or not. If False, the output resolution is equal to the input resolution. Default: True.

  • spynet_path (str) – Path to the pretrained weights of SPyNet. Default: None.

  • cpu_cache_length (int, optional) – When the length of sequence is larger than this value, the intermediate features are sent to CPU. This saves GPU memory, but slows down the inference speed. You can increase this number if you have a GPU with large memory. Default: 100.

check_if_mirror_extended(lqs)[source]

Check whether the input is a mirror-extended sequence. If mirror-extended, the i-th (i=0, …, t-1) frame is equal to the (t-1-i)-th frame. :param lqs: Input low quality (LQ) sequence with

shape (n, t, c, h, w).

compute_flow(lqs)[source]

Compute optical flow using SPyNet for feature alignment. Note that if the input is an mirror-extended sequence, ‘flows_forward’ is not needed, since it is equal to ‘flows_backward.flip(1)’. :param lqs: Input low quality (LQ) sequence with

shape (n, t, c, h, w).

Returns

Optical flow. ‘flows_forward’ corresponds to the

flows used for forward-time propagation (current to previous). ‘flows_backward’ corresponds to the flows used for backward-time propagation (current to next).

Return type

tuple(Tensor)

forward(lqs)[source]

Forward function for BasicVSR++. :param lqs: Input low quality (LQ) sequence with

shape (n, t, c, h, w).

Returns

Output HR sequence with shape (n, t, c, 4h, 4w).

Return type

Tensor

propagate(feats, flows, module_name)[source]

Propagate the latent features throughout the sequence. :param feats dict: Features from previous branches. Each

component is a list of tensors with shape (n, c, h, w).

Parameters
  • flows (tensor) – Optical flows with shape (n, t - 1, 2, h, w).

  • module_name (str) – The name of the propgation branches. Can either be ‘backward_1’, ‘forward_1’, ‘backward_2’, ‘forward_2’.

Returns

A dictionary containing all the propagated

features. Each key in the dictionary corresponds to a propagation branch, which is represented by a list of tensors.

Return type

dict(list[tensor])

training: bool
upsample(lqs, feats)[source]

Compute the output image given the features. :param lqs: Input low quality (LQ) sequence with

shape (n, t, c, h, w).

Parameters

feats (dict) – The features from the propgation branches.

Returns

Output HR sequence with shape (n, t, c, 4h, 4w).

Return type

Tensor

class basicsr.archs.basicvsrpp_arch.SecondOrderDeformableAlignment(*args, **kwargs)[source]

Bases: ModulatedDeformConvPack

Second-order deformable alignment module. :param in_channels: Same as nn.Conv2d. :type in_channels: int :param out_channels: Same as nn.Conv2d. :type out_channels: int :param kernel_size: Same as nn.Conv2d. :type kernel_size: int or tuple[int] :param stride: Same as nn.Conv2d. :type stride: int or tuple[int] :param padding: Same as nn.Conv2d. :type padding: int or tuple[int] :param dilation: Same as nn.Conv2d. :type dilation: int or tuple[int] :param groups: Same as nn.Conv2d. :type groups: int :param bias: If specified as auto, it will be decided by the

norm_cfg. Bias will be set as True if norm_cfg is None, otherwise False.

Parameters

max_residue_magnitude (int) – The maximum magnitude of the offset residue (Eq. 6 in paper). Default: 10.

forward(x, extra_feat, flow_1, flow_2)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

init_offset()[source]
training: bool