Concatinate more imput Images in a Block

Hey Pytorch-Masters,

I want to feed more than one picture in one ConvBlock, so you can see it as one more than one shortcut in a Resnet. But I got an Exception like :

if in_channels % groups != 0:

RuntimeError: Boolean value of Tensor with more than one value is ambiguous

Thats my Block I am testing:

class three_ConvBlock(nn.Module):

def __init__(self, in_ch, out_ch, conv_index, customized_shortcut):
    super(three_ConvBlock, self).__init__()

    conv_index = nn.Parameter(conv_index)
    customized_shortcut = nn.Parameter(customized_shortcut)

    self.layer_1 = nn.Conv3d(in_ch,out_ch,3,stride=(1,1,1), padding=0)
    self.layer_2 = nn.Conv3d(in_ch,out_ch,3, stride=(1,1,1), padding=0)

def forward(self,x, conv_index, customized_shortcut):

    x_1 = self.layer_1(x)
    conv_index_out = x_1

    x_2 = torch.sub(x_1,customized_shortcut)
    x_2 =,conv_index))
    x_3 = self.layer_2(x_1)        

    #print(conv_index, customized_shortcut)
    return x_3 , conv_index_out

Image = torch.randint(10, (3,3,3),requires_grad=True,dtype=torch.float64)

a = torch.randint(5, (3,3,3),requires_grad=True,dtype=torch.float64)

b = torch.randint(4, (3,3,3),requires_grad=True,dtype=torch.float64)

test_layer = three_ConvBlock(Image,Image,conv_index=a,customized_shortcut=b)

result = test_layer(Image,conv_index=a,customized_shortcut=b)



Thanks for any advice!!!

You are trying to pass the image in a shape of [3, 3, 3] into the in_channels and out_channels arguments while ints or tuples or ints are expected.
Use the actual channel dimension and it should work:

test_layer = three_ConvBlock(Image.size(0),Image.size(1),conv_index=a,customized_shortcut=b)

Afterwards you will run into a shape mismatch error since nn.Conv3d layers expect an input with 5 dimensions representing [batch_size, channels, depth, height, width].

1 Like