Fundamentally I don’t think it is possible for a single conv2d transpose layer to accept any number of input channels, as the size of the weights depends on this parameter! What does it mean when we need more weights than we have, or when we want to ignore some existing weights due to the variation in input channels?
Instead, a workaround you might try is to simply define some number of conv2d_transpose layers ahead of time and to dispatch to the correct one depending on current shape.
For example:
def forward(self, x):
    if x.size(0) == size1:
        x = layer1(x)
    elif x.size(0) == size2:
        x = layer2(x)
...