Training Result Check
The key steps are as follows:
- View the training results.
- To export the sparse table data in .npy format, call the export API.
- To export the .pb model file, call the export_saved_model API of Estimator. The following is an example:
import os import tensorflow as tf if tf.__version__.startswith("1"): from npu_bridge.npu_init import NPURunConfig, NPUEstimator else: from npu_device.compat.v1.npu_init import NPURunConfig, NPUEstimator # For details, see "Running Configuration" and "Creating an Estimator Object" in Porting with Estimator. run_config = NPURunConfig(...) est = NPUEstimator(...) # Generally, the export_saved_model API is called after the train or train_and_evaluate call. def _serving_input_fn(): # Adjust the input based on the specific service model. The following uses the input of the little demo estimator model as an example. inputs = { "user_ids": tf.compat.v1.placeholder(shape=(None, 32), dtype=tf.int64, name="user_ids"), "item_ids": tf.compat.v1.placeholder(shape=(None, 8), dtype=tf.int64, name="item_ids"), "label_0": tf.compat.v1.placeholder(shape=(None,), dtype=tf.float32, name="label_0"), "label_1": tf.compat.v1.placeholder(shape=(None,), dtype=tf.float32, name="label_1"), } return tf.estimator.export.ServingInputReceiver(features=inputs, receiver_tensors=inputs) target_pb_path = os.path.abspath("pb_model_path") # Call the export_saved_model API of Estimator to save the model in .pb format. export_path = est.export_saved_model(target_pb_path, _serving_input_fn).decode("utf-8") print(f"The export saved model path is {export_path}.")
- Call the terminate_config_initializer API to disable the data flow and release resources.
Parent topic: Estimator Training