zoukankan      html  css  js  c++  java
  • Detectron2测试

    Detectron2测试

    # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
    import argparse
    import glob
    import multiprocessing as mp
    import os
    import time
    import cv2
    import tqdm
    
    from detectron2.config import get_cfg
    from detectron2.data.detection_utils import read_image
    from detectron2.utils.logger import setup_logger
    
    from predictor import VisualizationDemo
    
    
    # constants
    WINDOW_NAME = "COCO detections"
    
    confidence_threshold=0.5
    opts=['MODEL.WEIGHTS', 'model_final_c10459X3.pkl']
    
    def setup_cfg():
        # load config from file and command-line arguments
        cfg = get_cfg()
        cfg.merge_from_file("mask_rcnn_R_50_FPN_3x.yaml")
        cfg.merge_from_list(opts)
        # Set score_threshold for builtin models
        cfg.MODEL.RETINANET.SCORE_THRESH_TEST = confidence_threshold
        cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = confidence_threshold
        cfg.MODEL.PANOPTIC_FPN.COMBINE.INSTANCES_CONFIDENCE_THRESH = confidence_threshold
        cfg.freeze()
        return cfg
    
    
    def test1():
        setup_logger(name="fvcore")
        logger = setup_logger()
        
    
        cfg = setup_cfg()
        demo = VisualizationDemo(cfg)
    
        path="input1.jpg"
        img = read_image(path, format="BGR")
        start_time = time.time()
        predictions, visualized_output = demo.run_on_image(img)
    
        logger.info(
                    "{}: {} in {:.2f}s".format(
                        path,
                        "detected {} instances".format(len(predictions["instances"]))
                        if "instances" in predictions
                        else "finished",
                        time.time() - start_time,
                    )
                )
        
    
        cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_NORMAL)
        cv2.imshow(WINDOW_NAME, visualized_output.get_image()[:, :, ::-1])
        cv2.imwrite("test-result1.jpg",visualized_output.get_image()[:, :, ::-1])
        
        cv2.waitKey(100)
    
    
    
    test1()
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ python test-img-2020092002.py
    [09/20 12:44:38 fvcore.common.checkpoint]: Loading checkpoint from model_final_c10459X3.pkl
    [09/20 12:44:39 fvcore.common.checkpoint]: Reading a file from 'Detectron2 Model Zoo'
    [09/20 12:44:39 fvcore.common.checkpoint]: The checkpoint state_dict contains keys that are not used by the model:
      sem_seg_head.p2.0.weight
      sem_seg_head.p2.0.norm.{weight, bias}
      sem_seg_head.p3.0.weight
      sem_seg_head.p3.0.norm.{weight, bias}
      sem_seg_head.p4.0.weight
      sem_seg_head.p4.0.norm.{weight, bias}
      sem_seg_head.p4.2.weight
      sem_seg_head.p4.2.norm.{weight, bias}
      sem_seg_head.p5.0.weight
      sem_seg_head.p5.0.norm.{weight, bias}
      sem_seg_head.p5.2.weight
      sem_seg_head.p5.2.norm.{weight, bias}
      sem_seg_head.p5.4.weight
      sem_seg_head.p5.4.norm.{weight, bias}
      sem_seg_head.predictor.{weight, bias}
    [09/20 12:44:39 detectron2]: input2.jpg: detected 2 instances in 0.23s
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ 
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ 
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ 
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ 
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ python test-img-2020092002.py
    [09/20 12:45:13 fvcore.common.checkpoint]: Loading checkpoint from model_final_c10459X3.pkl
    [09/20 12:45:13 fvcore.common.checkpoint]: Reading a file from 'Detectron2 Model Zoo'
    [09/20 12:45:13 fvcore.common.checkpoint]: The checkpoint state_dict contains keys that are not used by the model:
      sem_seg_head.p2.0.weight
      sem_seg_head.p2.0.norm.{weight, bias}
      sem_seg_head.p3.0.weight
      sem_seg_head.p3.0.norm.{weight, bias}
      sem_seg_head.p4.0.weight
      sem_seg_head.p4.0.norm.{weight, bias}
      sem_seg_head.p4.2.weight
      sem_seg_head.p4.2.norm.{weight, bias}
      sem_seg_head.p5.0.weight
      sem_seg_head.p5.0.norm.{weight, bias}
      sem_seg_head.p5.2.weight
      sem_seg_head.p5.2.norm.{weight, bias}
      sem_seg_head.p5.4.weight
      sem_seg_head.p5.4.norm.{weight, bias}
      sem_seg_head.predictor.{weight, bias}
    [09/20 12:45:13 detectron2]: input1.jpg: detected 1 instances in 0.23s
    (wind2) star@xmatrix:~/Detectron2/detectron2-master/demo$ 

    QQ 3087438119
  • 相关阅读:
    题解:CF1494 F. Delete The Edges
    「CEOI2011」选做
    题解:「CEOI2017」Chase
    学习笔记:《具体数学》问题整理
    题解:「COCI2019」 Transport
    【做题记录】位运算
    线性DP
    虚树 virtual-tree
    三元环计数
    长链剖分
  • 原文地址:https://www.cnblogs.com/herd/p/13699676.html
Copyright © 2011-2022 走看看