def visualize_result(batch_data, pred, args): colors = loadmat('datasets/mit_list/color150.mat')['colors'] (image, seg, info) = batch_data for j in range(len(info)): # recover image img = image[j].clone() for t, m, s in zip(img, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]): t.mul_(s).add_(m) img = (img.numpy().transpose((1, 2, 0)) * 255).astype(np.uint8) img = img[:, :, ::-1] # segmentation seg_ = seg[j].numpy() seg_color = colorEncode(seg_, colors) # preddiction pred_ = np.argmax(pred.data.cpu()[j].numpy(), axis=0) pred_color = colorEncode(pred_, colors) # aggregate images and save im_vis = np.concatenate((img, seg_color, pred_color), axis=1).astype(np.uint8) img_name = info[j].split('/')[-1] imsave(os.path.join(args.result, img_name.replace('.jpg', '.png')), im_vis)
def visualize_tv(batch_data, pred1, pred2, args): colors = loadmat('datasets/mit_list/color150.mat')['colors'] (imgs, segs, infos) = batch_data for j in range(len(infos)): # get/recover image # img = imread(os.path.join(args.root_img, infos[j])) img = imgs[j].clone() for t, m, s in zip(img, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]): t.mul_(s).add_(m) img = (img.numpy().transpose((1, 2, 0)) * 255).astype(np.uint8) img = imresize(img, (args.imgSize, args.imgSize), interp='bilinear') # segmentation lab = segs[j].numpy() lab_color = colorEncode(lab, colors) lab_color = imresize(lab_color, (args.imgSize, args.imgSize), interp='nearest') # prediction #print('#############') #print(pred1) pred1_ = np.argmax(pred1.data.cpu()[j].numpy(), axis=0) #print('**************') #print(pred1_) #print(pred1_.size()) pred1_color = colorEncode(pred1_, colors) #print('&&&&&&&&&&&&&&&&&') #print(pred1_color) pred1_color = imresize(pred1_color, (args.imgSize, args.imgSize), interp='nearest') pred2_ = np.argmax(pred2.data.cpu()[j].numpy(), axis=0) pred2_color = colorEncode(pred2_, colors) pred2_color = imresize(pred2_color, (args.imgSize, args.imgSize), interp='nearest') #pred_out_ = np.argmax(pred_out.data.cpu()[j].numpy(), axis=0) #pred_out_color = colorEncode(pred_out_, colors) #pred_out_color = imresize(pred_out_color, (args.imgSize, args.imgSize), interp='nearest') # aggregate images and save im_vis = np.concatenate((img, lab_color, pred1_color, pred2_color), axis=1).astype(np.uint8) imsave( os.path.join(args.result, infos[j].replace('/', '_').replace('.jpg', '.png')), im_vis)
def visualize_test_result(img, pred1, pred2, pred_outputs, args): colors = loadmat('datasets/mit_list/color150.mat')['colors'] # recover image img = img[0] #pred1 = pred1.data.cpu()[0] #pred2 = pred2.data.cpu()[0] #pred_outputs = pred_outputs.data.cpu()[0] for t, m, s in zip(img, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]): t.mul_(s).add_(m) img = (img.numpy().transpose((1, 2, 0)) * 255).astype(np.uint8) #img = imresize(img, (args.imgSize, args.imgSize), interp='bilinear') # prediction #print('#############') #print(pred1) pred1_ = np.argmax(pred1.data.cpu()[0].numpy(), axis=0) + 1 #print('**************') #print(pred1_) #print(pred1_.size()) pred1_color = colorEncode(pred1_, colors) #print('&&&&&&&&&&&&&&&&&') #print(pred1_color) #pred1_color = imresize(pred1_color, (args.imgSize, args.imgSize), interp='nearest') pred2_ = np.argmax(pred2.data.cpu()[0].numpy(), axis=0) + 1 pred2_color = colorEncode(pred2_, colors) #pred2_color = imresize(pred2_color, (args.imgSize, args.imgSize), interp='nearest') pred_outputs_ = np.argmax(pred_outputs.data.cpu()[0].numpy(), axis=0) + 1 pred_outputs_color = colorEncode(pred_outputs_, colors) #pred2_color = imresize(pred2_color, (args.imgSize, args.imgSize), interp='nearest') # aggregate images and save im_vis = np.concatenate( (img, pred1_color, pred2_color, pred_outputs_color), axis=1).astype(np.uint8) imsave(os.path.join(args.result, os.path.basename(args.test_img) + '.png'), im_vis)