Layers

class MaskedConv2d[source]

MaskedConv2d(c_in, c_out, ks, mask, stride=1, padding=None, d_cond:int=None) :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool

make_mask_a[source]

make_mask_a(ks:int)

make_mask_b[source]

make_mask_b(ks:int)

fig, axs = plt.subplots(1,2)
axs[0].imshow(make_mask_a(5).numpy())
axs[0].set_title("Type A mask")
axs[1].imshow(make_mask_b(5).numpy())
axs[1].set_title("Type B mask")
plt.show()

class SimplePixelCNN[source]

SimplePixelCNN(nh:int=64, ks:int=7, n_layers:int=8, d_cond:int=None, size=20) :: Module

Simple PixelCNN

x = torch.randn(4,1,8,8)
model = SimplePixelCNN()
out = model(x)
assert out.shape == x.shape
res = model.sample(n=4, d=8)
assert res.shape == (4,1,8,8)

class PixelCNNResBlock[source]

PixelCNNResBlock(c_in, c_out, ks, mask, stride=1, padding=None, d_cond:int=None) :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool

x = torch.randn(4,16,8,8)
m = PixelCNNResBlock(16, 16, 5, make_mask_b(5))
out = m(x)
assert out.shape == x.shape

class PixelCNN[source]

PixelCNN(nh:int=64, ks:int=7, n_layers:int=8, d_cond:int=None, size=20) :: Module

PixelCNN