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.
- Parameters:
lqs (tensor) – 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)’.
- Parameters:
lqs (tensor) – 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++.
- Parameters:
lqs (tensor) – 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.
- Parameters:
dict (feats) – Features from previous branches. Each component is a list of tensors with shape (n, c, h, w).
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¶
- class basicsr.archs.basicvsrpp_arch.SecondOrderDeformableAlignment(*args, **kwargs)[source]¶
Bases:
ModulatedDeformConvPack
Second-order deformable alignment module.
- Parameters:
in_channels (int) – Same as nn.Conv2d.
out_channels (int) – Same as nn.Conv2d.
kernel_size (int or tuple[int]) – Same as nn.Conv2d.
stride (int or tuple[int]) – Same as nn.Conv2d.
padding (int or tuple[int]) – Same as nn.Conv2d.
dilation (int or tuple[int]) – Same as nn.Conv2d.
groups (int) – Same as nn.Conv2d.
bias (bool or str) – 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.
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.
- training: bool¶