import torch.nn as nn from huggingface_hub import PyTorchModelHubMixin class ModelColorization(nn.Module, PyTorchModelHubMixin): def __init__(self): super(ModelColorization, self).__init__() self.encoder = nn.Sequential( nn.Conv2d(1, 64, kernel_size=3, stride=1, padding=1), nn.MaxPool2d(kernel_size=2, stride=2), nn.ReLU(), nn.BatchNorm2d(64), nn.Conv2d(64, 32, kernel_size=3, stride=1, padding=1), nn.MaxPool2d(kernel_size=2, stride=2), nn.ReLU(), nn.BatchNorm2d(32), nn.Conv2d(32, 16, kernel_size=3, stride=1, padding=1), nn.MaxPool2d(kernel_size=2, stride=2), nn.ReLU(), nn.BatchNorm2d(16), nn.Flatten(), nn.Linear(16*45*45, 4000), ) self.decoder = nn.Sequential( nn.Linear(4000, 16 * 45 * 45), nn.ReLU(), nn.Unflatten(1, (16, 45, 45)), nn.ConvTranspose2d(16, 32, kernel_size=3, stride=2, padding=1, output_padding=1), nn.ReLU(), nn.BatchNorm2d(32), nn.ConvTranspose2d(32, 64, kernel_size=3, stride=2, padding=1, output_padding=1), nn.ReLU(), nn.BatchNorm2d(64), nn.ConvTranspose2d(64, 3, kernel_size=3, stride=2, padding=1, output_padding=1), nn.Sigmoid() ) def forward(self, x): x = self.encoder(x) x = self.decoder(x) return x