def save_det_result(config_file, out_dir, checkpoint_file=None, img_dir=None, score_thr=0.2): """Visualize results and save to the disk """ cfg = Config.fromfile(config_file) data_test = cfg.data.test dataset = get_dataset(data_test) classnames = [dataset.CLASSES] # use checkpoint path in cfg if not checkpoint_file: checkpoint_file = osp.join(cfg.work_dir, 'latest.pth') # use testset in cfg if not img_dir: img_dir = data_test.img_prefix model = init_detector(config_file, checkpoint_file, device='cuda:0') img_list = os.listdir(img_dir) for img_name in img_list: img_path = osp.join(img_dir, img_name) img_out_path = osp.join(out_dir, img_name) result = inference_detector(model, img_path) img = draw_poly_detections(img_path, result, classnames, scale=1.0, threshold=score_thr, colormap=[(212, 188, 0)]) print(img_out_path) cv2.imwrite(img_out_path, img)
def inference_single_vis(self, srcpath, dstpath, slide_size, chip_size): detections = self.inference_single(srcpath, slide_size, chip_size) img = draw_poly_detections(srcpath, detections, self.classnames, scale=1, threshold=0.3) cv2.imwrite(dstpath, img)
def inference_single_vis(self, srcpath, dstpath, slide_size, chip_size): detections = self.inference_single(srcpath, slide_size, chip_size) #classnames = [cls if cls not in CLASS_MAP else CLASS_MAP[cls] for cls in self.classnames] classnames = [''] * 15 img = draw_poly_detections(srcpath, detections, classnames, scale=1, threshold=0.3) cv2.imwrite(dstpath, img)
def inference_single_vis(self, srcpath, dstpath): img = mmcv.imread(srcpath) detections = self.inference_single(img) img = cv2.resize(img, (512, 512)) print('{}检测到{}个'.format(os.path.basename(srcpath), len(detections))) print(detections) # print('detections是什么',len(detections)) img = draw_poly_detections(img, detections, self.classnames, scale=1, threshold=0.3) cv2.imwrite(dstpath, img)