首页 > 其他分享 >(倒推2)E:\mmdetection-main\demo\image_demo.py 代码解读

(倒推2)E:\mmdetection-main\demo\image_demo.py 代码解读

时间:2023-11-16 11:44:34浏览次数:34  
标签:parser help -- demo image args call 倒推

# Copyright (c) OpenMMLab. All rights reserved.
"""Image Demo.

This script adopts a new infenence class, currently supports image path,
np.array and folder input formats, and will support video and webcam
in the future.

Example:
    Save visualizations and predictions results::

        python demo/image_demo.py demo/demo.jpg rtmdet-s

        python demo/image_demo.py demo/demo.jpg \
        configs/rtmdet/rtmdet_s_8xb32-300e_coco.py \
        --weights rtmdet_s_8xb32-300e_coco_20220905_161602-387a891e.pth

        python demo/image_demo.py demo/demo.jpg \
        glip_atss_swin-t_a_fpn_dyhead_pretrain_obj365 --texts bench

        python demo/image_demo.py demo/demo.jpg \
        glip_atss_swin-t_a_fpn_dyhead_pretrain_obj365 --texts 'bench . car .'

        python demo/image_demo.py demo/demo.jpg \
        glip_atss_swin-t_a_fpn_dyhead_pretrain_obj365
        --texts 'bench . car .' -c

        python demo/image_demo.py demo/demo.jpg \
        glip_atss_swin-t_a_fpn_dyhead_pretrain_obj365 \
        --texts 'There are a lot of cars here.'

    Visualize prediction results::

        python demo/image_demo.py demo/demo.jpg rtmdet-ins-s --show

        python demo/image_demo.py demo/demo.jpg rtmdet-ins_s_8xb32-300e_coco \
        --show
"""

from argparse import ArgumentParser

from mmengine.logging import print_log

from mmdet.apis import DetInferencer


def parse_args():
    parser = ArgumentParser()
    parser.add_argument(
        'inputs', type=str, help='Input image file or folder path.')
    parser.add_argument(
        'model',
        type=str,
        help='Config or checkpoint .pth file or the model name '
        'and alias defined in metafile. The model configuration '
        'file will try to read from .pth if the parameter is '
        'a .pth weights file.')
    parser.add_argument('--weights', default=None, help='Checkpoint file')
    parser.add_argument(
        '--out-dir',
        type=str,
        default='outputs',
        help='Output directory of images or prediction results.')
    parser.add_argument('--texts', help='text prompt')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--pred-score-thr',
        type=float,
        default=0.3,
        help='bbox score threshold')
    parser.add_argument(
        '--batch-size', type=int, default=1, help='Inference batch size.')
    parser.add_argument(
        '--show',
        action='store_true',
        help='Display the image in a popup window.')
    parser.add_argument(
        '--no-save-vis',
        action='store_true',
        help='Do not save detection vis results')
    parser.add_argument(
        '--no-save-pred',
        action='store_true',
        help='Do not save detection json results')
    parser.add_argument(
        '--print-result',
        action='store_true',
        help='Whether to print the results.')
    parser.add_argument(
        '--palette',
        default='none',
        choices=['coco', 'voc', 'citys', 'random', 'none'],
        help='Color palette used for visualization')
    # only for GLIP
    parser.add_argument(
        '--custom-entities',
        '-c',
        action='store_true',
        help='Whether to customize entity names? '
        'If so, the input text should be '
        '"cls_name1 . cls_name2 . cls_name3 ." format')

    call_args = vars(parser.parse_args())

    if call_args['no_save_vis'] and call_args['no_save_pred']:
        call_args['out_dir'] = ''

    if call_args['model'].endswith('.pth'):
        print_log('The model is a weight file, automatically '
                  'assign the model to --weights')
        call_args['weights'] = call_args['model']
        call_args['model'] = None

    init_kws = ['model', 'weights', 'device', 'palette']
    init_args = {}
    for init_kw in init_kws:
        init_args[init_kw] = call_args.pop(init_kw)

    return init_args, call_args


def main():
    init_args, call_args = parse_args()
    # TODO: Video and Webcam are currently not supported and
    #  may consume too much memory if your input folder has a lot of images.
    #  We will be optimized later.
    inferencer = DetInferencer(**init_args)
    inferencer(**call_args)

    if call_args['out_dir'] != '' and not (call_args['no_save_vis']
                                           and call_args['no_save_pred']):
        print_log(f'results have been saved at {call_args["out_dir"]}')


if __name__ == '__main__':
    main()

  

标签:parser,help,--,demo,image,args,call,倒推
From: https://www.cnblogs.com/wenluderen/p/17835893.html

相关文章

  • Natural Image Reconstruction from fMRI using Deep Learning: A Survey
    NaturalImageReconstructionfromfMRIusingDeepLearning:ASurveyZarinaRakhimberdina1,3,QuentinJodelet1,3,XinLiu2,3,∗,TsuyoshiMurata1,3一句话概括:介绍了各种自然图像重构方法(生成模型和非生成模型)以及评价指标,并提出了综合评价各模型的方法。介绍fMR......
  • 【论文阅读笔记】【Image Retrieval】 Global Features are All You Need for Image R
    SuperGlobalICCV2023读论文思考的问题论文试图解决什么问题?图片检索方法通常由粗粒度图片检索和精确的结果重排列两个模块组成。人们通常认为图片的localfeature在结果重排列中是不可或缺的,但对大量的localfeature的计算需要较高的计算资源和时间能否只用图片......
  • springcloud教程 -- 快速搭建入门级demo
    废话不多讲,跟紧我,开启你的SpringCloud初体验 首先回顾微服务的基本组成: [图片here] 生产者:提供服务消费者:消费服务服务注册/发现中心:服务注册,发现,监控所以,首先明白springcloud微服务的架构基础:生产者(client),消费者(client),服务注册/发现中心(server) ****************......
  • 如何使用ImageMagick将SVG转换为PNG?
    内容来自DOChttps://q.houxu6.top/?s=如何使用ImageMagick将SVG转换为PNG?我有一个尺寸为16x16的SVG文件。当我使用ImageMagick的convert程序将其转换为PNG时,结果得到了一个16x16像素的PNG,这个尺寸太小了:converttest.svgtest.png我需要指定输出PNG的像素大小。-size参数......
  • .net6.0及以上WPF中使用GDI+的demo
    usingSystem;usingSystem.Drawing;usingSystem.Runtime.InteropServices;usingSystem.Windows;usingSystem.Windows.Interop;usingSystem.Windows.Media.Imaging;namespaceTryDemo{///<summary>///InteractionlogicforMainWindow.xaml......
  • 解决 Fedora Live-CD 启动时出现 Invalid image 的问题
    .....安装Fedora39的时候,Live-CD启动报如下错误:InvalidimageFailedtoreadheader:UnsupportedFailedtoloadimage:Unsupportedstart_image()returnedUnsupported尝试了各种解决办法未果,后来在Fedora论坛上发现有人在Fedora37时遇到过同样的问题。......
  • [论文阅读] Latent Consistency Models@ Synthesizing High-Resolution Images with F
    1.Pretitle:LatentConsistencyModels:SynthesizingHigh-ResolutionImageswithFew-StepInferenceaccepted:arXiv2023(ICLR2024Submission)paper:https://arxiv.org/abs/2303.01469code:https://github.com/openai/consistency_modelsref:https://mp.wei......
  • Android:在按钮(Button)或图像按钮(ImageButton)上合并文本和图片。
    内容来自DOChttps://q.houxu6.top/?s=Android:在按钮(Button)或图像按钮(ImageButton)上合并文本和图片。我正在尝试在按钮背景上添加一张图片,并根据运行时发生的情况动态地添加一些文本到图片上方。如果使用ImageButton,我甚至无法添加文本。如果使用Button,我可以添加文本,但只......
  • 格式转换:相机帧void* pBuffer,QImage,cv::Mat,Halconcpp::HObject
    【说明】1、若传递的是指针,则内存共享,其一改变,另一个也被改变。为了避免输入被更改,做了些处理。如QImage2Mat中使用了两个变量mat,out。2、有的存在宽度方向4字节对齐情况,所以做了些处理。如QImage2HObject中让宽度变为4的整数倍。 【相机帧void*pBuffer赋给其他格式】 ......
  • Adding Conditional Control to Text-to-Image Diffusion Models
    https://mp.weixin.qq.com/s/iL6YitT7EGP6DnrBehb9MQ1.AddingConditionalControltoText-to-ImageDiffusionModels论文地址:https://arxiv.org/pdf/2302.05543.pdf开源地址:https://github.com/lllyasviel/ControlNet(该项目已有2.4万stars)作者单位:斯坦福大学这......