tf.saved_model.save(m,model_dir,signatures={'serving_default':serving_fn,'xai_preprocess':preprocess_fn,# Required for AI Explanations'xai_model':model_fn# Required for AI Explanations})
# Build, compile, train, and evaluate your Keras modelmodel=tf.keras.Sequential(...)model.compile(...)model.fit(...)model.predict(...)## Convert your Keras model to an Estimatorkeras_estimator=tf.keras.estimator.model_to_estimator(keras_model=model,model_dir='export')## Define a serving input function appropriate for your modeldefserving_input_receiver_fn():...returntf.estimator.export.ServingInputReceiver(...)## Export the SavedModel to Cloud Storage using your serving input functionexport_path=keras_estimator.export_saved_model('gs://'+'YOUR_BUCKET_NAME',serving_input_receiver_fn).decode('utf-8')print("Model exported to: ",export_path)
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-07。"],[[["\u003cp\u003eThis feature is currently in Beta and is subject to the "Pre-GA Offerings Terms," offering limited support and available "as is".\u003c/p\u003e\n"],["\u003cp\u003eTo save a TensorFlow 2.x model for AI Explanations, use \u003ccode\u003etf.saved_model.save\u003c/code\u003e, and specify the model's signature with the \u003ccode\u003exai_model\u003c/code\u003e key if there are multiple input signatures, or \u003ccode\u003exai_preprocess\u003c/code\u003e and \u003ccode\u003exai_model\u003c/code\u003e keys if preprocessing is used.\u003c/p\u003e\n"],["\u003cp\u003eFor TensorFlow 1.15, avoid \u003ccode\u003etf.saved_model.save\u003c/code\u003e; instead, use \u003ccode\u003etf.estimator.export_savedmodel\u003c/code\u003e with \u003ccode\u003etf.estimator.export.ServingInputReceiver\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIf using Keras with TensorFlow 1.15, convert the Keras model to a TensorFlow Estimator using \u003ccode\u003etf.keras.estimator.model_to_estimator\u003c/code\u003e, define a serving input function, and export it as a SavedModel using \u003ccode\u003etf.estimator.export_saved_model\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFurther explore the provided examples of \u003ca href=\"https://colab.research.google.com/github/GoogleCloudPlatform/ai-platform-samples/blob/master/notebooks/samples/explanations/tf2/ai-explanations-tabular.ipynb\"\u003eTabular example notebook for TensorFlow 2\u003c/a\u003e, \u003ca href=\"https://colab.research.google.com/github/GoogleCloudPlatform/ai-platform-samples/blob/master/notebooks/samples/explanations/tf2/ai-explanations-image.ipynb\"\u003eImage example notebook for TensorFlow 2\u003c/a\u003e, \u003ca href=\"https://colab.research.google.com/github/GoogleCloudPlatform/ai-platform-samples/blob/master/notebooks/samples/explanations/ai-explanations-tabular.ipynb\"\u003eTabular example notebook for TensorFlow 1.15\u003c/a\u003e and \u003ca href=\"https://colab.research.google.com/github/GoogleCloudPlatform/ai-platform-samples/blob/master/notebooks/samples/explanations/ai-explanations-image.ipynb\"\u003eImage example notebook for TensorFlow 1.15\u003c/a\u003e.\u003c/p\u003e\n"]]],[],null,[]]