boxes, masks, seg_scores = im_detect(im, net) #print 'boxes{},masks{},seg_scores{}'.format(boxes.shape,masks.shape,seg_scores.shape) print 'boxes{}'.format(boxes.shape) end = time.time() print 'forward time %f' % (end - start) result_mask, result_box = gpu_mask_voting(masks, boxes, seg_scores, len(CLASSES) + 1, 300, im.shape[1], im.shape[0]) #print 'res_box{},res_mask{}'.format(result_box.shape,result_mask.shape) #pred_dict = get_vis_dict(result_box, result_mask, 'data/demo/' + im_name, CLASSES) pred_dict = get_vis_dict(result_box, result_mask, data_path + im_name, CLASSES) img_width = im.shape[1] img_height = im.shape[0] inst_img, cls_img = _convert_pred_to_image(img_width, img_height, pred_dict) color_map = _get_voc_color_map() target_cls_file = os.path.join(res_path, 'cls_maskSeg_' + img_name + '.jpg') cls_out_img = np.zeros((img_height, img_width, 3)) for i in xrange(img_height): for j in xrange(img_width): cls_out_img[i][j] = color_map[cls_img[i][j]][::-1] cv2.imwrite(target_cls_file, cls_out_img) background = Image.open(gt_image) #boxx = (0,0,200,200) #background = background.crop(boxx) mask = Image.open(target_cls_file) background = background.convert('RGBA') mask = mask.convert('RGBA')
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'Demo for data/demo/{}'.format(im_name) gt_image = os.path.join(demo_dir, im_name) im = cv2.imread(gt_image) start = time.time() boxes, masks, seg_scores = im_detect(im, net) end = time.time() print 'forward time %f' % (end-start) result_mask, result_box = gpu_mask_voting(masks, boxes, seg_scores, len(CLASSES) + 1, 100, im.shape[1], im.shape[0]) pred_dict = get_vis_dict(result_box, result_mask, 'data/demo/' + im_name, CLASSES) img_width = im.shape[1] img_height = im.shape[0] inst_img, cls_img = _convert_pred_to_image(img_width, img_height, pred_dict) color_map = _get_voc_color_map() target_cls_file = os.path.join(demo_dir, 'cls_' + im_name) cls_out_img = np.zeros((img_height, img_width, 3)) for i in xrange(img_height): for j in xrange(img_width): cls_out_img[i][j] = color_map[cls_img[i][j]][::-1] cv2.imwrite(target_cls_file, cls_out_img) background = Image.open(gt_image) mask = Image.open(target_cls_file) background = background.convert('RGBA') mask = mask.convert('RGBA') superimpose_image = Image.blend(background, mask, 0.8) superimpose_name = os.path.join(demo_dir, 'final_' + im_name) superimpose_image.save(superimpose_name, 'JPEG')