# auto_decomposition

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | x |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | x |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | x |
| Atlas 200I/500 A2 推理产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |


#### 功能说明

根据用户提供的Caffe原始模型（.prototxt和.caffemodel），生成张量分解后的模型文件以及权重文件。


#### 函数原型

```
auto_decomposition(model_file,weights_file,new_model_file,new_weights_file)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| model\_file | 输入 | 含义：用户Caffe模型的定义文件，格式为.prototxt。 数据类型：string |
| weights\_file | 输入 | 含义：用户训练好的Caffe模型权重文件，格式为.caffemodel。 数据类型：string |
| new\_model\_file | 输入 | 含义：张量分解后的Caffe模型定义文件，格式为.prototxt，例如xx\_tensor\_decomposition.prototxt。 数据类型：string |
| new\_weights\_file | 输入 | 含义：张量分解后的Caffe模型权重文件，格式为.caffemodel，例如xx\_tensor\_decomposition.caffemodel。 数据类型：string |


#### 返回值说明

无


#### 约束说明

- 用户提供用于转换的原始Caffe模型，需要保证prototxt文件和caffemodel配套。
- 用户调用张量分解接口函数，输入原始模型路径以及模型分解后的保存路径，接口函数对符合分解条件的卷积层进行自动分解，约束请参见  分解约束
。


#### 调用示例

```
from amct_caffe.tensor_decompose import auto_decomposition
auto_decomposition(model_file='ResNet-50-deploy.prototxt',
                  weights_file='ResNet-50-weights.caffemodel',
                  new_model_file='ResNet-50-deploy_tensor_decomposition.prototxt',
                  new_weights_file='ResNet-50-deploy_tensor_decomposition.caffemodel')
```

落盘文件说明：

- 张量分解后的模型定义文件，格式为.prototxt。
- 张量分解后的模型权重文件，格式为.caffemodel。
