Shortcuts

Note

You are reading the documentation for MMEditing 0.x, which will soon be deprecated by the end of 2022. We recommend you upgrade to MMEditing 1.0 to enjoy fruitful new features and better performance brought by OpenMMLab 2.0. Check out the changelog, code and documentation of MMEditing 1.0 for more details.

Source code for mmedit.models.common.img_normalize

# Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn


[docs]class ImgNormalize(nn.Conv2d): """Normalize images with the given mean and std value. Based on Conv2d layer, can work in GPU. Args: pixel_range (float): Pixel range of feature. img_mean (Tuple[float]): Image mean of each channel. img_std (Tuple[float]): Image std of each channel. sign (int): Sign of bias. Default -1. """ def __init__(self, pixel_range, img_mean, img_std, sign=-1): assert len(img_mean) == len(img_std) num_channels = len(img_mean) super().__init__(num_channels, num_channels, kernel_size=1) std = torch.Tensor(img_std) self.weight.data = torch.eye(num_channels).view( num_channels, num_channels, 1, 1) self.weight.data.div_(std.view(num_channels, 1, 1, 1)) self.bias.data = sign * pixel_range * torch.Tensor(img_mean) self.bias.data.div_(std) self.weight.requires_grad = False self.bias.requires_grad = False
Read the Docs v: latest
Versions
latest
stable
1.x
v0.16.0
v0.15.2
v0.15.1
v0.15.0
v0.14.0
v0.13.0
v0.12.0
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.