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

pre-process speed differs so much #5806

Closed
1 task done
Monday-Leo opened this issue Nov 26, 2021 · 7 comments · Fixed by #5810
Closed
1 task done

pre-process speed differs so much #5806

Monday-Leo opened this issue Nov 26, 2021 · 7 comments · Fixed by #5810
Labels
question Further information is requested

Comments

@Monday-Leo
Copy link

Monday-Leo commented Nov 26, 2021

Search before asking

Question

I use the latest export.py to export my tensort model. It has a good result by running the detect.py. But the pre-process is too long.
I35KPJM`Z8I8Y)Z6C(}G2SF
I found this line below takes so much time when use tensorrt model.
im = im.half() if half else im.float() # uint8 to fp16/32
When I use best.pt to predict, the pre-process is only 0.2ms. So, how can I solve the problem?
W625JH~X5$SW}2EKTONB{J

Additional

No response

@Monday-Leo Monday-Leo added the question Further information is requested label Nov 26, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2021

👋 Hello @Monday-Leo, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@Monday-Leo thanks for the profiling results!

What is the datatype of your im when it is being cast to half or float?

@glenn-jocher
Copy link
Member

@Monday-Leo also note that detect.py can optionally apply half precision FP16 inference on PyTorch and TRT models with the --half flag, i.e. python detect.py --half. Default is FP32.

@Monday-Leo
Copy link
Author

Monday-Leo commented Nov 26, 2021

I didn't change any code of detect.py . I put my pics under the folder data/images.
dataset = LoadImages(source, img_size=imgsz, stride=stride, auto=pt and not jit)
for path, im, im0s, vid_cap, s in dataset:
t1 = time_sync()
im = torch.from_numpy(im).cuda()
im = im.half() if half else im.float() # uint8 to fp16/32
t2 = time_sync()
I also notice the flag --half and I already set it True. My command is like this
python detect.py --weights=./weights/fp16.engine --half
Running onnx model the problem exists as well, pre-process time is too long.

@Monday-Leo
Copy link
Author

This is the total output:

(yolov5) G:\code\yolov5-master>python detect.py --weights=./weights/fp16.engine --half
detect: weights=['./weights/fp16.engine'], source=data\images, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=0, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=1, hide_labels=False, hide_conf=False, half=True, dnn=False
YOLOv5 2021-11-26 torch 1.10.0+cu102 CUDA:0 (NVIDIA GeForce GTX 1650, 4096MiB)

Loading ./weights/fp16.engine for TensorRT inference...
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] Init CUDA: CPU +389, GPU +0, now: CPU 5313, GPU 885 (MiB)
[11/26/2021-23:04:58] [TRT] [I] Loaded engine size: 19 MiB
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +206, GPU +70, now: CPU 5547, GPU 973 (MiB)
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +169, GPU +88, now: CPU 5717, GPU 1061 (MiB)
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in engine deserialization: CPU +0, GPU +18, now: CPU 0, GPU 18 (MiB)
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU -3, GPU +10, now: CPU 5697, GPU 1075 (MiB)
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +1, GPU +8, now: CPU 5694, GPU 1083 (MiB)
[11/26/2021-23:04:58] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in IExecutionContext creation: CPU +0, GPU +29, now: CPU 0, GPU 47 (MiB)
image 1/21 G:\code\yolov5-master\data\images\2021.10.18.16.jpg: 640x640 1 class4, 1 class17, 1 class19, 1 class20, 1 class22, 1 class33, 1 class39, 1 class40, Done. (0.007s)
image 2/21 G:\code\yolov5-master\data\images\2021.10.18.215.jpg: 640x640 1 class4, 1 class8, 1 class9, 1 class11, 1 class12, 2 class16s, 2 class17s, 1 class18, 2 class19s, 2 class20s, 1 class33, 2 class39s, 1 class40, Done. (0.007s)
image 3/21 G:\code\yolov5-master\data\images\2021_08_226.jpg: 640x640 1 class3, 1 class6, 1 class15, 1 class16, 1 class22, 1 class25, 1 class27, 1 class28, 1 class30, 2 class31s, Done. (0.007s)
image 4/21 G:\code\yolov5-master\data\images\2021_08_293.jpg: 640x640 1 class0, 3 class6s, 1 class10, 1 class16, 1 class30, 1 class34, 1 class37, 2 class38s, 1 class41, Done. (0.007s)
image 5/21 G:\code\yolov5-master\data\images\2021_08_45.jpg: 640x640 1 class1, 1 class5, 1 class15, 1 class21, 1 class23, 1 class25, 2 class26s, 1 class28, 1 class30, 1 class35, Done. (0.007s)
image 6/21 G:\code\yolov5-master\data\images\2021_08_836.jpg: 640x640 1 class0, 2 class6s, 1 class7, 1 class17, 1 class23, 2 class27s, 1 class31, 1 class34, 1 class38, Done. (0.007s)
image 7/21 G:\code\yolov5-master\data\images\2021_08_8729.jpg: 640x640 2 class0s, 1 class2, 1 class12, 1 class15, 1 class20, 1 class22, 1 class26, 2 class29s, 1 class30, 1 class34, 1 class35, 1 class39, Done. (0.007s)
image 8/21 G:\code\yolov5-master\data\images\2021_08_8731.jpg: 640x640 2 class0s, 1 class2, 1 class12, 1 class15, 1 class20, 2 class22s, 1 class26, 2 class29s, 1 class30, 1 class34, 1 class35, 1 class39, Done. (0.007s)
image 9/21 G:\code\yolov5-master\data\images\2021_08_8732.jpg: 640x640 2 class0s, 1 class2, 2 class12s, 1 class15, 1 class20, 2 class22s, 1 class26, 2 class29s, 1 class30, 1 class34, 1 class35, 1 class39, Done. (0.007s)
image 10/21 G:\code\yolov5-master\data\images\2021_08_8735.jpg: 640x640 2 class0s, 1 class2, 1 class12, 1 class15, 1 class20, 1 class22, 1 class26, 1 class29, 1 class30, 1 class34, 1 class35, 1 class39, Done. (0.007s)
image 11/21 G:\code\yolov5-master\data\images\2021_08_8751.jpg: 640x640 3 class0s, 1 class2, 1 class12, 1 class15, 1 class20, 1 class22, 1 class26, 1 class29, 1 class30, 1 class34, 1 class35, 1 class38, 1 class39, Done. (0.007s)
image 12/21 G:\code\yolov5-master\data\images\2021_08_8783.jpg: 640x640 2 class0s, 2 class2s, 1 class12, 1 class15, 1 class20, 1 class22, 2 class26s, 1 class29, 1 class30, 1 class34, 1 class35, 1 class38, 1 class39, Done. (0.007s)
image 13/21 G:\code\yolov5-master\data\images\2021_08_8797.jpg: 640x640 2 class0s, 1 class1, 1 class2, 2 class12s, 1 class15, 1 class25, 1 class29, 2 class34s, 1 class35, 1 class39, Done. (0.007s)
image 14/21 G:\code\yolov5-master\data\images\2021_08_8798.jpg: 640x640 2 class0s, 1 class1, 1 class2, 2 class12s, 1 class15, 1 class20, 1 class25, 1 class29, 1 class34, 1 class35, 1 class36, 1 class38, Done. (0.007s)
image 15/21 G:\code\yolov5-master\data\images\2021_08_8799.jpg: 640x640 2 class0s, 1 class1, 1 class2, 2 class12s, 1 class15, 1 class20, 1 class25, 1 class29, 1 class34, 1 class35, 1 class36, 1 class39, Done. (0.006s)
image 16/21 G:\code\yolov5-master\data\images\2021_08_8800.jpg: 640x640 2 class0s, 2 class1s, 1 class2, 1 class12, 1 class20, 1 class25, 1 class29, 1 class34, 1 class35, 1 class36, 1 class39, Done. (0.007s)
image 17/21 G:\code\yolov5-master\data\images\2021_08_8819.jpg: 640x640 2 class0s, 1 class1, 1 class2, 1 class5, 1 class12, 1 class20, 1 class23, 1 class25, 1 class29, 1 class35, 2 class36s, 1 class38, Done. (0.007s)
image 18/21 G:\code\yolov5-master\data\images\2021_08_8824.jpg: 640x640 2 class0s, 2 class1s, 1 class2, 1 class5, 1 class12, 1 class20, 1 class23, 1 class25, 1 class29, 1 class35, 2 class36s, 1 class39, Done. (0.007s)
image 19/21 G:\code\yolov5-master\data\images\2021_08_8828.jpg: 640x640 2 class0s, 1 class1, 1 class2, 1 class5, 1 class12, 1 class20, 1 class23, 1 class25, 1 class29, 1 class35, 3 class36s, 1 class38, Done. (0.007s)
image 20/21 G:\code\yolov5-master\data\images\2021_08_8831.jpg: 640x640 2 class0s, 1 class1, 1 class2, 1 class12, 1 class20, 1 class23, 1 class25, 1 class29, 1 class35, 2 class36s, 1 class38, 1 class39, Done. (0.007s)
image 21/21 G:\code\yolov5-master\data\images\2021_08_8834.jpg: 640x640 2 class0s, 1 class1, 2 class2s, 1 class12, 1 class20, 1 class23, 1 class25, 1 class29, 1 class35, 2 class36s, 1 class38, Done. (0.007s)
Speed: 69.8ms pre-process, 7.0ms inference, 1.6ms NMS per image at shape (1, 3, 640, 640)
Results saved to runs\detect\exp23

You can see pre-process time is 69.8ms.

@Monday-Leo
Copy link
Author

Monday-Leo commented Nov 26, 2021

I have already found the problem. The first pre-process time is 1400ms and then the second pic drop to normal speed. Maybe warmup is needed. Now detect.py only warmup for pytorch model. At 100 line in detect.py, if pt and device.type != 'cpu':, here use "and",so onnx,engine,etc will not run warmup.But I think warmup is necessary for all models.
Finally, thanks for your reply and hope yoloV5 gets better!

@glenn-jocher
Copy link
Member

@Monday-Leo good news 😃! Your original issue may now be fixed ✅ in PR #5810. This PR adds warmup to TensorRT and ONNX models on GPU.

To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

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

Successfully merging a pull request may close this issue.

2 participants