在 TPU 上训练模型后的单幅图像预测值

Predict value of single image after training model on TPU

我仍然想知道如何在训练网络后预测图像的值,但似乎还不支持。任何解决方法的想法(取自 mnist_tpu.py)?

  if mode == tf.estimator.ModeKeys.PREDICT:
    raise RuntimeError("mode {} is not supported yet".format(mode))

除了 Whosebug - 我还能在其他任何地方获得使用 TPU 实现我的模型的支持?

根据documentation,您可以选择在线或批量模式进行预测,但不能select目标设备。如前所述,"the prediction service allocates resources to run your job."

文档说预测是由节点执行的。我以为我在某处读到预测节点在 Google Compute Engine 中始终是 CPU,但我找不到明确的参考。

这是一个 Python 程序,它将图像发送到 TPU 训练模型(本例中为 ResNet)并返回分类:

with tf.gfile.FastGFile('/some/path.jpg', 'r') as ifp:
    credentials = GoogleCredentials.get_application_default()
    api = discovery.build('ml', 'v1', credentials=credentials,
               discoveryServiceUrl='https://storage.googleapis.com/cloud-ml/discovery/ml_v1_discovery.json')

    request_data = {'instances':
      [
         {"image_bytes": {"b64": base64.b64encode(ifp.read())}}
      ]
    }
    parent = 'projects/%s/models/%s/versions/%s' % (PROJECT, MODEL, VERSION)
    response = api.projects().predict(body=request_data, name=parent).execute()
    print("response={0}".format(response))

完整代码在这里:https://github.com/GoogleCloudPlatform/training-data-analyst/blob/master/quests/tpu/flowers_resnet.ipynb

本文记录了为 Cloud TPU 编写模型的过程:https://medium.com/tensorflow/how-to-write-a-custom-estimator-model-for-the-cloud-tpu-7d8bd9068c26

现在支持了。已对 https://github.com/tensorflow/models/blob/master/official/mnist/mnist_tpu.py 进行更改以使其正常工作。

除了 Whosebug,您还可以在 github https://github.com/tensorflow/tpu/issues.

上添加您的问题