Concatenate two tensor for each timestep
<SCODE>def forward(...):
        ...
        z = Variable(torch.zeros(y.size(0), y.size(1), 1024))
        for i in range(z.size(0)):
            z[i] = torch.cat((y[i], x), 1)

        z = self.decoderGRU(z, init_decoder_GRU)
        decoded = self.classLinear(z.view(z.size(0)*z.size(1), z.size(2))) #error here.
        ...
<ECODE> Error message: <SCODE>AttributeError: 'tuple' object has no attribute 'view'
<ECODE> What is the best way to do this?
NgPDat
If so, this should do the trick for you and will be much more efficient: <SCODE># Replace the for loop with this line. It will expand x to be of size seqLen x batch x feature1
# and concatenate it with y in one go. 
z = torch.cat([y, x.unsqueeze(0).expand(seqLen, *x.size())], 2)
<ECODE> <SCODE>z = self.decoderGRU(z, init_decoder_GRU)[0]
<ECODE>
apaszke
Thank you. Both solve my problem. Never thought of using expand that way.
NgPDat
Hi, I wonder if it’s convenient for you to share your encoder-decoder code with me, as I am trying to implement a similar network?
chifish
Hi,
amy