Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
856fd5f
Refactor Inference and Benchmarking Logic
DimaBir Oct 15, 2023
dc10c78
Fixing import modules path
DimaBir Oct 15, 2023
17ef63c
Fixing import modules path
DimaBir Oct 15, 2023
8ec05ba
Fixing import modules path
DimaBir Oct 15, 2023
338dae5
Fixing import modules path
DimaBir Oct 15, 2023
c022e06
Fixing import modules path
DimaBir Oct 15, 2023
d3e862e
Fixing import modules path
DimaBir Oct 15, 2023
42ea101
Fixing import modules path
DimaBir Oct 15, 2023
fab8073
Fixing import modules path
DimaBir Oct 15, 2023
949803f
Fixing import modules path
DimaBir Oct 15, 2023
eaf2d83
Fixing import modules path
DimaBir Oct 15, 2023
9569e0f
Fixing import modules path
DimaBir Oct 15, 2023
6594c02
Fixing import modules path
DimaBir Oct 15, 2023
f84745f
Fixing import modules path
DimaBir Oct 15, 2023
826e25f
Fixing import modules path
DimaBir Oct 15, 2023
78c7fb2
Fixing import modules path
DimaBir Oct 15, 2023
4664081
Fixing import modules path
DimaBir Oct 15, 2023
75e60b7
Fixing import modules path
DimaBir Oct 15, 2023
e3731b8
Fixing import modules path
DimaBir Oct 15, 2023
075076c
Fixing import modules path
DimaBir Oct 15, 2023
f7399a1
Fixing import modules path
DimaBir Oct 15, 2023
96e5c0e
Fixing import modules path
DimaBir Oct 15, 2023
56348c6
Fixing import modules path
DimaBir Oct 15, 2023
3c4ef7a
Fixing import modules path
DimaBir Oct 15, 2023
5fe420a
Fixing import modules path
DimaBir Oct 15, 2023
6ac019c
Fixing import modules path
DimaBir Oct 15, 2023
c3ffbfe
Fixing import modules path
DimaBir Oct 15, 2023
df27f19
Fixing import modules path
DimaBir Oct 15, 2023
28d9499
Fixing import modules path
DimaBir Oct 15, 2023
3d09fba
Fixing import modules path
DimaBir Oct 15, 2023
ab1e9eb
Fixing import modules path
DimaBir Oct 15, 2023
afd7baa
Cleaned files
DimaBir Oct 15, 2023
1d2fdad
Cleaned files
DimaBir Oct 15, 2023
a11d295
Cleaned files
DimaBir Oct 15, 2023
249ebc0
Cleaned files
DimaBir Oct 15, 2023
0257df7
Updated files before refactor
DimaBir Oct 15, 2023
45c5174
Updated files before refactor
DimaBir Oct 15, 2023
201a57d
Updated files before refactor
DimaBir Oct 15, 2023
1092977
Updated files before refactor
DimaBir Oct 15, 2023
ab1da39
Fixing model.eval
DimaBir Oct 16, 2023
58bea8d
Fixing model.eval
DimaBir Oct 16, 2023
7697614
Fixing model.eval
DimaBir Oct 16, 2023
ac12a28
Fixing model.eval
DimaBir Oct 16, 2023
02dd2f8
Fixing model.eval
DimaBir Oct 16, 2023
e126230
Fixing model.eval
DimaBir Oct 16, 2023
a4f9450
Fixing model.eval
DimaBir Oct 16, 2023
cac7abd
Fixing model.eval
DimaBir Oct 16, 2023
e222ea4
Fixing model.eval
DimaBir Oct 16, 2023
14e9abc
Fixing model.eval
DimaBir Oct 16, 2023
3f869e7
Refactored inference_base.py
DimaBir Oct 16, 2023
d9baa30
Refactored inference_base.py
DimaBir Oct 16, 2023
cdae50e
Refactored onnx_inference.py
DimaBir Oct 16, 2023
14793ce
Refactored ov_inference.py
DimaBir Oct 16, 2023
a2f72de
Refactored pytorch_inference.py
DimaBir Oct 16, 2023
b9e96c5
Added debug flag
DimaBir Oct 16, 2023
cf153ad
Added debug flag
DimaBir Oct 16, 2023
cf2424c
Added debug flag
DimaBir Oct 16, 2023
96ce380
Refactored tensorrt_inference.py
DimaBir Oct 16, 2023
7961042
Refactored tensorrt_inference.py
DimaBir Oct 16, 2023
ed142f7
Refactored tensorrt_inference.py
DimaBir Oct 16, 2023
0a92651
Refactored tensorrt_inference.py
DimaBir Oct 16, 2023
c0491fb
Refactored tensorrt_inference.py
DimaBir Oct 16, 2023
2c9c0e5
Fixing errors for gpu
DimaBir Oct 16, 2023
cda859f
Dded debug prints
DimaBir Oct 16, 2023
a947d78
Added debug prints
DimaBir Oct 16, 2023
72f672e
Added debug prints
DimaBir Oct 16, 2023
dbbb6df
Added debug prints
DimaBir Oct 16, 2023
3572a62
Added debug prints
DimaBir Oct 16, 2023
8ee038b
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
21bd36b
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
0e84803
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
e3cd401
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
61fe8fe
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
5b8329d
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
8034ff9
Fixed tensorrt_inference.py
DimaBir Oct 16, 2023
e1de139
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
72a90a7
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
6653ad0
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
d2a81b6
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
3bc7029
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
02e9fda
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
f24ed81
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
e23a24f
Expanded batch to be dynamic size
DimaBir Oct 16, 2023
fe70cfd
Updated README.md
DimaBir Oct 16, 2023
f03f3a5
Updated README.md
DimaBir Oct 16, 2023
7253b4e
Updated README.md
DimaBir Oct 16, 2023
63c5938
Updated README.md
DimaBir Oct 16, 2023
5bc6e59
Updated README.md
DimaBir Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 31 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@
2. [Requirements](#requirements)
- [Steps to Run](#steps-to-run)
- [Example Command](#example-command)
3. [GPU-CUDA Results](#gpu-cuda-results) ![Static Badge](https://img.shields.io/badge/update-orange)
- [Results explanation](#results-explanation)
- [Example Input](#example-input)
- [Example prediction results](#example-prediction-results)
- [PC Setup](#pc-setup)
4. [Benchmark Implementation Details](#benchmark-implementation-details) ![New](https://img.shields.io/badge/-New-842E5B)
3. [CPU Results](#cpu-results) ![Static Badge](https://img.shields.io/badge/update-orange)
4. [GPU (CUDA) Results](#gpu-cuda-results) ![Static Badge](https://img.shields.io/badge/update-orange)
5. [Benchmark Implementation Details](#benchmark-implementation-details) ![New](https://img.shields.io/badge/-New-842E5B)
- [PyTorch CPU & CUDA](#pytorch-cpu--cuda)
- [TensorRT FP32 & FP16](#tensorrt-fp32--fp16)
- [ONNX](#onnx)
- [OpenVINO](#openvino)
5. [Extra](#extra) ![New](https://img.shields.io/badge/-New-842E5B)
- [Linux Server Inference](#linux-server-inference)
- [Prediction results](#prediction-results)
- [PC Setup Linux](#pc-setup-linux)
6. [Author](#author)
7. [References](#references)


<img src="./inference/plot_latest.png" width="100%">
<img src="./inference/plot_new_gpu.png" width="100%">

## Overview
This project showcases inference with a PyTorch ResNet-50 model and its optimization using ONNX, OpenVINO, and NVIDIA TensorRT. The script infers a user-specified image and displays top-K predictions. Benchmarking covers configurations like PyTorch CPU, ONNX CPU, OpenVINO CPU, PyTorch CUDA, TensorRT-FP32, and TensorRT-FP16.
Expand All @@ -50,13 +43,13 @@ Refer to the [Steps to Run](#steps-to-run) section for Docker instructions.
1. **CPU Deployment**:
For systems without a GPU or CUDA support, simply use the default base image.
```bash
docker build -t my_image_cpu .
docker build -t cpu_img .
```

2. **GPU Deployment**:
If your system has GPU and CUDA support, you can use the TensorRT base image to leverage GPU acceleration.
```bash
docker build --build-arg ENVIRONMENT=gpu --build-arg BASE_IMAGE=nvcr.io/nvidia/tensorrt:23.08-py3 -t my_project_image_gpu .
docker build --build-arg ENVIRONMENT=gpu --build-arg BASE_IMAGE=nvcr.io/nvidia/tensorrt:23.08-py3 -t gpu_img .
```

### Running the Docker Container
Expand All @@ -78,7 +71,7 @@ python main.py [--mode all]
### Arguments
- `--image_path`: (Optional) Specifies the path to the image you want to predict.
- `--topk`: (Optional) Specifies the number of top predictions to show. Defaults to 5 if not provided.
- `--mode`: (Optional) Specifies the model's mode for exporting and running. Choices are: `onnx`, `ov`, `cuda`, and `all`. If not provided, it defaults to `all`.
- `--mode`: (Optional) Specifies the model's mode for exporting and running. Choices are: `onnx`, `ov`, `cpu`, `cuda`, `tensorrt`, and `all`. If not provided, it defaults to `all`.

### Example Command
```sh
Expand All @@ -87,17 +80,33 @@ python main.py --topk 3 --mode=all --image_path="./inference/train.jpg"

This command will run predictions on the chosen image (`./inference/train.jpg`), show the top 3 predictions, and run all available models. Note: plot created only for `--mode=all` and results plotted and saved to `./inference/plot.png`

## GPU-CUDA Results
## CPU Results
<img src="./inference/plot.png" width="70%">

### Prediction results
```
#1: 15% Egyptian cat
#2: 14% tiger cat
#3: 9% tabby
#4: 2% doormat
#5: 2% lynx
```
### PC Setup Linux
- CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
- RAM: 16 GB
- GPU: None

## GPU (CUDA) Results
### Inference Benchmark Results
<img src="./inference/plot_latest.png" width="70%">
<img src="./inference/plot_new_gpu.png" width="100%">

### Results explanation
- `PyTorch_cpu: 978.71 ms` indicates the average batch time when running the `PyTorch` model on `CPU` device.
- `PyTorch_cuda: 30.11 ms` indicates the average batch time when running the `PyTorch` model on the `CUDA` device.
- `TRT_fp32: 19.20 ms` shows the average batch time when running the model with `TensorRT` using `float32` precision.
- `TRT_fp16: 7.32 ms` indicates the average batch time when running the model with `TensorRT` using `float16` precision.
- ![New](https://img.shields.io/badge/-New-842E5B)`ONNX: 15.95 ms` indicates the average batch inference time when running the `PyTorch` converted to the `ONNX` model on the `CPU` device.
- ![New](https://img.shields.io/badge/-New-842E5B)`OpenVINO: 13.37 ms` indicates the average batch inference time when running the `ONNX` model converted to `OpenVINO` on the `CPU` device.
- `PyTorch_cpu: 32.83 ms` indicates the average batch time when running the `PyTorch` model on `CPU` device.
- `PyTorch_cuda: 5.59 ms` indicates the average batch time when running the `PyTorch` model on the `CUDA` device.
- `TRT_fp32: 1.69 ms` shows the average batch time when running the model with `TensorRT` using `float32` precision.
- `TRT_fp16: 1.69 ms` indicates the average batch time when running the model with `TensorRT` using `float16` precision.
- ![New](https://img.shields.io/badge/-New-842E5B)`ONNX: 16.01 ms` indicates the average batch inference time when running the `PyTorch` converted to the `ONNX` model on the `CPU` device.
- ![New](https://img.shields.io/badge/-New-842E5B)`OpenVINO: 15.65 ms` indicates the average batch inference time when running the `ONNX` model converted to `OpenVINO` on the `CPU` device.

### Example Input
Here is an example of the input image to run predictions and benchmarks on:
Expand Down Expand Up @@ -158,33 +167,6 @@ OpenVINO is a toolkit from Intel that optimizes deep learning model inference fo
4. Perform inference on the provided image using the OpenVINO model.
5. Benchmark results, including average inference time, are logged for the OpenVINO model.

## Extra
### Linux Server Inference
<img src="./inference/plot_linux_server.png" width="70%">

### Prediction results
`model.log` file content
```
Running prediction for OV model
#1: 15% Egyptian cat
#2: 14% tiger cat
#3: 9% tabby
#4: 2% doormat
#5: 2% lynx


Running prediction for ONNX model
#1: 15% Egyptian cat
#2: 14% tiger cat
#3: 9% tabby
#4: 2% doormat
#5: 2% lynx
```
### PC Setup Linux
- CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
- RAM: 16 GB
- GPU: None

## Author
[DimaBir](https://github.com/DimaBir)

Expand Down
Empty file removed benchmark/__init__.py
Empty file.
247 changes: 0 additions & 247 deletions benchmark/benchmark_models.py

This file was deleted.

Loading