Shortcuts

mmagic.models.editors.ttsr.ttsr_net

Module Contents

Classes

TTSRNet

TTSR network structure (main-net) for reference-based super-resolution.

SFE

Structural Feature Encoder.

CSFI2

Cross-Scale Feature Integration between 1x and 2x features.

CSFI3

Cross-Scale Feature Integration between 1x, 2x, and 4x features.

MergeFeatures

Merge Features. Merge 1x, 2x, and 4x features.

Attributes

_conv3x3_layer

_conv1x1_layer

mmagic.models.editors.ttsr.ttsr_net._conv3x3_layer[source]
mmagic.models.editors.ttsr.ttsr_net._conv1x1_layer[source]
class mmagic.models.editors.ttsr.ttsr_net.TTSRNet(in_channels, out_channels, mid_channels=64, texture_channels=64, num_blocks=(16, 16, 8, 4), res_scale=1.0, init_cfg=None)[source]

Bases: mmengine.model.BaseModule

TTSR network structure (main-net) for reference-based super-resolution.

Paper: Learning Texture Transformer Network for Image Super-Resolution

Adapted from ‘https://github.com/researchmm/TTSR.git’ ‘https://github.com/researchmm/TTSR’ Copyright permission at ‘https://github.com/researchmm/TTSR/issues/38’.

Parameters
  • in_channels (int) – Number of channels in the input image

  • out_channels (int) – Number of channels in the output image

  • mid_channels (int) – Channel number of intermediate features. Default: 64

  • texture_channels (int) – Number of texture channels. Default: 64.

  • num_blocks (tuple[int]) – Block numbers in the trunk network. Default: (16, 16, 8, 4)

  • res_scale (float) – Used to scale the residual in residual block. Default: 1.

  • init_cfg (dict, optional) – Initialization config dict.

forward(x, soft_attention, textures)[source]

Forward function.

Parameters
  • x (Tensor) – Input tensor with shape (n, c, h, w).

  • soft_attention (Tensor) – Soft-Attention tensor with shape (n, 1, h, w).

  • textures (Tuple[Tensor]) – Transferred HR texture tensors. [(N, C, H, W), (N, C/2, 2H, 2W), …]

Returns

Forward results.

Return type

Tensor

class mmagic.models.editors.ttsr.ttsr_net.SFE(in_channels, mid_channels, num_blocks, res_scale)[source]

Bases: torch.nn.Module

Structural Feature Encoder.

Backbone of Texture Transformer Network for Image Super-Resolution.

Parameters
  • in_channels (int) – Number of channels in the input image

  • mid_channels (int) – Channel number of intermediate features

  • num_blocks (int) – Block number in the trunk network

  • res_scale (float) – Used to scale the residual in residual block. Default: 1.

forward(x)[source]

Forward function.

Parameters

x (Tensor) – Input tensor with shape (n, c, h, w).

Returns

Forward results.

Return type

Tensor

class mmagic.models.editors.ttsr.ttsr_net.CSFI2(mid_channels)[source]

Bases: torch.nn.Module

Cross-Scale Feature Integration between 1x and 2x features.

Cross-Scale Feature Integration in Texture Transformer Network for

Image Super-Resolution.

It is cross-scale feature integration between 1x and 2x features.

For example, conv2to1 means conv layer from 2x feature to 1x feature. Down-sampling is achieved by conv layer with stride=2, and up-sampling is achieved by bicubic interpolate and conv layer.

Parameters

mid_channels (int) – Channel number of intermediate features

forward(x1, x2)[source]

Forward function.

Parameters
  • x1 (Tensor) – Input tensor with shape (n, c, h, w).

  • x2 (Tensor) – Input tensor with shape (n, c, 2h, 2w).

Returns

Output tensor with shape (n, c, h, w). x2 (Tensor): Output tensor with shape (n, c, 2h, 2w).

Return type

x1 (Tensor)

class mmagic.models.editors.ttsr.ttsr_net.CSFI3(mid_channels)[source]

Bases: torch.nn.Module

Cross-Scale Feature Integration between 1x, 2x, and 4x features.

Cross-Scale Feature Integration in Texture Transformer Network for

Image Super-Resolution.

It is cross-scale feature integration between 1x and 2x features.

For example, conv2to1 means conv layer from 2x feature to 1x feature. Down-sampling is achieved by conv layer with stride=2, and up-sampling is achieved by bicubic interpolate and conv layer.

Parameters

mid_channels (int) – Channel number of intermediate features

forward(x1, x2, x4)[source]

Forward function.

Parameters
  • x1 (Tensor) – Input tensor with shape (n, c, h, w).

  • x2 (Tensor) – Input tensor with shape (n, c, 2h, 2w).

  • x4 (Tensor) – Input tensor with shape (n, c, 4h, 4w).

Returns

Output tensor with shape (n, c, h, w). x2 (Tensor): Output tensor with shape (n, c, 2h, 2w). x4 (Tensor): Output tensor with shape (n, c, 4h, 4w).

Return type

x1 (Tensor)

class mmagic.models.editors.ttsr.ttsr_net.MergeFeatures(mid_channels, out_channels)[source]

Bases: torch.nn.Module

Merge Features. Merge 1x, 2x, and 4x features.

Final module of Texture Transformer Network for Image Super-Resolution.

Parameters
  • mid_channels (int) – Channel number of intermediate features

  • out_channels (int) – Number of channels in the output image

forward(x1, x2, x4)[source]

Forward function.

Parameters
  • x1 (Tensor) – Input tensor with shape (n, c, h, w).

  • x2 (Tensor) – Input tensor with shape (n, c, 2h, 2w).

  • x4 (Tensor) – Input tensor with shape (n, c, 4h, 4w).

Returns

Output tensor with shape (n, c_out, 4h, 4w).

Return type

x (Tensor)

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.