无论如何 Google App Engine 应用程序可以通信或控制机器学习模型或任务吗?

Is there anyway Google App Engine apps can communicate or control Machine Learning models or tasks?

我想将 Google 的机器学习 与编写在 python 上的 App Engine 应用程序一起使用.

由于调查性质(使用 Kohonen 的 SOM 进行数据聚类),此应用程序应在每次使用前重新训练 TensorFlow 模型。

我有以下问题:

基于 App Engine 的应用可以命令 机器学习 使用一些输入数据训练一些模型吗? 基于 App Engine 的应用程序能否将一些输入向量发送到 ML thing 并获得结果(该向量属于哪个集群)? 如果一切皆有可能,该怎么做?

如果这一切都不可能,我可以使用任何其他架构来制作基于 App Engine 的应用程序使用 TensorFlow

我来说说这件事:

是的,您可以使用 App Engine 与 Google Cloud Machine Learning(以下简称 CloudML)通信。

要从 Python 与 CloudML 通信,您可以使用 Google API client library, which you can use with any Google Service. This client library can also be used on App Engine, it even has specific documentation for this here

我建议先在本地试用 API 客户端,然后再在 App Engine 上进行测试。对于此答案的下一部分,我将不区分在本地还是在 App Engine 上使用此客户端库。


您提到了两种不同类型的操作,您希望使用 CloudML:

  1. 用新数据更新模型
  2. 从 trained/deployed 模型中获取预测结果

1。使用新数据更新模型

根据新数据更新模型实际上对应两个步骤。首先在新数据(有或没有 CloudML)上训练模型,然后在 CloudML.

上部署这个新训练的模型

您可以使用 App Engine 的 API 客户端库执行这两个步骤,但为了降低复杂性,我认为您应该从遵循 prediction quickstart 开始。这将使您拥有一个新训练和部署的模型,并让您了解所涉及的不同步骤。

一旦熟悉了所涉及的概念和步骤,您就会发现可以将新数据存储在 GCS, and replace the different gcloud commands in the quickstart by their respective API calls that you can make with the API client library (documentation) 上。

2。从部署的模型中获取预测

如果您有已部署的模型(如果没有,请遵循 link from the previous step), you can easily communicate with CloudML to either get 1)batch predictions or 2)online predictions(后者处于 alpha 阶段)。 由于您使用的是 App Engine,我假设您有兴趣使用在线预测(立即获得结果)。 执行此操作所需的最少代码:

from oauth2client.client import GoogleCredentials
from googleapiclient import discovery

projectID = 'projects/<your_project_id>'
modelName = projectID+'/models/<your_model_name>'

credentials = GoogleCredentials.get_application_default()


ml = discovery.build('ml', 'v1beta1', credentials=credentials)
# Create a dictionary with the fields from the request body.
requestDict = {"instances":[
                    {"image": [0.0,..., 0.0, 0.0], "key": 0}
        ]}
# Create a request to call projects.models.create.
request = ml.projects().predict(
      name=modelName,
      body=requestDict)
response = request.execute()

使用 {"image": <image_array>, "key": <key_id>} 您在上一步中通过 link 为部署模型定义的输入格式。这将 return in response 包含模型的预期输出。