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


class FleetwoodNet9V1(nn.Module):
    def __init__(
        self,
        num_classes,
        init_weights=True,
    ):
        super().__init__()
        # Convolutional Layers
        self.features = nn.Sequential(
            nn.Conv2d(1, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            
            nn.Conv2d(64, 128, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            
            nn.Conv2d(128, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            
            nn.Conv2d(256, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
        )
        
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        
        # Fully-connected classification layers
        self.classifier = nn.Sequential(
            nn.Linear(512 * 14 * 14, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, num_classes),
        )
        
        if init_weights:
            self._initialize_weights()

    def forward(self, x):
        x = self.features(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.classifier(x)
        return F.softmax(x, dim=1)

    def _initialize_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)
23085659a793b7f7640916e1b0afcb19eb0472f9
<mask token>


class FleetwoodNet9V1(nn.Module):

    def __init__(self, num_classes, init_weights=True):
        super().__init__()
        self.features = nn.Sequential(nn.Conv2d(1, 64, kernel_size=3,
            padding=1), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=2,
            stride=2), nn.Conv2d(64, 128, kernel_size=3, padding=1), nn.
            ReLU(inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.
            Conv2d(128, 256, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.Conv2d(256, 256, kernel_size=3, padding=1), nn.ReLU(
            inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.Conv2d
            (256, 512, kernel_size=3, padding=1), nn.ReLU(inplace=True), nn
            .Conv2d(512, 512, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.MaxPool2d(kernel_size=2, stride=2))
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        self.classifier = nn.Sequential(nn.Linear(512 * 14 * 14, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, num_classes))
        if init_weights:
            self._initialize_weights()
    <mask token>
    <mask token>

<mask token>


class FleetwoodNet9V1(nn.Module):

    def __init__(self, num_classes, init_weights=True):
        super().__init__()
        self.features = nn.Sequential(nn.Conv2d(1, 64, kernel_size=3,
            padding=1), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=2,
            stride=2), nn.Conv2d(64, 128, kernel_size=3, padding=1), nn.
            ReLU(inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.
            Conv2d(128, 256, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.Conv2d(256, 256, kernel_size=3, padding=1), nn.ReLU(
            inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.Conv2d
            (256, 512, kernel_size=3, padding=1), nn.ReLU(inplace=True), nn
            .Conv2d(512, 512, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.MaxPool2d(kernel_size=2, stride=2))
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        self.classifier = nn.Sequential(nn.Linear(512 * 14 * 14, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, num_classes))
        if init_weights:
            self._initialize_weights()
    <mask token>

    def _initialize_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out',
                    nonlinearity='relu')
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)

<mask token>


class FleetwoodNet9V1(nn.Module):

    def __init__(self, num_classes, init_weights=True):
        super().__init__()
        self.features = nn.Sequential(nn.Conv2d(1, 64, kernel_size=3,
            padding=1), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=2,
            stride=2), nn.Conv2d(64, 128, kernel_size=3, padding=1), nn.
            ReLU(inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.
            Conv2d(128, 256, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.Conv2d(256, 256, kernel_size=3, padding=1), nn.ReLU(
            inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.Conv2d
            (256, 512, kernel_size=3, padding=1), nn.ReLU(inplace=True), nn
            .Conv2d(512, 512, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.MaxPool2d(kernel_size=2, stride=2))
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        self.classifier = nn.Sequential(nn.Linear(512 * 14 * 14, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, num_classes))
        if init_weights:
            self._initialize_weights()

    def forward(self, x):
        x = self.features(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.classifier(x)
        return F.softmax(x, dim=1)

    def _initialize_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out',
                    nonlinearity='relu')
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)

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


class FleetwoodNet9V1(nn.Module):

    def __init__(self, num_classes, init_weights=True):
        super().__init__()
        self.features = nn.Sequential(nn.Conv2d(1, 64, kernel_size=3,
            padding=1), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=2,
            stride=2), nn.Conv2d(64, 128, kernel_size=3, padding=1), nn.
            ReLU(inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.
            Conv2d(128, 256, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.Conv2d(256, 256, kernel_size=3, padding=1), nn.ReLU(
            inplace=True), nn.MaxPool2d(kernel_size=2, stride=2), nn.Conv2d
            (256, 512, kernel_size=3, padding=1), nn.ReLU(inplace=True), nn
            .Conv2d(512, 512, kernel_size=3, padding=1), nn.ReLU(inplace=
            True), nn.MaxPool2d(kernel_size=2, stride=2))
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        self.classifier = nn.Sequential(nn.Linear(512 * 14 * 14, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, 4096), nn.
            ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, num_classes))
        if init_weights:
            self._initialize_weights()

    def forward(self, x):
        x = self.features(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.classifier(x)
        return F.softmax(x, dim=1)

    def _initialize_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out',
                    nonlinearity='relu')
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)

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


class FleetwoodNet9V1(nn.Module):
    def __init__(
        self,
        num_classes,
        init_weights=True,
    ):
        super().__init__()
        # Convolutional Layers
        self.features = nn.Sequential(
            nn.Conv2d(1, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            
            nn.Conv2d(64, 128, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            
            nn.Conv2d(128, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            
            nn.Conv2d(256, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
        )
        
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        
        # Fully-connected classification layers
        self.classifier = nn.Sequential(
            nn.Linear(512 * 14 * 14, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, num_classes),
        )
        
        if init_weights:
            self._initialize_weights()

    def forward(self, x):
        x = self.features(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.classifier(x)
        return F.softmax(x, dim=1)

    def _initialize_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)