Jacky_Liu:

r_out2 = self.linear(r_out[:, -1, :])


@ptrblck any opinion of yours here… i built it this way ,dfference in every discussion it is assumed that dataset input is seq ,bs,c,h,w  but i simply do view . Last output of lstm in every forum i seen is  seq len,bs,no of element feature.
My doubt is with this shape how can we compute the loss?
M i using lstm well with this architecture?
 (head): Head(
    (fc): Sequential(
      (0): GeM(p={:.4f}
      (1): Flatten()
      (2): BatchNorm1d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (3): Dropout(p=0.5, inplace=False)
      (4): Linear(in_features=2048, out_features=1024, bias=True)
      (5): Mish()
    )
  )
  (lstm): lstm(
    (lstm): LSTM(1024, 512, num_layers=2, batch_first=True)
    (drop): Dropout(p=0.5, inplace=False)
  )
  (linear): Linear(in_features=512, out_features=2, bias=True)
)

class Rnxt(nn.Module):
    def __init__(self, arch='resnext50_32x4d_ssl', n=1, pre=True, ps=0.5):
        super().__init__()
        m = torch.hub.load('facebookresearch/semi-supervised-ImageNet1K-models', arch,True)
        #m = torch.load('/home/temp/.cache/torch/checkpoints/semi_supervised_resnext50_32x4-ddb3e555.pth', arch)
        
        self.layer0 = nn.Sequential(m.conv1, m.bn1, nn.ReLU(inplace=True))
        self.layer1 = nn.Sequential(
            nn.MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False),
            m.layer1)
        self.layer2 = m.layer2
        self.layer3 = m.layer3
        self.layer4 = m.layer4
        
        nc = 2048
        self.head = Head(nc,n,ps=ps)
        self.lstm=lstm(16,12)#seq len and num of frames
        self.linear=nn.Linear(512,2)
    def forward(self, x):    
        #x =  F.interpolate(x, scale_factor=2, mode='bilinear')
        shape=x.shape[0]
        x = self.layer0(x)
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        x = self.head(x)
        #print('x',x.size())
        x=self.lstm(x).contiguous()
        #print('x',x.size())
        
        x=x.view(x.shape[0]*x.shape[1],512).contiguous()# 
        #print(x.size())
        if x.size(0)!=shape: #incase last few batches have different sizes
            x=x[0:shape,:]
        x=self.linear(x)
        
        return x

#lstm fwd
self.lstm = nn.LSTM(1024, 512 ,2,batch_first=True) #assume 16*12,1024 input
 def forward(self,input):
        #print(input.size(0))
        if input.size(0)!=self.batch*self.num:
            input=torch.cat([input,input[0:self.batch*self.num-input.size(0),:]],dim=0)
        x=input.view(self.batch,self.num,input.size(1)).contiguous()
         
        x,y=self.lstm(x)
        
        #x = x[:,-1,:]
        
        x=self.drop(x)
        return x