Mem buffers= 212904
Model Definition
class Sequential(nn.Module):
	def __init__(self,backend,seq_len,embed_size=512):
		super(Sequential,self).__init__()
		self.seq_len = seq_len
		self.bk_name = backend
		# defining backend 
		if self.bk_name == 'resnet':
			resnet = models.resnet50(pretrained=True)
			# self.dilate_resnet(resnet)
			self.init_resnet(resnet)
			self.encoder = nn.Linear(8192,embed_size,bias=True)
		elif self.bk_name == 'vgg':
			vgg = models.vgg19(pretrained=True) 
			self.init_vgg(vgg)
		else:
			assert 0, 'Backend not implemented'

		self.rnn = LSTM(embed_size)
		#print(self.rnn)
		#print("feature extracted")
		# self.rnn = G_LSTM(embed_size)
		# self.rnn = GRU(embed_size)
		self.decoder = nn.Linear(embed_size,1,bias=True)
		# self.decoder_extra = nn.Linear(embed_size,1024)
		# self.decoder = nn.Linear(1024,1,bias=True)

		#fixting saliency module
		for para in self.backend.parameters():
			para.requires_grad = True # fixing pretrained modules or not

	def init_resnet(self,resnet):
		self.backend = nn.Sequential(*list(resnet.children())[:-2])

	def init_vgg(self,vgg):
		# self.backend = vgg.features
		self.backend = nn.Sequential(*list(vgg.features.children())[:-1]) # omitting the last Max Pooling 

	def dilate_resnet(self, resnet): #modifying resnet as in SAM paper
		resnet.layer3[0].conv1.stride = 1
		resnet.layer3[0].downsample[0].stride = 1
		resnet.layer4[0].conv1.stride = 1
		resnet.layer4[0].downsample[0].stride = 1
		
		for block in resnet.layer3:
			block.conv2.dilation = 2
			block.conv2.padding = 2

		for block in resnet.layer4:
			block.conv2.dilation = 4
			block.conv2.padding = 4 

	def init_hidden(self,x): #initializing hidden state as all zero
		h = x.data.new().resize_as_(x.data).fill_(0)
		c = x.data.new().resize_as_(x.data).fill_(0)
		return (Variable(h),Variable(c))
		# return Variable(h) # return only h when using GRU

	def forward(self,x):
		batch, seq, c, h, w = x.size()
		x = x.view(batch*seq,c,h,w)
		# backend forward pass
		if self.bk_name == 'resnet':
			x = self.backend(x)
			x = F.avg_pool2d(x,(7,7)) # Global Average Pooling
			# x = F.max_pool2d(x,(7,7)) # Global Max Pooling
			x = x.view(batch*seq,-1)
			x = F.relu(self.encoder(F.dropout(x,p=0.4)))
		else:
			x = self.backend(x)
			x = F.avg_pool2d(x,(14,14)) # Global Average Pooling for vgg19 without final maxpool
		x = x.view(batch,seq,-1) # unroll features

		# recurrent loop
		state = self.init_hidden(x[:,0,:]) # initialize hidden state
		for i in range(self.seq_len):
			cur_x = x[:,i,:].contiguous()
			state = self.rnn(cur_x,state)

			
		h, c = state # LSTM
		x = torch.sigmoid(self.decoder(F.dropout(h,p=0.5)))
		
		return x