| 299 | self.fake_H = predicted_image |
| 300 | self.netG.train() |
| 301 | def test(self): |
| 302 | self.netG.eval() |
| 303 | with torch.no_grad(): |
| 304 | # deg_image = self.var_L# /255.0 |
| 305 | |
| 306 | deg_image = np.array(cv2.imread(self.de_path[0],cv2.IMREAD_UNCHANGED))/255 |
| 307 | print('read:',np.max(deg_image), np.min(deg_image)) |
| 308 | h,w,_ = deg_image.shape |
| 309 | if(h<384): |
| 310 | cv2.resize(deg_image, (w, 384)) |
| 311 | h = 384 |
| 312 | if(w<384): |
| 313 | cv2.resize(deg_image, (384,h)) |
| 314 | w = 384 |
| 315 | while w%4!=0: |
| 316 | w+=1 |
| 317 | while h%4!=0: |
| 318 | h+=1 |
| 319 | deg_image = cv2.resize(deg_image,(w,h)) |
| 320 | print(deg_image.shape) |
| 321 | print('resize:',np.max(deg_image), np.min(deg_image)) |
| 322 | |
| 323 | test_image = deg_image |
| 324 | print('deg_images.shape:', test_image.shape) |
| 325 | h = ((test_image.shape [0] // 256) +1)*256 |
| 326 | w = ((test_image.shape [1] // 256 ) +1)*256 |
| 327 | |
| 328 | test_padding = np.zeros((h,w,3))+1 |
| 329 | test_padding[:test_image.shape[0],:test_image.shape[1]]=test_image |
| 330 | |
| 331 | test_image_p=self.split2(test_padding.reshape(1,h,w,3),1,h,w) |
| 332 | #print('p:', test_image_p.shape) |
| 333 | predicted_list=[] |
| 334 | for l in range(test_image_p.shape[0]): |
| 335 | #print("patch shape:",np.transpose(test_image_p[l], [2,0,1]).shape) |
| 336 | tmp = np.transpose(test_image_p[l], [2,0,1]) |
| 337 | tmp = torch.from_numpy(tmp).reshape(1,3,256,256).float() |
| 338 | #print(tmp.shape) |
| 339 | self.netG(tmp) |
| 340 | |
| 341 | # for torch : 1.7.1 |
| 342 | predict = self.netG(tmp)[0].squeeze().permute((1,2,0)).cpu().numpy() |
| 343 | # else : |
| 344 | # predict = torch.permute(self.netG(tmp)[0].squeeze(), (1,2,0)).cpu().numpy() |
| 345 | |
| 346 | #print(predict.shape) |
| 347 | predicted_list.append(predict) |
| 348 | |
| 349 | predicted_image = np.array(predicted_list)#.reshape() |
| 350 | predicted_image=self.merge_image2(predicted_image,h,w) |
| 351 | |
| 352 | # if training |
| 353 | predicted_image = (predicted_image[:,:]>0.95)*1 |
| 354 | |
| 355 | predicted_image=(predicted_image[:test_image.shape[0],:test_image.shape[1]]*255).round() |
| 356 | print('predicted shape:', predicted_image.shape) |
| 357 | print(predicted_image) |
| 358 | |