My training code running good with around 8GB but when it goes into validation, it show me out of memory for 16GB GPU. I am using model.eval() and torch.no_grad() also but getting same. Here is my testing code for reference of testing which I am using in validation.
def test(self):
self.netG1.eval()
self.netG2.eval()
with torch.no_grad():
self.SR = self.netG1(self.var_L)
self.LR_est = self.netG2(self.SR)
self.DR = self.netG2(self.var_H)
self.HR_est = self.netG1(self.DR)
self.netG1.train()
self.netG2.train()
def get_current_visuals(self, need_HR=True):
out_dict = OrderedDict()
#out_dict[‘LR’] = self.var_L.detach()[0].float().cpu()
out_dict[‘SR’] = self.SR.detach()[0].float().cpu()
#out_dict[‘LR_est’] = self.LR_est.detach()[0].float().cpu()
if need_HR:
out_dict[‘HR’] = self.var_H.detach()[0].float().cpu()
#out_dict[‘DR’] = self.DR.detach()[0].float().cpu()
#out_dict[‘HR_Est’] = self.HR_est.detach()[0].float().cpu()
return out_dict
And my validation code is as bellow.
if current_step % opt[‘train’][‘val_freq’] == 0:
avg_psnr = 0.0
idx = 0
for val_data in val_loader:
idx += 1
img_name = os.path.splitext(os.path.basename(val_data[‘LR_path’][0]))[0]
img_dir = os.path.join(opt[‘path’][‘val_images’], img_name)
util.mkdir(img_dir)
                model.feed_data(val_data)
                model.test()

                visuals = model.get_current_visuals()
                sr_img = util.tensor2img(visuals['SR'])  # uint8
                gt_img = util.tensor2img(visuals['HR'])  # uint8

.
.
.
.
.
Waiting for any solution. Thanks in advance.