公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
使用 TensorFlow 和 Cloud AI Platform 進行預測
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
TensorFlow 是開放原始碼機器學習平台,支援深度學習等進階機器學習方法。本頁面說明 Earth Engine 中的 TensorFlow 專屬功能。雖然 TensorFlow 模型是在 Earth Engine 外部開發及訓練,但 Earth Engine API 提供方法,可用於以 TFRecord 格式匯出訓練和測試資料,以及以 TFRecord 格式匯入/匯出影像。如要進一步瞭解如何開發管道,以便使用 TensorFlow 搭配 Earth Engine 的資料,請參閱 TensorFlow 範例頁面。請參閱 TFRecord 頁面,進一步瞭解 Earth Engine 如何將資料寫入 TFRecord 檔案。
ee.Model
ee.Model
套件會處理與 TensorFlow 支援機器學習模型的互動。
您可以使用 ee.Model.fromAiPlatformPredictor()
建立新的 ee.Model
例項。這是一個 ee.Model
物件,可將 Earth Engine 資料封裝成張量,並將其轉送為預測要求,傳送至 Google AI Platform,然後自動將回應重新組合為 Earth Engine 資料類型。請注意,視模型及其輸入內容的大小和複雜度而定,您可能需要調整 AI Platform 模型的最低節點大小,以便處理大量預測。
Earth Engine 要求 AI Platform 模型使用 TensorFlow 的 SavedModel 格式。託管模型必須先與 TensorProto 交換格式相容,才能與 Earth Engine 互動,特別是將 TensorProto 序列化為 base64。為簡化這項作業,Earth Engine CLI 提供 model prepare
指令,可在必要作業中包裝現有的 SavedModel,以便轉換輸入/輸出格式。
如要使用 ee.Model.fromAiPlatformPredictor()
中的模型,您必須具備足夠的權限才能使用模型。具體來說,您 (或任何使用模型的使用者) 至少需要具備
ML Engine 模型使用者角色。您可以前往 Cloud 控制台的「模型」頁面,查看及設定模型權限。
區域
您應為模型使用地區端點,在建立模型、建立版本和 ee.Model.fromAiPlatformPredictor()
時指定地區。任何區域都適用 (請勿使用 global),但建議使用 us-central1
。請勿指定 REGIONS
參數。如果您是透過 Cloud 控制台建立模型,請務必勾選「regional」(區域) 核取方塊。
費用
圖片預測
使用 model.predictImage()
搭配託管模型,針對 ee.Image
進行預測。predictImage()
的傳回類型是 ee.Image
,可新增至地圖、用於其他運算、匯出等。Earth Engine 會自動分割輸入頻帶,並視需要調整輸出投影方式,以便變更比例和分割過多。(如要進一步瞭解平鋪作業的運作方式,請參閱 TFRecord 文件)。請注意,即使頻帶為標量 (最後一個維度為 1),Earth Engine 仍會一律將 3D 張量轉寄至模型。
幾乎所有卷積模型都會採用固定的輸入投影 (也就是模型訓練時使用的資料)。在這種情況下,請在對 ee.Model.fromAiPlatformPredictor()
的呼叫中將 fixInputProj
參數設為 true。在視覺化預測結果時,請小心縮小具有固定輸入投影的模型。原因與這裡所述相同。具體來說,放大至較大的空間範圍可能會導致要求過多資料,並可能導致 AI 平台速度變慢或拒絕要求。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThis guide is deprecated and users should refer to the TensorFlow with Vertex AI guide for updated information.\u003c/p\u003e\n"],["\u003cp\u003eEarth Engine facilitates the use of TensorFlow for machine learning by providing methods for data export/import in TFRecord format and integration with AI Platform for model hosting.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eee.Model\u003c/code\u003e package enables interaction with TensorFlow models, specifically allowing predictions on Earth Engine images using models hosted on AI Platform.\u003c/p\u003e\n"],["\u003cp\u003eWhen using AI Platform models, ensure compatibility with TensorFlow's SavedModel format and configure necessary permissions for model access.\u003c/p\u003e\n"],["\u003cp\u003eBe mindful of potential costs associated with using billable components of Google Cloud, such as AI Platform and Cloud Storage.\u003c/p\u003e\n"]]],["This content outlines using TensorFlow models with Earth Engine, focusing on `ee.Model` for AI Platform interaction. Key actions include creating `ee.Model` instances with `ee.Model.fromAiPlatformPredictor()`, packaging Earth Engine data into tensors for AI Platform prediction requests, and reassembling responses. Models must use TensorFlow's SavedModel format, prepared using the Earth Engine CLI. Image predictions utilize `model.predictImage()`, returning an `ee.Image`. The document warns about costs associated with AI Platform and Cloud Storage and recommend using regional endpoints.\n"],null,["# Predictions using TensorFlow and Cloud AI Platform\n\n| **Deprecated!** This guide uses datasets that may be removed from the\n| Earth Engine catalog and/or methods that may be removed in future versions of the Earth\n| Engine API. See [](/earth-engine/guides/earth-engine/guides/tensorflow-vertex)instead.\n\n[TensorFlow](https://www.tensorflow.org/) is an open source ML platform that\nsupports advanced ML methods such as deep learning. This page describes TensorFlow\nspecific features in Earth Engine. Although TensorFlow models are developed and trained\noutside Earth Engine, the Earth Engine API provides methods for exporting training and\ntesting data in TFRecord format and importing/exporting imagery in TFRecord format. See\n[the TensorFlow examples page](/earth-engine/guides/tf_examples) for more information about how to\ndevelop pipelines for using TensorFlow with data from Earth Engine. See\n[the TFRecord page](/earth-engine/guides/tfrecord) to learn more about how Earth Engine writes data to\nTFRecord files.\n\n`ee.Model`\n----------\n\n\nThe `ee.Model` package handles interaction with TensorFlow backed machine\nlearning models.\n\n### Interacting with models hosted on AI Platform\n\n\nA new `ee.Model` instance can be created with\n`ee.Model.fromAiPlatformPredictor()`. This is an `ee.Model` object\nthat packages Earth Engine data into tensors, forwards them as predict requests to\n[Google AI Platform](https://cloud.google.com/ai-platform/) then automatically\nreassembles the responses into Earth Engine data types. Note that depending on the size\nand complexity of your model and its inputs, you may wish to\n[adjust\nthe minimum node size](https://cloud.google.com/ml-engine/docs/prediction-overview#node-allocation) of your AI Platform model to accommodate a high volume of\npredictions.\n\nEarth Engine requires AI Platform models to use TensorFlow's\n[SavedModel](https://www.tensorflow.org/guide/saved_model#save_and_restore_models)\nformat. Before a hosted model can interact with Earth Engine, its inputs/outputs need to\nbe compatible with the TensorProto interchange format, specifically serialized\nTensorProtos in base64. To make this easier, the Earth Engine CLI has the\n[`model prepare`](/earth-engine/guides/command_line#model) command that wraps an existing\nSavedModel in the required operations to convert input/output formats.\n\n\nTo use a model with `ee.Model.fromAiPlatformPredictor()`, you must have sufficient\npermissions to use the model. Specifically, you (or anyone who uses the model) needs at\nleast the [ML Engine Model User role](https://cloud.google.com/ai-platform/prediction/docs/access-control#model_user_role). You can inspect and set model permissions from the\n[models page of the Cloud\nConsole](https://console.cloud.google.com/ai-platform/models).\n\n### Regions\n\n\nYou should use regional endpoints for your models, specifying the region at model creation,\nversion creation and in `ee.Model.fromAiPlatformPredictor()`. Any region will\nwork (don't use global), but `us-central1` is preferred. Don't specify the\n`REGIONS` parameter. If you are are creating a model from the\n[Cloud Console](https://console.cloud.google.com/ai-platform/models),\nensure the regional box is checked.\n\nCosts\n-----\n\n| **Warning!** These guides use billable components of Google Cloud including:\n|\n| - AI Platform Training ([pricing](https://cloud.google.com/ai-platform/training/pricing))\n| - AI Platform Prediction ([pricing](https://cloud.google.com/ai-platform/prediction/pricing))\n| - Cloud Storage ([pricing](https://cloud.google.com/storage/pricing))\n|\n| You can use the\n| [Pricing Calculator](https://cloud.google.com/products/calculator) to generate\n| a cost estimate based on your projected usage.\n\n### Image Predictions\n\n\nUse `model.predictImage()` to make predictions on an `ee.Image`\nusing a hosted model. The return type of `predictImage()` is an\n`ee.Image` which can be added to the map, used in other computations,\nexported, etc. Earth Engine will automatically tile the input bands and adjust\nthe output projection for scale changes and overtiling as needed. (See\n[the TFRecord doc](/earth-engine/guides/tfrecord#exporting-images) for more information on how tiling\nworks). Note that Earth Engine will always forward 3D tensors to your model even when\nbands are scalar (the last dimension will be 1).\n\n\nNearly all convolutional models will have a fixed input projection (that of the data\non which the model was trained). In this case, set the `fixInputProj` parameter\nto **true** in your call to `ee.Model.fromAiPlatformPredictor()`.\nWhen visualizing predictions, use caution when zooming out on a model that has a fixed\ninput projection. This is for the same reason as [described\nhere](/earth-engine/guides/projections#reprojecting). Specifically, zooming to a large spatial scope can result in requests for too\nmuch data and may manifest as slowdowns or rejections by AI Platform."]]