About Keras
Keras is similar to Estimator. They are both TensorFlow high-level APIs and provide convenient graph construction functions and convenient APIs for training, evaluation, validation, and export. To use the Keras API to develop a training script, perform the following steps:
- Preprocess the data.
- Construct a model.
- Build the model.
- Train the model.
When Keras is migrated to the Ascend platform, some functions are restricted, for example, the dynamic learning rate is not supported. Therefore, you are not advised to migrate a network script developed by using Keras to the Ascend platform. To run a Keras script on the Ascend platform, you can use either of the following migration methods:
- On the Ascend platform, you can directly use the native Keras API for training. However, only one session.run call is allowed and the number of iterations per training loop on the Ascend AI Processor is fixed at 1. For details, see Native Keras API Support.
- To reduce the number of interactions between the host and devices and shorten the training duration, you need to use the model_to_npu_estimator API to convert the model constructed by using Keras into an NPUEstimator object. Besides, you need to specify the number of iterations per training loop on the Ascend AI Processor per sess.run() call by using the iterations_per_loop parameter in NPURunConfig. For details, see Keras to NPUEstimator Conversion.