def test(self, valLoader, epoch): print( "*********************************test****************************" ) self.model.eval() avgLoss = 0 visImg = [] self.progbar = progbar(len(valLoader), width=self.opt.barwidth) print("valLoader : ", len(valLoader)) for i, (inputData, line, imgids) in enumerate(valLoader): if self.opt.debug and i > 10: break start = time.time() with torch.no_grad(): inputData_var, line_var = Variable(inputData), Variable(line) #print(inputData_var.shape, ' ', line_var.shape) if self.opt.GPU: inputData_var = inputData_var.cuda() line_var = line_var.cuda() dataTime = time.time() - start loss, line_loss, line_result = self.model.forward( inputData_var, line_var) #print(line_result) img_line = line[0][0].numpy() ''' img_origin imshow img_origin = inputData[0].numpy() print(line_result.shape) mean = np.array([0.485, 0.456, 0.406]) std = np.array([0.229, 0.224, 0.225]) img_origin = np.transpose(img_origin, (1, 2, 0)) img_origin = t.unNormalize(img_origin, mean, std) ''' mean = np.array([0.485, 0.456, 0.406]) std = np.array([0.229, 0.224, 0.225]) img_result = line_result[0].cpu().detach().numpy() print(np.min(img_result), ' ', np.max(img_result)) img_result_plt = line_result[0][0].cpu().detach().numpy() img_result = np.transpose(img_result, (1, 2, 0)) img_result = t.unNormalize(img_result, mean, std) print(img_result) print(np.min(img_result), ' ', np.max(img_result)) img_result = np.clip(img_result, 0, 255) img_result = np.uint8(img_result) #print(img_result) img_result = cv2.resize(img_result, dsize=(320, 320), interpolation=cv2.INTER_LANCZOS4) cv2.imshow("Gray", img_result) cv2.waitKey(30000) #print(img_result) #print(img_result.shape) #plt.figure(1) #plt.axis("off") # cv2.imshow("Gray",img_result) #plt.imshow(img_result_plt,cmap="gray") # plt.imshow(cv2.cvtColor(img_origin, cv2.COLOR_BGR2RGB)) # plt.imshow(img) #plt.show() #print("x_1 shape[0]", x_1.shape) # plt.figure(figsize=(8, 8)) # arr_img1 = [] # if i == 1: # idx = 1 # for j in range(36): # img = x_1[1][j].cpu().detach().numpy() # ax = plt.subplot(6, 6, idx) # ax.set_xticks([]) # ax.set_yticks([]) # plt.imshow(img, cmap='gray') # idx += 1 # cv2.imshow("img",img) # cv2.waitKey(300) # plt.show() # for _ in range(8): # for _ in range(8): # ax = plt.subplot(8, 8, idx) # ax.set_xticks([]) # ax.set_yticks([]) # plt.imshow(arr_img1[idx], cmap='gray') # idx += 1 # print("x_1 shape[0]", x_1[0][0].shape) # print("x_1[0][0] type : ", type(x_1[0][0])) # img = x_1[0][0].cpu().detach().numpy() # print(img) # cv2.imshow("img",img) # cv2.waitKey(300000) return 0
def process(im): mean = torch.Tensor([0.485, 0.456, 0.406]) std = torch.Tensor([0.229, 0.224, 0.225]) im = np.transpose(im, (1, 2, 0)) im = t.unNormalize(im, mean, std) return im