MCPcopy Create free account
hub / github.com/RylonW/DocNLC / val

Method val

models/SIEN_model.py:238–300  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

236 ind=ind+1
237 return np.array(image)
238 def val(self):
239 self.netG.eval()
240 with torch.no_grad():
241 # deg_image = self.var_L# /255.0
242
243 deg_image = np.array(cv2.imread(self.de_path[0],cv2.IMREAD_UNCHANGED))/255
244 print('read:',np.max(deg_image), np.min(deg_image))
245 h,w,_ = deg_image.shape
246 if(h<384):
247 cv2.resize(deg_image, (w, 384))
248 h = 384
249 if(w<384):
250 cv2.resize(deg_image, (384,h))
251 w = 384
252 while w%4!=0:
253 w+=1
254 while h%4!=0:
255 h+=1
256 deg_image = cv2.resize(deg_image,(w,h))
257 print(deg_image.shape)
258 print('resize:',np.max(deg_image), np.min(deg_image))
259
260 test_image = deg_image
261 print('deg_images.shape:', test_image.shape)
262 h = ((test_image.shape [0] // 256) +1)*256
263 w = ((test_image.shape [1] // 256 ) +1)*256
264
265 test_padding = np.zeros((h,w,3))+1
266 test_padding[:test_image.shape[0],:test_image.shape[1]]=test_image
267
268 test_image_p=self.split2(test_padding.reshape(1,h,w,3),1,h,w)
269 #print('p:', test_image_p.shape)
270 predicted_list=[]
271 for l in range(test_image_p.shape[0]):
272 #print("patch shape:",np.transpose(test_image_p[l], [2,0,1]).shape)
273 tmp = np.transpose(test_image_p[l], [2,0,1])
274 tmp = torch.from_numpy(tmp).reshape(1,3,256,256).float()
275 #print(tmp.shape)
276 self.netG(tmp)
277
278 # for torch : 1.7.1
279 predict = self.netG(tmp)[0].squeeze().permute((1,2,0)).cpu().numpy()
280 # else :
281 # predict = torch.permute(self.netG(tmp)[0].squeeze(), (1,2,0)).cpu().numpy()
282
283 #print(predict.shape)
284 predicted_list.append(predict)
285
286 predicted_image = np.array(predicted_list)#.reshape()
287 predicted_image=self.merge_image2(predicted_image,h,w)
288
289 # if training with threshold
290 # predicted_image = (predicted_image[:,:]>0.95)*1
291
292 predicted_image=(predicted_image[:test_image.shape[0],:test_image.shape[1]]*255).round()
293 print('predicted shape:', predicted_image.shape)
294 print(predicted_image)
295

Callers 2

mainFunction · 0.45
mainFunction · 0.45

Calls 2

split2Method · 0.95
merge_image2Method · 0.95

Tested by

no test coverage detected