Many thanks for your reply! Is this the sort of thing you mean?
class Autoencoder(torch.nn.Module):
               
    def __init__(self):
        super().__init__()
                
            
        self.conv1 = torch.nn.Conv2d(1,64,3,padding=1) 
        self.conv2 = torch.nn.Conv2d(64,128,3,padding=1)
        self.conv3 = torch.nn.Conv2d(128,256,3,padding=1)
        self.relu = torch.nn.ReLU()
        self.mp = torch.nn.MaxPool2d(2,return_indices=True)
        self.up = torch.nn.MaxUnpool2d(2)
        self.trans1 = torch.nn.ConvTranspose2d(256,128,3,padding=1)
        self.trans2 = torch.nn.ConvTranspose2d(128,64,3,padding=1)
        self.trans3 = torch.nn.ConvTranspose2d(64,1,3,padding=1)

def forward(self,x):
        x = self.conv1(x)
        x = self.relu(x)
        x, ind1 = self.mp(x)
        x = self.conv2(x)
        x = self.relu(x)
        x = self.conv3(x)
        x = self.relu(x)
        x, ind2 = self.mp(x)
        
        x = self.up(x, ind2)
        x = self.relu(x)
        x = self.trans1(x)
        x = self.up(x, ind1)
        x = self.relu(x)
        x = self.trans2(x)
        x = self.relu(x)
        x = self.trans3(x)
        x = self.relu(x)

        return x

It produces a shape error at x = self.up(x, ind1) but it might be working up to then…