# Build engine from onnx model, can not set dynamic shape right

**URL:** <https://forums.developer.nvidia.com/t/build-engine-from-onnx-model-can-not-set-dynamic-shape-right/258271>\
**Category:** TensorRT\
**Created:** [June 29, 2023, 8:13am UTC](https://forums.developer.nvidia.com/t/build-engine-from-onnx-model-can-not-set-dynamic-shape-right/258271 "2023-06-29T08:13:43Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![AaronCoC](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@AaronCoC](https://forums.developer.nvidia.com/u/AaronCoC)\
**Post date:** [June 30, 2023, 2:27am UTC](https://forums.developer.nvidia.com/t/build-engine-from-onnx-model-can-not-set-dynamic-shape-right/258271/4 "2023-06-30T02:27:31Z")

</div>

The model and code I’ve already sent in Relevant Files block.  
And I tried trtexec to convert the onnx, if I not set the min/opt/max dynamic shapes with command

```auto
${trtexec} --onnx=output/models/${model_name}.onnx \
    --saveEngine=output/models/${model_name}.engine \
    --dumpOutput \
    --dumpProfile \
    --dumpLayerInfo --useSpinWait \
    --separateProfileRun >output/models/log/trtexec.log

```

I will got:

 ![image](https://global.discourse-cdn.com/nvidia/original/4X/2/6/4/2642de4bd33788327c6d2a2c0d4c0419a7cd35c7.png)

If I set the dynamic shapes with command:

```sh
min_batch=1
max_batch=8
opt_batch=4

${trtexec} --onnx=output/models/${model_name}.onnx \
    --saveEngine=output/models/${model_name}.engine \
    --minShapes=element_states_batch:${min_batch}x136x128,element_hidden_states:${min_batch}x136x128,element_states_mask:${min_batch}x136,lane_states_batch:${min_batch}x128x128,lane_mask:${min_batch}x128,sparse_goals_2D:${min_batch}x1536x2,sparse_goals_2D_mask:${min_batch}x1536 \
    --optShapes=element_states_batch:${opt_batch}x136x128,element_hidden_states:${opt_batch}x136x128,element_states_mask:${opt_batch}x136,lane_states_batch:${opt_batch}x128x128,lane_mask:${opt_batch}x128,sparse_goals_2D:${opt_batch}x1536x2,sparse_goals_2D_mask:${opt_batch}x1536 \
    --maxShapes=element_states_batch:${max_batch}x136x128,element_hidden_states:${max_batch}x136x128,element_states_mask:${max_batch}x136,lane_states_batch:${max_batch}x128x128,lane_mask:${max_batch}x128,sparse_goals_2D:${max_batch}x1536x2,sparse_goals_2D_mask:${max_batch}x1536 \
    --dumpOutput \
    --dumpProfile \
    --dumpLayerInfo --useSpinWait \
    --separateProfileRun >output/models/log/trtexec.log

```

And I got this:

 ![image](https://global.discourse-cdn.com/nvidia/original/4X/6/3/1/63149f82bc895a14bab70552f8d064746007ae7a.png)  
Whole trtexec log:  
[trtexec.log](https://forums.developer.nvidia.com/uploads/short-url/a7lDemu7f8e2f88Jx8P0PwoJ1M9.log) (10.0 KB)

---

_[View the full topic](https://forums.developer.nvidia.com/t/build-engine-from-onnx-model-can-not-set-dynamic-shape-right/258271)._
