Skip to content

INN.ResizeFeatures

Zhang Yanbo edited this page Oct 28, 2022 · 3 revisions

CLASS INN.ResizeFeatures(feature_in, feature_out, dist='normal') [source]

Resize the features of input, for n-d input, include linear or multi-channel inputs. This will turn [N, feature_in, *] to [N, feature_out, *] by abandoning feature_in - feature_out dimensions. The inverse process will fill the feature_in - feature_out dimensions from dist distribution.

  • feature_in: input feature dimension
  • feature_out: output feature dimension. feature_out < feature_in. This layer will abandon some number of features so we can resize the inputs.
  • dist: distribution model ('normal' or INN.INNAbstract.Distribution modules). This will defines how it computes the log-probability of abandoned dimensions.

Methods

forward(input, log_p0=0, log_det_J_=0)

Compute the result y. If compute_p=True, it will return y, logp and log_detJ.

inverse(y, **args)

Compute the inverse of y. **args is only a place-holder for consistency. When doing inverse, the abandoned dimensions will be generated by sampling from the dist distribution.

import INN
import torch

model = INN.ResizeFeatures(feature_in=3, feature_out=1)

x = torch.Tensor([[1,2,3],
                  [4,5,6],
                  [7,8,9]])

y, logp, logdet = model(x)
print(y)

x_hat = model.inverse(y)
print(x_hat)


'''Result
# y = model(x)
tensor([[1.],
        [4.],
        [7.]])
# x_hat = model.inverse(y)
tensor([[ 1.0000,  1.5800, -0.6237],
        [ 4.0000,  0.5238,  0.3988],
        [ 7.0000,  1.0111, -0.0900]])
'''