<jupyter_start><jupyter_text>https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html<jupyter_code>class Discriminator(nn.Module):
    def __init__(self, ngpu):
        super(Discriminator, self).__init__()
        self.ngpu = ngpu
        self.main = nn.Sequential(
            # input is (nc) x 64 x 64
            nn.Conv2d(nc, ndf, 4, 2, 1, bias=False),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf) x 32 x 32
            nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 2),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf*2) x 16 x 16
            nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 4),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf*4) x 8 x 8
            nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 8),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf*8) x 4 x 4
            nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False),
            nn.Sigmoid()
        )

    def forward(self, input):
        return self.main(input)
import torch
import torch.nn as nn<jupyter_output><empty_output><jupyter_text>class Discriminator(nn.Module):    def __init__(self, ngpu):        super(Discriminator, self).__init__()        self.ngpu = ngpu        self.main = nn.Sequential(             input is (nc) x 64 x 64            nn.Conv2d(nc,ndf , 4, 2, 1, bias=False),            nn.LeakyReLU(0.2, inplace=True),             state size. (ndf) x 32 x 32            nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),            nn.BatchNorm2d(ndf * 2),            nn.LeakyReLU(0.2, inplace=True),             state size. (ndf*2) x 16 x 16            nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),            nn.BatchNorm2d(ndf * 4),            nn.LeakyReLU(0.2, inplace=True),             state size. (ndf*4) x 8 x 8            nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),            nn.BatchNorm2d(ndf * 8),            nn.LeakyReLU(0.2, inplace=True),             state size. (ndf*8) x 4 x 4            nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False),            nn.Sigmoid()        )    def forward(self, input):        return self.main(input) nc - number of color **channels** in the input images. For color images this is 3ndf - sets the depth of feature maps propagated through the discriminator https://pytorch.org/docs/master/generated/torch.nn.BatchNorm2d.htmlnum_features – CC from an expected input of size (N, C, H, W)<jupyter_code>class D_block(nn.Module):
        def __init__(self, channels, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                channels, ndf, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d(ndf)
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))<jupyter_output><empty_output><jupyter_text>class D_block(nn.Block):    def __init__(self, channels, kernel_size=4, strides=2,                 padding=1, alpha=0.2, **kwargs):        super(D_block, self).__init__(**kwargs)        self.conv2d = nn.Conv2D(            channels, kernel_size, strides, padding, use_bias=False)        self.batch_norm = nn.BatchNorm()        self.activation = nn.LeakyReLU(alpha)    def forward(self, X):        return self.activation(self.batch_norm(self.conv2d(X)))<jupyter_code>x = torch.zeros((2, 3, 16, 16))
d_blk = D_block(20)
d_blk(x).shapex = np.zeros((2, 3, 16, 16))
d_blk = D_block(20)
d_blk.initialize()
d_blk(x).shape<jupyter_output><empty_output><jupyter_text>n_D = 64 https://towardsdatascience.com/how-to-build-a-dcgan-with-pytorch-31bfbf2ad96ahttps://stackoverflow.com/questions/60591140/i-dont-understand-pytorch-input-sizes-of-conv1d-conv2d<jupyter_code>class D_block(nn.Module):
        def __init__(self, channels, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                channels, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d()
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))<jupyter_output><empty_output><jupyter_text>https://towardsdatascience.com/residual-network-implementing-resnet-a7da63c7b278<jupyter_code>class D_block(nn.Module):
        def __init__(self, channels, ndf, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                channels, ndf, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d()
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))
x = torch.zeros((2, 3, 16, 16))
d_blk = D_block(20)
d_blk(x).shap
class D_block(nn.Module):
        def __init__(self, channels, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                channels, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d()
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))
x = torch.zeros((2, 3, 16, 16))
d_blk = D_block(20)
d_blk(x).shape<jupyter_output><empty_output><jupyter_text>https://discuss.pytorch.org/t/understanding-conv2d-and-convtranspose2d/42142<jupyter_code>class D_block(nn.Module):
        def __init__(self, channels, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                channels, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d(channels)
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))
x = torch.zeros((2, 3, 16, 16))
d_blk = D_block(20)
d_blk(x).shape
class D_block(nn.Module):
        def __init__(self, nc=3, channels, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                nc, channels, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d(channels)
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))
class D_block(nn.Module):
        def __init__(self, channels, nc=3, kernel_size=4, strides=2,
                 padding=1, alpha=0.2, **kwargs):
            super(D_block, self).__init__(**kwargs)
            self.conv2d = nn.Conv2d(
                nc, channels, kernel_size, strides, padding, bias=False)
            self.batch_norm = nn.BatchNorm2d(channels)
            self.activation = nn.LeakyReLU(alpha, inplace=True)

        def forward(self, X):
            return self.activation(self.batch_norm(self.conv2d(X)))
x = torch.zeros((2, 3, 16, 16))
d_blk = D_block(20)
d_blk(x).shape<jupyter_output><empty_output><jupyter_text>https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html<jupyter_code>n_D = 64
net_D = nn.Sequential(
    D_block(n_D),    # Output: (64, 32, 32)
    D_block(n_D*2),  # Output: (64 * 2, 16, 16)
    D_block(n_D*4),  # Output: (64 * 4, 8, 8)
    D_block(n_D*8),  # Output: (64 * 8, 4, 4)
    nn.Conv2d(3, 1, kernel_size=4, bias=False)  # Output: (1, 1, 1)
)
x = torch.zeros((1, 3, 64, 64))
net_D(x).shape
def nn.Conv2D(channels, nc=3, kernel_size, use_bias):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)
def nn.Conv2D(channels, kernel_size, use_bias, nc=3,):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)
def nn.Conv2D(channels, kernel_size, use_bias, nc=3):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)
def Conv2D(channels, kernel_size, use_bias, nc=3):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)
n_D = 64
net_D = nn.Sequential(
    D_block(n_D),    # Output: (64, 32, 32)
    D_block(n_D*2),  # Output: (64 * 2, 16, 16)
    D_block(n_D*4),  # Output: (64 * 4, 8, 8)
    D_block(n_D*8),  # Output: (64 * 8, 4, 4)
    Conv2d(3, 1, kernel_size=4, bias=False)  # Output: (1, 1, 1)
)
def Conv2d(channels, kernel_size, use_bias, nc=3):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)
n_D = 64
net_D = nn.Sequential(
    D_block(n_D),    # Output: (64, 32, 32)
    D_block(n_D*2),  # Output: (64 * 2, 16, 16)
    D_block(n_D*4),  # Output: (64 * 4, 8, 8)
    D_block(n_D*8),  # Output: (64 * 8, 4, 4)
    Conv2d(3, 1, kernel_size=4, bias=False)  # Output: (1, 1, 1)
)
n_D = 64
net_D = nn.Sequential(
    D_block(n_D),    # Output: (64, 32, 32)
    D_block(n_D*2),  # Output: (64 * 2, 16, 16)
    D_block(n_D*4),  # Output: (64 * 4, 8, 8)
    D_block(n_D*8),  # Output: (64 * 8, 4, 4)
    Conv2d(1, kernel_size=4, bias=False)  # Output: (1, 1, 1)
)
n_D = 64
net_D = nn.Sequential(
    D_block(n_D),    # Output: (64, 32, 32)
    D_block(n_D*2),  # Output: (64 * 2, 16, 16)
    D_block(n_D*4),  # Output: (64 * 4, 8, 8)
    D_block(n_D*8),  # Output: (64 * 8, 4, 4)
    Conv2d(1, kernel_size=4, use_bias=False)  # Output: (1, 1, 1)
)
x = torch.zeros((1, 3, 64, 64))
net_D(x).shape
def Conv2d(channels, kernel_size, use_bias, nc=3):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)
def Conv2D(channels, kernel_size, use_bias, nc=3):
    return nn.Conv2d(nc, channels, kernel_size=kernel_size, bias=use_bias)

n_D = 64
net_D = nn.Sequential(
    D_block(n_D),    # Output: (64, 32, 32)
    D_block(n_D*2),  # Output: (64 * 2, 16, 16)
    D_block(n_D*4),  # Output: (64 * 4, 8, 8)
    D_block(n_D*8),  # Output: (64 * 8, 4, 4)
    Conv2D(1, kernel_size=4, use_bias=False)  # Output: (1, 1, 1)
)
x = torch.zeros((1, 3, 64, 64))
net_D(x).shape
d_blk(x).shape
d_blk(x).shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1484508648545904, 'fraction_numerical': 0.04951530127352215, 'mean_word_length': 2.8099203475742214, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '192119', 'license': 'MIT', 'n_tokens_mistral': 4386, 'n_tokens_neox': 4026, 'n_words': 824, 'path': 'chapter-generative-adversarial-networks/D_block.ipynb', 'repo_name': 'dltech-xyz/d2l-en-read', 'size': '10522'}