---
title: model_to_npu_estimator
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/TensorFlowCommercial/latest/migration/tfmigr1/tfmigr1_tfadapi_0092.html
sourcePath: /source/zh/TensorFlowCommercial/900/migration/tfmigr1/tfmigr1_tfadapi_0092.html
indexId: 1cf38a825929f53ef9a34046a2e8497b4de7191f807753f450d73e329765400879
---
# model_to_npu_estimator

#### 产品支持情况

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


#### 功能说明

将通过Keras构建的模型转换为NPUEstimator对象。


#### 函数原型

```
def model_to_npu_estimator(keras_model=None,
                           keras_model_path=None,
                           custom_objects=None,
                           model_dir=None,
                           checkpoint_format='saver',
                           config=None,
                           job_start_file='')
```


#### 参数说明

| 参数名 | 描述 |
| --- | --- |
| keras\_model | 已经编译好的Keras模型对象。 该参数与keras\_model\_path不可同时传入。 |
| keras\_model\_path | 保存在磁盘上的已编译Keras模型的路径。可以使用Keras模型的save()方法生成HDF5格式的Keras模型。 该参数与keras\_model不可同时传入。 |
| custom\_objects | 自定义对象的字典，在构造Keras时，如果有自定义的层或者函数，在加载模型时需要使用custom\_objects。 |
| model\_dir | 保存模型路径，用于保存或恢复模型文件。如果没有配置，那么将使用config中的model\_dir配置。如果都设置了，那这两个配置项必须一样。如果都设置为None，就会使用临时的文件夹/tmp。 |
| checkpoint\_format | 设置训练时NPUEstimator保存的checkpoint的格式。取值： saver（默认）：表示通过tf.train.Saver()保存模型。 checkpoint：表示通过tf.train.Checkpoint ()保存模型，tf.train.Checkpoint与tf.train.Saver相比，强大之处在于其支持在即时执行模式下“延迟”恢复变量。 |
| config | NPURunConfig类对象，用于配置NPUEstimator的运行参数。 关于NPURunConfig类的构造函数，请参见NPURunConfig构造函数。 |
| job\_start\_file | CSA场景下用于启动训练进程的配置文件路径。 |


#### 返回值

根据传入的keras model返回一个NPUEstimator对象。


#### 约束说明

目前仅功能模型和序列模型（为Keras构图方式）支持通过model_to_npu_estimator接口转换为NPUEstimator对象。
