Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何测量得到论文中的检测与实例分割的延迟? #60

Open
QWERDF007 opened this issue Apr 24, 2024 · 1 comment
Open

Comments

@QWERDF007
Copy link

我在i9-9900k和3070上测试得到的延迟是50ms左右.
测试代码:

# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
from argparse import ArgumentParser

from mmdet.apis import (async_inference_detector, inference_detector,
                        init_detector, show_result_pyplot)

import repvit
import torch

from pathlib import Path
import time
from PIL import Image
import magic


def parse_args():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument('--out-file', default=None, help='Path to output file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--palette',
        default='coco',
        choices=['coco', 'voc', 'citys', 'random'],
        help='Color palette used for visualization')
    parser.add_argument(
        '--score-thr', type=float, default=0.3, help='bbox score threshold')
    parser.add_argument(
        '--async-test',
        action='store_true',
        help='whether to set async options for async inference.')
    args = parser.parse_args()
    return args


def main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    
    data_dir = Path(args.img)
    for fpath in data_dir.iterdir():
    # fpaths = [str(fpath) for fpath in data_dir.iterdir()]
        
        start = time.time()
        # test a single image
        result = inference_detector(model,  str(fpath))
        torch.cuda.synchronize()
        end = time.time()
        
        # print(f"Inference time: {end-start},  total: {len(fpaths)} average time: {(end-start)/len(fpaths)}")
        img = Image.open(str(fpath))

        print(f"{fpath} size: {img.width}x{img.height}, time: {end-start}")
        img.close()
    # show the results
    # show_result_pyplot(
    #     model,
    #     str(fpath),
    #     result,
    #     palette=args.palette,
    #     score_thr=args.score_thr,
    #     out_file=args.out_file)


async def async_main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    tasks = asyncio.create_task(async_inference_detector(model, args.img))
    result = await asyncio.gather(tasks)
    # show the results
    show_result_pyplot(
        model,
        args.img,
        result[0],
        palette=args.palette,
        score_thr=args.score_thr,
        out_file=args.out_file)


if __name__ == '__main__':
    args = parse_args()
    if args.async_test:
        asyncio.run(async_main(args))
    else:
        main(args)


测试结果:

/data/wt/TestData/dataset/dogsvscats/test1/1.jpg size: 381x499, time: 0.08272171020507812
/data/wt/TestData/dataset/dogsvscats/test1/10.jpg size: 500x374, time: 0.06478381156921387
/data/wt/TestData/dataset/dogsvscats/test1/100.jpg size: 499x343, time: 0.07163786888122559
/data/wt/TestData/dataset/dogsvscats/test1/1000.jpg size: 288x499, time: 0.0686182975769043
/data/wt/TestData/dataset/dogsvscats/test1/10000.jpg size: 467x499, time: 0.048500776290893555
/data/wt/TestData/dataset/dogsvscats/test1/10001.jpg size: 499x293, time: 0.06814789772033691
/data/wt/TestData/dataset/dogsvscats/test1/10002.jpg size: 500x374, time: 0.06205487251281738
/data/wt/TestData/dataset/dogsvscats/test1/10003.jpg size: 500x263, time: 0.05933856964111328
/data/wt/TestData/dataset/dogsvscats/test1/10004.jpg size: 488x399, time: 0.05417633056640625
/data/wt/TestData/dataset/dogsvscats/test1/10005.jpg size: 249x227, time: 0.04686784744262695
/data/wt/TestData/dataset/dogsvscats/test1/10006.jpg size: 499x375, time: 0.05886483192443848
/data/wt/TestData/dataset/dogsvscats/test1/10007.jpg size: 500x374, time: 0.05744314193725586
/data/wt/TestData/dataset/dogsvscats/test1/10008.jpg size: 499x375, time: 0.05886197090148926
/data/wt/TestData/dataset/dogsvscats/test1/10009.jpg size: 489x367, time: 0.057126522064208984
/data/wt/TestData/dataset/dogsvscats/test1/1001.jpg size: 250x243, time: 0.045355796813964844
/data/wt/TestData/dataset/dogsvscats/test1/10010.jpg size: 500x374, time: 0.058531999588012695
/data/wt/TestData/dataset/dogsvscats/test1/10011.jpg size: 400x345, time: 0.05124783515930176
/data/wt/TestData/dataset/dogsvscats/test1/10012.jpg size: 335x409, time: 0.05216383934020996
/data/wt/TestData/dataset/dogsvscats/test1/10013.jpg size: 470x500, time: 0.04745936393737793
/data/wt/TestData/dataset/dogsvscats/test1/10015.jpg size: 500x387, time: 0.05611777305603027
/data/wt/TestData/dataset/dogsvscats/test1/10016.jpg size: 240x269, time: 0.049646854400634766
/data/wt/TestData/dataset/dogsvscats/test1/10017.jpg size: 250x293, time: 0.05157661437988281
/data/wt/TestData/dataset/dogsvscats/test1/10018.jpg size: 434x375, time: 0.05177617073059082
/data/wt/TestData/dataset/dogsvscats/test1/10019.jpg size: 499x432, time: 0.051323652267456055
/data/wt/TestData/dataset/dogsvscats/test1/1002.jpg size: 374x500, time: 0.05673623085021973
/data/wt/TestData/dataset/dogsvscats/test1/10020.jpg size: 199x200, time: 0.0448911190032959
/data/wt/TestData/dataset/dogsvscats/test1/10021.jpg size: 396x260, time: 0.06324148178100586
/data/wt/TestData/dataset/dogsvscats/test1/10022.jpg size: 500x374, time: 0.057634830474853516
/data/wt/TestData/dataset/dogsvscats/test1/10023.jpg size: 360x269, time: 0.05904746055603027
/data/wt/TestData/dataset/dogsvscats/test1/10024.jpg size: 303x359, time: 0.050252437591552734
/data/wt/TestData/dataset/dogsvscats/test1/10025.jpg size: 443x459, time: 0.04602837562561035
/data/wt/TestData/dataset/dogsvscats/test1/10026.jpg size: 499x375, time: 0.05867409706115723
/data/wt/TestData/dataset/dogsvscats/test1/10027.jpg size: 320x431, time: 0.05827951431274414
/data/wt/TestData/dataset/dogsvscats/test1/10028.jpg size: 200x149, time: 0.05838799476623535
/data/wt/TestData/dataset/dogsvscats/test1/10029.jpg size: 319x414, time: 0.05730867385864258
/data/wt/TestData/dataset/dogsvscats/test1/1003.jpg size: 499x398, time: 0.055377960205078125
/data/wt/TestData/dataset/dogsvscats/test1/10030.jpg size: 479x401, time: 0.05260920524597168
/data/wt/TestData/dataset/dogsvscats/test1/10031.jpg size: 274x500, time: 0.06286954879760742
/data/wt/TestData/dataset/dogsvscats/test1/10033.jpg size: 499x375, time: 0.06049299240112305
/data/wt/TestData/dataset/dogsvscats/test1/10034.jpg size: 406x400, time: 0.04815244674682617
/data/wt/TestData/dataset/dogsvscats/test1/10035.jpg size: 310x458, time: 0.061447858810424805
/data/wt/TestData/dataset/dogsvscats/test1/10036.jpg size: 499x375, time: 0.0570530891418457
/data/wt/TestData/dataset/dogsvscats/test1/10037.jpg size: 499x375, time: 0.06384038925170898
/data/wt/TestData/dataset/dogsvscats/test1/10038.jpg size: 499x466, time: 0.04932117462158203
@hellohahaw
Copy link

我在i9-9900k和3070上测试得到的延迟是50ms左右. 测试代码:

# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
from argparse import ArgumentParser

from mmdet.apis import (async_inference_detector, inference_detector,
                        init_detector, show_result_pyplot)

import repvit
import torch

from pathlib import Path
import time
from PIL import Image
import magic


def parse_args():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument('--out-file', default=None, help='Path to output file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--palette',
        default='coco',
        choices=['coco', 'voc', 'citys', 'random'],
        help='Color palette used for visualization')
    parser.add_argument(
        '--score-thr', type=float, default=0.3, help='bbox score threshold')
    parser.add_argument(
        '--async-test',
        action='store_true',
        help='whether to set async options for async inference.')
    args = parser.parse_args()
    return args


def main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    
    data_dir = Path(args.img)
    for fpath in data_dir.iterdir():
    # fpaths = [str(fpath) for fpath in data_dir.iterdir()]
        
        start = time.time()
        # test a single image
        result = inference_detector(model,  str(fpath))
        torch.cuda.synchronize()
        end = time.time()
        
        # print(f"Inference time: {end-start},  total: {len(fpaths)} average time: {(end-start)/len(fpaths)}")
        img = Image.open(str(fpath))

        print(f"{fpath} size: {img.width}x{img.height}, time: {end-start}")
        img.close()
    # show the results
    # show_result_pyplot(
    #     model,
    #     str(fpath),
    #     result,
    #     palette=args.palette,
    #     score_thr=args.score_thr,
    #     out_file=args.out_file)


async def async_main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    tasks = asyncio.create_task(async_inference_detector(model, args.img))
    result = await asyncio.gather(tasks)
    # show the results
    show_result_pyplot(
        model,
        args.img,
        result[0],
        palette=args.palette,
        score_thr=args.score_thr,
        out_file=args.out_file)


if __name__ == '__main__':
    args = parse_args()
    if args.async_test:
        asyncio.run(async_main(args))
    else:
        main(args)

测试结果:

/data/wt/TestData/dataset/dogsvscats/test1/1.jpg size: 381x499, time: 0.08272171020507812
/data/wt/TestData/dataset/dogsvscats/test1/10.jpg size: 500x374, time: 0.06478381156921387
/data/wt/TestData/dataset/dogsvscats/test1/100.jpg size: 499x343, time: 0.07163786888122559
/data/wt/TestData/dataset/dogsvscats/test1/1000.jpg size: 288x499, time: 0.0686182975769043
/data/wt/TestData/dataset/dogsvscats/test1/10000.jpg size: 467x499, time: 0.048500776290893555
/data/wt/TestData/dataset/dogsvscats/test1/10001.jpg size: 499x293, time: 0.06814789772033691
/data/wt/TestData/dataset/dogsvscats/test1/10002.jpg size: 500x374, time: 0.06205487251281738
/data/wt/TestData/dataset/dogsvscats/test1/10003.jpg size: 500x263, time: 0.05933856964111328
/data/wt/TestData/dataset/dogsvscats/test1/10004.jpg size: 488x399, time: 0.05417633056640625
/data/wt/TestData/dataset/dogsvscats/test1/10005.jpg size: 249x227, time: 0.04686784744262695
/data/wt/TestData/dataset/dogsvscats/test1/10006.jpg size: 499x375, time: 0.05886483192443848
/data/wt/TestData/dataset/dogsvscats/test1/10007.jpg size: 500x374, time: 0.05744314193725586
/data/wt/TestData/dataset/dogsvscats/test1/10008.jpg size: 499x375, time: 0.05886197090148926
/data/wt/TestData/dataset/dogsvscats/test1/10009.jpg size: 489x367, time: 0.057126522064208984
/data/wt/TestData/dataset/dogsvscats/test1/1001.jpg size: 250x243, time: 0.045355796813964844
/data/wt/TestData/dataset/dogsvscats/test1/10010.jpg size: 500x374, time: 0.058531999588012695
/data/wt/TestData/dataset/dogsvscats/test1/10011.jpg size: 400x345, time: 0.05124783515930176
/data/wt/TestData/dataset/dogsvscats/test1/10012.jpg size: 335x409, time: 0.05216383934020996
/data/wt/TestData/dataset/dogsvscats/test1/10013.jpg size: 470x500, time: 0.04745936393737793
/data/wt/TestData/dataset/dogsvscats/test1/10015.jpg size: 500x387, time: 0.05611777305603027
/data/wt/TestData/dataset/dogsvscats/test1/10016.jpg size: 240x269, time: 0.049646854400634766
/data/wt/TestData/dataset/dogsvscats/test1/10017.jpg size: 250x293, time: 0.05157661437988281
/data/wt/TestData/dataset/dogsvscats/test1/10018.jpg size: 434x375, time: 0.05177617073059082
/data/wt/TestData/dataset/dogsvscats/test1/10019.jpg size: 499x432, time: 0.051323652267456055
/data/wt/TestData/dataset/dogsvscats/test1/1002.jpg size: 374x500, time: 0.05673623085021973
/data/wt/TestData/dataset/dogsvscats/test1/10020.jpg size: 199x200, time: 0.0448911190032959
/data/wt/TestData/dataset/dogsvscats/test1/10021.jpg size: 396x260, time: 0.06324148178100586
/data/wt/TestData/dataset/dogsvscats/test1/10022.jpg size: 500x374, time: 0.057634830474853516
/data/wt/TestData/dataset/dogsvscats/test1/10023.jpg size: 360x269, time: 0.05904746055603027
/data/wt/TestData/dataset/dogsvscats/test1/10024.jpg size: 303x359, time: 0.050252437591552734
/data/wt/TestData/dataset/dogsvscats/test1/10025.jpg size: 443x459, time: 0.04602837562561035
/data/wt/TestData/dataset/dogsvscats/test1/10026.jpg size: 499x375, time: 0.05867409706115723
/data/wt/TestData/dataset/dogsvscats/test1/10027.jpg size: 320x431, time: 0.05827951431274414
/data/wt/TestData/dataset/dogsvscats/test1/10028.jpg size: 200x149, time: 0.05838799476623535
/data/wt/TestData/dataset/dogsvscats/test1/10029.jpg size: 319x414, time: 0.05730867385864258
/data/wt/TestData/dataset/dogsvscats/test1/1003.jpg size: 499x398, time: 0.055377960205078125
/data/wt/TestData/dataset/dogsvscats/test1/10030.jpg size: 479x401, time: 0.05260920524597168
/data/wt/TestData/dataset/dogsvscats/test1/10031.jpg size: 274x500, time: 0.06286954879760742
/data/wt/TestData/dataset/dogsvscats/test1/10033.jpg size: 499x375, time: 0.06049299240112305
/data/wt/TestData/dataset/dogsvscats/test1/10034.jpg size: 406x400, time: 0.04815244674682617
/data/wt/TestData/dataset/dogsvscats/test1/10035.jpg size: 310x458, time: 0.061447858810424805
/data/wt/TestData/dataset/dogsvscats/test1/10036.jpg size: 499x375, time: 0.0570530891418457
/data/wt/TestData/dataset/dogsvscats/test1/10037.jpg size: 499x375, time: 0.06384038925170898
/data/wt/TestData/dataset/dogsvscats/test1/10038.jpg size: 499x466, time: 0.04932117462158203
``

我在i9-9900k和3070上测试得到的延迟是50ms左右. 测试代码:

# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
from argparse import ArgumentParser

from mmdet.apis import (async_inference_detector, inference_detector,
                        init_detector, show_result_pyplot)

import repvit
import torch

from pathlib import Path
import time
from PIL import Image
import magic


def parse_args():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument('--out-file', default=None, help='Path to output file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--palette',
        default='coco',
        choices=['coco', 'voc', 'citys', 'random'],
        help='Color palette used for visualization')
    parser.add_argument(
        '--score-thr', type=float, default=0.3, help='bbox score threshold')
    parser.add_argument(
        '--async-test',
        action='store_true',
        help='whether to set async options for async inference.')
    args = parser.parse_args()
    return args


def main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    
    data_dir = Path(args.img)
    for fpath in data_dir.iterdir():
    # fpaths = [str(fpath) for fpath in data_dir.iterdir()]
        
        start = time.time()
        # test a single image
        result = inference_detector(model,  str(fpath))
        torch.cuda.synchronize()
        end = time.time()
        
        # print(f"Inference time: {end-start},  total: {len(fpaths)} average time: {(end-start)/len(fpaths)}")
        img = Image.open(str(fpath))

        print(f"{fpath} size: {img.width}x{img.height}, time: {end-start}")
        img.close()
    # show the results
    # show_result_pyplot(
    #     model,
    #     str(fpath),
    #     result,
    #     palette=args.palette,
    #     score_thr=args.score_thr,
    #     out_file=args.out_file)


async def async_main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    tasks = asyncio.create_task(async_inference_detector(model, args.img))
    result = await asyncio.gather(tasks)
    # show the results
    show_result_pyplot(
        model,
        args.img,
        result[0],
        palette=args.palette,
        score_thr=args.score_thr,
        out_file=args.out_file)


if __name__ == '__main__':
    args = parse_args()
    if args.async_test:
        asyncio.run(async_main(args))
    else:
        main(args)

测试结果:

/data/wt/TestData/dataset/dogsvscats/test1/1.jpg size: 381x499, time: 0.08272171020507812
/data/wt/TestData/dataset/dogsvscats/test1/10.jpg size: 500x374, time: 0.06478381156921387
/data/wt/TestData/dataset/dogsvscats/test1/100.jpg size: 499x343, time: 0.07163786888122559
/data/wt/TestData/dataset/dogsvscats/test1/1000.jpg size: 288x499, time: 0.0686182975769043
/data/wt/TestData/dataset/dogsvscats/test1/10000.jpg size: 467x499, time: 0.048500776290893555
/data/wt/TestData/dataset/dogsvscats/test1/10001.jpg size: 499x293, time: 0.06814789772033691
/data/wt/TestData/dataset/dogsvscats/test1/10002.jpg size: 500x374, time: 0.06205487251281738
/data/wt/TestData/dataset/dogsvscats/test1/10003.jpg size: 500x263, time: 0.05933856964111328
/data/wt/TestData/dataset/dogsvscats/test1/10004.jpg size: 488x399, time: 0.05417633056640625
/data/wt/TestData/dataset/dogsvscats/test1/10005.jpg size: 249x227, time: 0.04686784744262695
/data/wt/TestData/dataset/dogsvscats/test1/10006.jpg size: 499x375, time: 0.05886483192443848
/data/wt/TestData/dataset/dogsvscats/test1/10007.jpg size: 500x374, time: 0.05744314193725586
/data/wt/TestData/dataset/dogsvscats/test1/10008.jpg size: 499x375, time: 0.05886197090148926
/data/wt/TestData/dataset/dogsvscats/test1/10009.jpg size: 489x367, time: 0.057126522064208984
/data/wt/TestData/dataset/dogsvscats/test1/1001.jpg size: 250x243, time: 0.045355796813964844
/data/wt/TestData/dataset/dogsvscats/test1/10010.jpg size: 500x374, time: 0.058531999588012695
/data/wt/TestData/dataset/dogsvscats/test1/10011.jpg size: 400x345, time: 0.05124783515930176
/data/wt/TestData/dataset/dogsvscats/test1/10012.jpg size: 335x409, time: 0.05216383934020996
/data/wt/TestData/dataset/dogsvscats/test1/10013.jpg size: 470x500, time: 0.04745936393737793
/data/wt/TestData/dataset/dogsvscats/test1/10015.jpg size: 500x387, time: 0.05611777305603027
/data/wt/TestData/dataset/dogsvscats/test1/10016.jpg size: 240x269, time: 0.049646854400634766
/data/wt/TestData/dataset/dogsvscats/test1/10017.jpg size: 250x293, time: 0.05157661437988281
/data/wt/TestData/dataset/dogsvscats/test1/10018.jpg size: 434x375, time: 0.05177617073059082
/data/wt/TestData/dataset/dogsvscats/test1/10019.jpg size: 499x432, time: 0.051323652267456055
/data/wt/TestData/dataset/dogsvscats/test1/1002.jpg size: 374x500, time: 0.05673623085021973
/data/wt/TestData/dataset/dogsvscats/test1/10020.jpg size: 199x200, time: 0.0448911190032959
/data/wt/TestData/dataset/dogsvscats/test1/10021.jpg size: 396x260, time: 0.06324148178100586
/data/wt/TestData/dataset/dogsvscats/test1/10022.jpg size: 500x374, time: 0.057634830474853516
/data/wt/TestData/dataset/dogsvscats/test1/10023.jpg size: 360x269, time: 0.05904746055603027
/data/wt/TestData/dataset/dogsvscats/test1/10024.jpg size: 303x359, time: 0.050252437591552734
/data/wt/TestData/dataset/dogsvscats/test1/10025.jpg size: 443x459, time: 0.04602837562561035
/data/wt/TestData/dataset/dogsvscats/test1/10026.jpg size: 499x375, time: 0.05867409706115723
/data/wt/TestData/dataset/dogsvscats/test1/10027.jpg size: 320x431, time: 0.05827951431274414
/data/wt/TestData/dataset/dogsvscats/test1/10028.jpg size: 200x149, time: 0.05838799476623535
/data/wt/TestData/dataset/dogsvscats/test1/10029.jpg size: 319x414, time: 0.05730867385864258
/data/wt/TestData/dataset/dogsvscats/test1/1003.jpg size: 499x398, time: 0.055377960205078125
/data/wt/TestData/dataset/dogsvscats/test1/10030.jpg size: 479x401, time: 0.05260920524597168
/data/wt/TestData/dataset/dogsvscats/test1/10031.jpg size: 274x500, time: 0.06286954879760742
/data/wt/TestData/dataset/dogsvscats/test1/10033.jpg size: 499x375, time: 0.06049299240112305
/data/wt/TestData/dataset/dogsvscats/test1/10034.jpg size: 406x400, time: 0.04815244674682617
/data/wt/TestData/dataset/dogsvscats/test1/10035.jpg size: 310x458, time: 0.061447858810424805
/data/wt/TestData/dataset/dogsvscats/test1/10036.jpg size: 499x375, time: 0.0570530891418457
/data/wt/TestData/dataset/dogsvscats/test1/10037.jpg size: 499x375, time: 0.06384038925170898
/data/wt/TestData/dataset/dogsvscats/test1/10038.jpg size: 499x466, time: 0.04932117462158203

请问一下,这个作为backbone放到检测模型中,是不是比resnet系列会快一些

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants