• 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
  • 相关阅读:
    Java编程语言学习01-Java语言概述
    Java复习面试指南-06为什么要进行数据类型转换?什么情况下会进行自动类型转换?
    Java复习面试指南-05简单说一下Java当中的char字符类型?
    Java复习面试指南-04Java语言支持的8种基本数据类型是什么?占用的空间是多少?
    Java复习面试指南03-说一下Java当中标识符与关键字的区别?
    Linq LeftJoin 取不同和想同的对像
    vue父组件异步传递prop到子组件echarts画图问题踩坑总结
    linux下使用openssl生成https的crt和key证书
    css hover延时 解决快速划入划出
    记录时间操作
  • 原文地址:https://www.cnblogs.com/herd/p/13699676.html
Copyright © 2020-2023  润新知