Google Earth Engine(GEE)——TensorFlow支持深度学习等高级机器学习方法(非免费项目)

2024-02-02 08:19:17 浏览数 (3)

TensorFlow 和地球引擎

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 支持的机器学习模型的交互。

与 AI Platform 上托管的模型交互

ee.Model.fromAiPlatformPredictor(projectName, projectId, modelName, version, region, inputProperties, inputTypeOverride, inputShapes, proj, fixInputProj, inputTileSize, inputOverlapSize, outputTileSize, outputBands, outputProperties, outputMultiplier)

Returns an ee.Model from a description of an AI Platform prediction model. (See https://cloud.google.com/ml-engine/).

Arguments:

projectName (Object, default: null):

The Google Cloud project that owns the model. Deprecated: use "projectId" instead.

projectId (String, default: null):

The ID of the Google Cloud project that owns the model.

modelName (String, default: null):

The name of the model.

version (String, default: null):

The model version. Defaults to the AI Platform default model version.

region (String, default: null):

The model deployment region. Defaults to "us-central1".

inputProperties (List, default: null):

Properties passed with each prediction instance. Image predictions are tiled, so these properties will be replicated into each image tile instance. Defaults to no properties.

inputTypeOverride (Dictionary, default: null):

Types to which model inputs will be coerced if specified. Both Image bands and Image/Feature properties are valid.

inputShapes (Dictionary, default: null):

The fixed shape of input array bands. For each array band not specified, the fixed array shape will be automatically deduced from a non-masked pixel.

proj (Projection, default: null):

The input projection at which to sample all bands. Defaults to the default projection of an image's first band.

fixInputProj (Boolean, default: null):

If true, pixels will be sampled in a fixed projection specified by 'proj'. The output projection is used otherwise. Defaults to false.

inputTileSize (List, default: null):

Rectangular dimensions of pixel tiles passed in to prediction instances. Required for image predictions.

inputOverlapSize (List, default: null):

Amount of adjacent-tile overlap in X/Y along each edge of pixel tiles passed in to prediction instances. Defaults to [0, 0].

outputTileSize (List, default: null):

Rectangular dimensions of pixel tiles returned from AI Platform. Defaults to the value in 'inputTileSize'.

outputBands (Dictionary, default: null):

A map from output band names to a dictionary of output band info. Valid band info fields are 'type' and 'dimensions'. 'type' should be a ee.PixelType describing the output band, and 'dimensions' is an optional integer with the number of dimensions in that band e.g.: "outputBands: {'p': {'type': ee.PixelType.int8(), 'dimensions': 1}}". Required for image predictions.

outputProperties (Dictionary, default: null):

A map from output property names to a dictionary of output property info. Valid property info fields are 'type' and 'dimensions'. 'type' should be a ee.PixelType describing the output property, and 'dimensions' is an optional integer with the number of dimensions for that property if it is an array e.g.: "outputBands: {'p': {'type': ee.PixelType.int8(), 'dimensions': 1}}". Required for predictions from FeatureCollections.

outputMultiplier (Float, default: null):

An approximation to the increase in data volume for the model outputs over the model inputs. If specified this must be >= 1. This is only needed if the model produces more data than it consumes, e.g. a model that takes 5 bands and produces 10 outputs per pixel.

Returns: Model

ee.Model可以创建 一个新实例 ee.Model.fromAiPlatformPredictor()。这是一个ee.Model将 Earth Engine 数据打包成张量的对象,将它们作为预测请求转发到 Google AI Platform,然后自动将响应重新组合为 Earth Engine 数据类型。请注意,根据模型及其输入的大小和复杂性,您可能希望 调整AI Platform 模型的最小节点大小以适应大量预测。

Earth Engine 要求 AI Platform 模型使用 TensorFlow 的 SavedModel 格式。在托管模型可以与地球引擎交互之前,其输入/输出需要与 TensorProto 交换格式兼容,特别是在 base64 中序列化的 TensorProtos。为model prepare简化此操作,Earth Engine CLI 具有 将现有 SavedModel 包装在所需操作中以转换输入/输出格式的命令。

要将模型与 一起使用ee.Model.fromAiPlatformPredictor(),您必须具有足够的权限才能使用该模型。具体来说,您(或使用该模型的任何人)至少需要 ML Engine Model User 角色。您可以从Cloud Console的模型页面检查和设置模型权限 。

地区

您应该为模型使用区域端点,在模型创建、版本创建和ee.Model.fromAiPlatformPredictor(). 任何区域都可以工作(不要使用全局),但us-central1首选。不要指定 REGIONS参数。如果您是从Cloud Console创建模型 ,请确保选中区域框。

图像预测

predictImage(image)

Make predictions from pixel tiles of an image. The predictions are merged as bands with the input image.

The model will receive 0s in place of masked pixels. The masks of predicted output bands are the minimum of the masks of the inputs.

Arguments:

this:model (Model)

image (Image):

The input image.

Returns: Image

用于model.predictImage()ee.Image 使用托管模型进行预测。的返回类型predictImage()是 an ee.Image,可以添加到地图、用于其他计算、导出等。Earth Engine 将自动平铺输入波段并根据需要调整输出投影以进行比例更改和覆盖。(有关平铺工作原理的更多信息,请参阅 TFRecord 文档)。请注意,即使带是标量(最后一个维度将为 1),地球引擎也会始终将 3D 张量转发到您的模型。

几乎所有的卷积模型都有一个固定的输入投影(模型训练的数据的投影)。在这种情况下,请在调用 时将fixInputProj参数设置为trueee.Model.fromAiPlatformPredictor()。在可视化预测时,在缩小具有固定输入投影的模型时要小心。这与此处描述的原因相同。具体而言,缩放到较大的空间范围可能会导致请求过多数据,并可能表现为 AI Platform 速度减慢或拒绝。

1 人点赞