---
title: 函数：set_input_dynamic_dims
description: "如果模型输入的Shape是动态的、输入数据Format为ND格式（ND表示支持任意格式），在模型执行前调用本接口设置模型推理时具体维度的值。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendgraphapi/aclpythondevg_01_0159.html
sourcePath: /source/zh/canncommercial/900/API/ascendgraphapi/aclpythondevg_01_0159.html
indexId: fbdc60e05cce1e8050481ea609a74bb2ce3ef69029ce2231ac5dcc8de717a0b275
---
# 函数：set_input_dynamic_dims

#### 功能说明

如果模型输入的Shape是动态的、输入数据Format为ND格式（ND表示支持任意格式），在模型执行前调用本接口设置模型推理时具体维度的值。


#### 函数原型

- C函数原型
  1 aclError aclmdlSetInputDynamicDims(uint32_t modelId, aclmdlDataset *dataset, size_t index, const aclmdlIODims *dims)

- python函数
  1 ret = acl.mdl.set_input_dynamic_dims(model_id, dataset_in, index, dims)


#### 参数说明

| 参数名 | 说明 |
| --- | --- |
| modelId | int，模型ID。 可在以下接口成功加载模型后获取到模型ID。 acl.mdl.load\_from\_file acl.mdl.load\_from\_mem acl.mdl.load\_from\_file\_with\_mem acl.mdl.load\_from\_mem\_with\_mem |
| dataset | int，表示模型的输入数据。 使用aclmdlDataset类型的数据描述模型推理时的输入数据，输入的内存地址、内存大小用aclDataBuffer类型的数据来描述，aclmdlDataset。 |
| index | int，标识动态维度的输入index。 需调用acl.mdl.get\_input\_index\_by\_name接口获取，输入名称固定为“ascend\_mbatch\_shape\_data”。 |
| dims | dict，指定具体某一档的所有维度信息，具体请参见aclmdlIODims。 可以调用acl.mdl.get\_input\_dynamic\_dims接口获取指定模型支持的动态维度档位数以及每一档中的值。 例如：在ATC工具进行模型转换时，使用以下参数：input\_shape="data:1,1,40,\-1;label:1,\-1;mask:\-1,\-1" ，dynamic\_dims="20,20,1,1; 40,40,2,2; 80,60,4,4" 若输入数据的真实维度为（1,1,40,20,1,20,1,1），则dims输入示例如下（name暂不使用）： dims = {'dimCount': 8, 'name': '', 'dims': [1,1,40,20,1,20,1,1]} |


#### 返回值说明

| 返回值 | 说明 |
| --- | --- |
| ret | int，错误码，返回0表示成功，返回其它值表示失败。 |


#### 资源参考

接口调用流程与示例，参见动态Batch/动态分辨率/动态维度（设置多档维度值）(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/acldevg/aclpythondevg_0046.html)。
