You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

image_demo.py 2.2 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import asyncio
  3. from argparse import ArgumentParser
  4. import time
  5. import sys
  6. sys.path.append("/home/shanwei-luo/userdata/mmdetection")
  7. from mmdet.apis import (async_inference_detector, inference_detector,
  8. init_detector, show_result_pyplot)
  9. #python demo/image_demo.py /home/shanwei-luo/userdata/mmdetection/test_image/2-11-0-000.bmp /home/shanwei-luo/userdata/mmdetection/work_dirs/AD_pcb_test11/AD_pcb_test11.py /home/shanwei-luo/userdata/mmdetection/work_dirs/AD_pcb_test11/epoch_60.pth
  10. def parse_args():
  11. parser = ArgumentParser()
  12. parser.add_argument('img', help='Image file')
  13. parser.add_argument('config', help='Config file')
  14. parser.add_argument('checkpoint', help='Checkpoint file')
  15. parser.add_argument(
  16. '--device', default='cuda:0', help='Device used for inference')
  17. parser.add_argument(
  18. '--score-thr', type=float, default=0.3, help='bbox score threshold')
  19. parser.add_argument(
  20. '--async-test',
  21. action='store_true',
  22. help='whether to set async options for async inference.')
  23. args = parser.parse_args()
  24. return args
  25. def main(args):
  26. # build the model from a config file and a checkpoint file
  27. model = init_detector(args.config, args.checkpoint, device=args.device)
  28. # test a single image
  29. for i in range(1):
  30. start = time.time()
  31. result = inference_detector(model, args.img)
  32. end = time.time()
  33. print(end-start)
  34. print(result)
  35. # show the results
  36. show_result_pyplot(model, args.img, result, score_thr=args.score_thr)
  37. async def async_main(args):
  38. # build the model from a config file and a checkpoint file
  39. model = init_detector(args.config, args.checkpoint, device=args.device)
  40. # test a single image
  41. tasks = asyncio.create_task(async_inference_detector(model, args.img))
  42. result = await asyncio.gather(tasks)
  43. # show the results
  44. show_result_pyplot(model, args.img, result[0], score_thr=args.score_thr)
  45. if __name__ == '__main__':
  46. args = parse_args()
  47. if args.async_test:
  48. asyncio.run(async_main(args))
  49. else:
  50. main(args)

No Description

Contributors (3)