【Detectron2】入门01-一些基础函数
程序员文章站
2022-07-14 21:43:18
...
github:https://github.com/facebookresearch/detectron2/blob/master/GETTING_STARTED.md
colab:https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5
cfg.MODEL.WEIGHTS = model_zoo.get_config_file("detectron2://xx")
后面的地址在下面查:
https://github.com/facebookresearch/detectron2/blob/master/MODEL_ZOO.md
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
from detectron2 import model_zoo
from detectron2.engine import DefaultPredctor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog, DatasetCatalog
# 载入图片
im = cv2.imread(“./input.jpg”)
cv2.imshow(im)
# 创建一个detectron2 config
# 和detectron2 DefaultPredictor来inference这张图片
# config确定模型,并调整模型参数
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file(“COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml
”))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_THES = 0.5 #设置阈值
cfg.MODEL.WEIGHTS = model.zoo,get_checkpoint_url(“COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml
")
# predict
predictor = DefaultPredictor(cfg)
outputs = predictor(im)
print(outputs["instances"].pred_classes)
print(outputs["instances"].pred_boxes)
# 使用Visualizer来可视化结果
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
cv2_imshow(out.get_image()[:, :, ::-1])
上一篇: Stream数据流的探讨
下一篇: JDK8 Stream 数据流效率分析