ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.39k stars 16.26k forks source link

wrong output with segment/predict.py on tensorrt engine for custom dataset #10284

Closed GreatV closed 1 year ago

GreatV commented 1 year ago

Search before asking

YOLOv5 Component

Detection, Export

Bug

here is the output of .engine model

 python segment/predict.py --source ~/train_dataset/1.png --weights runs/train-seg/exp/weights/best.engine

1.png

Here is the output of .onnx model

 python segment/predict.py --source ~/train_dataset/1.png --weights runs/train-seg/exp/weights/best.onnx

99240191

Environment

Minimal Reproducible Example

python export.py  --weights runs/train-seg/exp/weights/best.pt --include engine --simplify --device 0

 python segment/predict.py --source ~/train_dataset/1.png --weights runs/train-seg/exp/weights/best.engine

Additional

TensorRT: input "images" with shape(1, 3, 640, 640) DataType.FLOAT
TensorRT: output "output0" with shape(1, 25200, 38) DataType.FLOAT
TensorRT: output "output1" with shape(1, 32, 160, 160) DataType.FLOAT
TensorRT: building FP32 engine as runs/train-seg/exp/weights/best.engine

Are you willing to submit a PR?

github-actions[bot] commented 1 year ago

πŸ‘‹ Hello @GreatV, 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 support@ultralytics.com.

Requirements

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

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

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

YOLOv5 CI

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

glenn-jocher commented 1 year ago

@GreatV this may be a TRT issue. Are you using the latest version of TRT 8?

On Colab we see identical results on TRT Engine benchmarking for segmentation models (using the latest TRT, 8.4.3.1), i.e.:

Screenshot 2022-11-25 at 21 37 05
GreatV commented 1 year ago

@glenn-jocher My custom dataset has only one class, does this matter?

(yolo) ubuntu@VM-0-3-ubuntu:~/yolov5$ python export.py  --weights runs/train-seg/exp/weights/best.pt --include engine --simplify --device 0
export: data=data/coco128.yaml, weights=['runs/train-seg/exp/weights/best.pt'], imgsz=[640, 640], batch_size=1, device=0, half=False, inplace=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['engine']
YOLOv5 πŸš€ v7.0-5-gbfa1f23 Python-3.9.15 torch-1.13.0 CUDA:0 (Tesla T4, 14961MiB)

Fusing layers... 
Model summary: 165 layers, 7398422 parameters, 0 gradients, 25.7 GFLOPs

PyTorch: starting from runs/train-seg/exp/weights/best.pt with output shape (1, 25200, 38) (14.4 MB)

ONNX: starting export with onnx 1.12.0...
ONNX: simplifying with onnx-simplifier 0.4.10...
ONNX: export success βœ… 1.6s, saved as runs/train-seg/exp/weights/best.onnx (28.7 MB)

TensorRT: starting export with TensorRT 8.4.3.1...
[11/26/2022-15:15:30] [TRT] [I] [MemUsageChange] Init CUDA: CPU +302, GPU +0, now: CPU 2487, GPU 1265 (MiB)
[11/26/2022-15:15:35] [TRT] [I] [MemUsageChange] Init builder kernel library: CPU +59, GPU +0, now: CPU 2565, GPU 1265 (MiB)
/home/ubuntu/yolov5/export.py:271: DeprecationWarning: Use set_memory_pool_limit instead.
  config.max_workspace_size = workspace * 1 << 30
[11/26/2022-15:15:35] [TRT] [I] ----------------------------------------------------------------
[11/26/2022-15:15:35] [TRT] [I] Input filename:   runs/train-seg/exp/weights/best.onnx
[11/26/2022-15:15:35] [TRT] [I] ONNX IR version:  0.0.7
[11/26/2022-15:15:35] [TRT] [I] Opset version:    12
[11/26/2022-15:15:35] [TRT] [I] Producer name:    pytorch
[11/26/2022-15:15:35] [TRT] [I] Producer version: 1.13.0
[11/26/2022-15:15:35] [TRT] [I] Domain:           
[11/26/2022-15:15:35] [TRT] [I] Model version:    0
[11/26/2022-15:15:35] [TRT] [I] Doc string:       
[11/26/2022-15:15:35] [TRT] [I] ----------------------------------------------------------------
[11/26/2022-15:15:35] [TRT] [W] onnx2trt_utils.cpp:369: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
TensorRT: input "images" with shape(1, 3, 640, 640) DataType.FLOAT
TensorRT: output "output0" with shape(1, 25200, 38) DataType.FLOAT
TensorRT: output "output1" with shape(1, 32, 160, 160) DataType.FLOAT
TensorRT: building FP32 engine as runs/train-seg/exp/weights/best.engine
/home/ubuntu/yolov5/export.py:298: DeprecationWarning: Use build_serialized_network instead.
  with builder.build_engine(network, config) as engine, open(f, 'wb') as t:
[11/26/2022-15:15:37] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +8, now: CPU 2599, GPU 1273 (MiB)
[11/26/2022-15:15:37] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 2599, GPU 1281 (MiB)
[11/26/2022-15:15:37] [TRT] [W] TensorRT was linked against cuDNN 8.4.1 but loaded cuDNN 8.3.2
[11/26/2022-15:15:37] [TRT] [I] Local timing cache in use. Profiling results in this builder pass will not be stored.
[11/26/2022-15:16:22] [TRT] [I] Some tactics do not have sufficient workspace memory to run. Increasing workspace size will enable more tactics, please check verbose output for requested sizes.
[11/26/2022-15:17:20] [TRT] [I] Detected 1 inputs and 5 output network tensors.
[11/26/2022-15:17:21] [TRT] [I] Total Host Persistent Memory: 168992
[11/26/2022-15:17:21] [TRT] [I] Total Device Persistent Memory: 0
[11/26/2022-15:17:21] [TRT] [I] Total Scratch Memory: 0
[11/26/2022-15:17:21] [TRT] [I] [MemUsageStats] Peak memory usage of TRT CPU/GPU memory allocators: CPU 0 MiB, GPU 0 MiB
[11/26/2022-15:17:21] [TRT] [I] [BlockAssignment] Algorithm ShiftNTopDown took 22.6327ms to assign 7 blocks to 139 nodes requiring 35635200 bytes.
[11/26/2022-15:17:21] [TRT] [I] Total Activation Memory: 35635200
[11/26/2022-15:17:21] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in building engine: CPU +0, GPU +0, now: CPU 0, GPU 0 (MiB)
[11/26/2022-15:17:21] [TRT] [W] The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
[11/26/2022-15:17:21] [TRT] [W] The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
TensorRT: export success βœ… 112.6s, saved as runs/train-seg/exp/weights/best.engine (31.4 MB)

Export complete (116.1s)
Results saved to /home/ubuntu/yolov5/runs/train-seg/exp/weights
Detect:          python segment/detect.py --weights runs/train-seg/exp/weights/best.engine 
Validate:        python segment/val.py --weights runs/train-seg/exp/weights/best.engine 
PyTorch Hub:     model = torch.hub.load('ultralytics/yolov5', 'custom', 'runs/train-seg/exp/weights/best.engine')  # WARNING ⚠️ SegmentationModel not yet supported for PyTorch Hub AutoShape inference
Visualize:       https://netron.app
glenn-jocher commented 1 year ago

@GreatV I'll try to reproduce with GlobalWheat2020.yaml. In the meantime I've corrected the Usage example for segmentation exports to point to segment/predict.py rather than segment/detect.py in https://github.com/ultralytics/yolov5/pull/10303

glenn-jocher commented 1 year ago

@GreatV oh, nevermind, we actually don't have a single-class segmentation dataset to train. You'll have to debug this one on your own.

GreatV commented 1 year ago

@glenn-jocher OK, I will try to figure it out.

github-actions[bot] commented 1 year ago

πŸ‘‹ Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 πŸš€ resources:

Access additional Ultralytics ⚑ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 πŸš€ and Vision AI ⭐!

glenn-jocher commented 11 months ago

@GreatV great! Feel free to ask if you have any further questions. Good luck!