Buckets:

download
raw
1.72 kB
import torch.nn as nn
from typing import Dict, Any
from promethium.ml.models.base import PromethiumModel
from promethium.ml.models.registry import ModelRegistry
@ModelRegistry.register("autoencoder")
class Autoencoder(PromethiumModel):
"""
Convolutional Autoencoder for Denoising.
"""
def __init__(self, config: Dict[str, Any]):
super().__init__(config)
n_channels = config.get("n_channels", 1)
base_filters = config.get("base_filters", 32)
# Encoder
self.encoder = nn.Sequential(
nn.Conv2d(n_channels, base_filters, 3, stride=2, padding=1), # /2
nn.BatchNorm2d(base_filters),
nn.LeakyReLU(),
nn.Conv2d(base_filters, base_filters*2, 3, stride=2, padding=1), # /4
nn.BatchNorm2d(base_filters*2),
nn.LeakyReLU(),
nn.Conv2d(base_filters*2, base_filters*4, 3, stride=2, padding=1), # /8
nn.BatchNorm2d(base_filters*4),
nn.LeakyReLU(),
)
# Decoder
self.decoder = nn.Sequential(
nn.ConvTranspose2d(base_filters*4, base_filters*2, 3, stride=2, padding=1, output_padding=1), # *2
nn.BatchNorm2d(base_filters*2),
nn.LeakyReLU(),
nn.ConvTranspose2d(base_filters*2, base_filters, 3, stride=2, padding=1, output_padding=1), # *4
nn.BatchNorm2d(base_filters),
nn.LeakyReLU(),
nn.ConvTranspose2d(base_filters, n_channels, 3, stride=2, padding=1, output_padding=1), # *8
nn.Tanh() # Assuming normalized input [-1, 1]
)
def forward(self, x):
z = self.encoder(x)
out = self.decoder(z)
return out

Xet Storage Details

Size:
1.72 kB
·
Xet hash:
324dfbad3c639a9b1a8154d980daf97022651f767fb79b3f7f04a565f4664646

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.