def modify_lengths(self, lengths):

    def safe_param(elem):
        return (elem if isinstance(elem, int) else elem[0])
    for (name, layer) in self.net['convs'].named_children():
        if isinstance(layer, (nn.Conv2d, nn.MaxPool2d)):
            (p, k, s) = map(safe_param, [layer.padding, layer.kernel_size, layer.stride])
            lengths = ((((lengths + (2 * p)) - k) // s) + 1).long()
    return torch.where((lengths > 0), lengths, torch.tensor(1, device=lengths.device))
def modify_lengths(self, lengths):

    def safe_param(elem):
        return (elem if isinstance(elem, int) else elem[0])
    for (name, layer) in self.net['convs'].named_children():
        if isinstance(layer, (nn.Conv2d, nn.MaxPool2d)):
            (p, k, s) = map(safe_param, [layer.padding, layer.kernel_size, layer.stride])
            lengths = ((((lengths + (2 * p)) - k) // s) + 1).long()
    return torch.where((lengths > 0), lengths, torch.tensor(1, device=lengths.device))