forked from NVIDIA/TensorRT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rajeev Rao <[email protected]>
- Loading branch information
1 parent
1002aad
commit b936ebd
Showing
80 changed files
with
1,358 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,6 @@ venv/ | |
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Crash dumps | ||
core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
tools/Polygraphy/examples/cli/run/05_comparing_with_custom_data/README.md
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
tools/Polygraphy/examples/cli/run/05_comparing_with_custom_data/data_loader.py
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
tools/Polygraphy/examples/cli/run/05_comparing_with_custom_input_data/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Comparing With Custom Input Data | ||
|
||
## Introduction | ||
|
||
In some cases, we may want to run comparisons using custom input data. | ||
Polygraphy provides multiple ways to do so, which are detailed [here](../../../../polygraphy/tools/README.md#using-custom-input-data). | ||
|
||
In this example, we'll demonstrate 2 different approaches: | ||
|
||
1. Using a data loader script by defining a `load_data()` function in a Python script (`data_loader.py`). | ||
Polygraphy will use `load_data()` to generate inputs at runtime. | ||
|
||
2. Using a JSON file containing pre-generated inputs. | ||
For convenience, we'll use our script from above (`data_loader.py`) to save the inputs | ||
generated by `load_data()` to a file called `custom_inputs.json`. | ||
|
||
*TIP: Generally, a data loader script is preferrable when working with large amounts of input data* | ||
*as it avoids the need to write to the disk.* | ||
*On the other hand, JSON files may be more portable and can help ensure reproducibility.* | ||
|
||
Finally, we'll supply our custom input data to `polygraphy run` and compare outputs between | ||
ONNX-Runtime and TensorRT. | ||
|
||
Since our model has dynamic shapes, we'll need to set up a TensorRT Optimization Profile. | ||
For details on how we can do this via the command-line, | ||
see [`convert` example 03](../../convert/03_dynamic_shapes_in_tensorrt). | ||
For simplicitly, we'll create a profile where `min` == `opt` == `max`. | ||
|
||
*NOTE: It is important that our optimization profile works with the shapes provided by our* | ||
*custom data loader. In our very simple case, the data loader always generates inputs of* | ||
*shape (1, 2, 28, 28), so we just need to ensure this falls within [`min`, `max`].* | ||
|
||
## Running The Example | ||
|
||
1. Run the script to save input data to the disk. | ||
*NOTE: This is only necessary for option 2.* | ||
```bash | ||
python3 data_loader.py | ||
``` | ||
|
||
2. Run the model with TensorRT and ONNX-Runtime using custom input data: | ||
- Option 1: Using the data loader script: | ||
|
||
```bash | ||
polygraphy run dynamic_identity.onnx --trt --onnxrt \ | ||
--trt-min-shapes X:[1,2,28,28] --trt-opt-shapes X:[1,2,28,28] --trt-max-shapes X:[1,2,28,28] \ | ||
--data-loader-script data_loader.py | ||
``` | ||
|
||
- Option 2: Using the JSON file containing the saved inputs: | ||
|
||
```bash | ||
polygraphy run dynamic_identity.onnx --trt --onnxrt \ | ||
--trt-min-shapes X:[1,2,28,28] --trt-opt-shapes X:[1,2,28,28] --trt-max-shapes X:[1,2,28,28] \ | ||
--load-inputs custom_inputs.json | ||
``` |
43 changes: 43 additions & 0 deletions
43
tools/Polygraphy/examples/cli/run/05_comparing_with_custom_input_data/data_loader.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
""" | ||
Demonstrates two methods of loading custom input data in Polygraphy: | ||
Option 1: Defines a `load_data` function that returns a generator yielding | ||
feed_dicts so that this script can be used as the argument for | ||
the --data-loader-script command-line parameter. | ||
Option 2: Writes input data to a JSON file that can be used as the argument for | ||
the --load-inputs command-line parameter. | ||
""" | ||
import numpy as np | ||
from polygraphy.json import save_json | ||
|
||
INPUT_SHAPE = (1, 2, 28, 28) | ||
|
||
# Option 1: Define a function that will yield feed_dicts (i.e. Dict[str, np.ndarray]) | ||
def load_data(): | ||
for _ in range(5): | ||
yield {"x": np.ones(shape=INPUT_SHAPE, dtype=np.float32)} # Still totally real data | ||
|
||
|
||
# Option 2: Create a JSON file containing the input data using the `save_json()` helper. | ||
# The input to `save_json()` should have type: List[Dict[str, np.ndarray]]. | ||
# For convenience, we'll reuse our `load_data()` implementation to generate the list. | ||
input_data = list(load_data()) | ||
save_json(input_data, "custom_inputs.json", description="custom input data") |
File renamed without changes.
Oops, something went wrong.