"""Classify a print patch by its correcting quarter-turn and optional reflection.""" from torch import nn class PatchOrient(nn.Sequential): def __init__(self, classes=4): layers = [] previous = 1 for channels in (16, 24, 48, 64): for stride in (2, 1): layers.extend( [ nn.Conv2d( previous, channels, 3, stride=stride, padding=1, bias=False ), nn.BatchNorm2d(channels), nn.ReLU(), ] ) previous = channels super().__init__( *layers, nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(previous, classes) )