map_location=lambda storage, loc: storage) net_utils.load_ckpt(maskRCNN, checkpoint['model']) maskRCNN.eval() maskRCNN = mynn.DataParallel(maskRCNN, cpu_keywords=['im_info', 'roidb'], minibatch=True, device_ids=[0]) # load image img_path = "/home/work/liupeng11/code/Detectron.pytorch/demo/sample_images/img1.jpg" im = cv2.imread(img_path) # detect bouding boxes and segments from core.test import im_detect_bbox, im_detect_mask, box_results_with_nms_and_limit, segm_results scores, boxes, im_scale, blob_conv = im_detect_bbox(maskRCNN, im, cfg.TEST.SCALE, cfg.TEST.MAX_SIZE, None) scores, boxes, cls_boxes = box_results_with_nms_and_limit(scores, boxes) masks = im_detect_mask(maskRCNN, im_scale, boxes, blob_conv) cls_segms = segm_results(cls_boxes, masks, boxes, im.shape[0], im.shape[1]) cls_keyps = None # save detected image name = 'test' output_dir = '/home/work/liupeng11/code/Detectron.pytorch/tmp' vis_utils.vis_one_image( im[:, :, ::-1], # BGR -> RGB for visualization name, output_dir, cls_boxes, cls_segms,
with open(osp.join(args.output_dir, 'config_args.json'), 'w') as fp: json.dump(vars(args), fp, indent=4, sort_keys=True) # ----------------------------------------------------------------------------------- # Detect faces on CS6 frames # ----------------------------------------------------------------------------------- start = time.time() for i, im_name in enumerate(image_subset): print('%d/%d: %s' % (i, len(image_subset), im_name)) im = cv2.imread(osp.join(args.data_dir, im_name)) assert im.size != 0 # Detect faces and regress bounding-boxes scores, boxes, im_scale, blob_conv = im_detect_bbox( net, im, cfg.TEST.SCALE, cfg.TEST.MAX_SIZE) # Format the detection output cls_ind = 1 cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)] cls_scores = scores[:, cls_ind] dets = np.hstack( (cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32) keep = box_utils.nms(dets, NMS_THRESH) dets = dets[keep, :] keep = np.where(dets[:, 4] > CONF_THRESH) dets = dets[keep] # (x, y, w, h) dets[:, 2] = dets[:, 2] - dets[:, 0] + 1 dets[:, 3] = dets[:, 3] - dets[:, 1] + 1 print('Num. detections: %d' % dets.shape[0])