【问题标题】:Predict value of single image after training model on TPU在 TPU 上训练模型后预测单张图像的值
【发布时间】:2019-02-22 01:25:15
【问题描述】:

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

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

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

【问题讨论】:

    标签: tensorflow google-cloud-platform google-compute-engine google-cloud-ml google-cloud-tpu


    【解决方案1】:

    现在支持。已经完成了更改为https://github.com/tensorflow/models/blob/master/official/mnist/mnist_tpu.py以使其工作。

    除stackoverflow外,您可以在github https://github.com/tensorflow/tpu/issues中添加您的问题。

    【讨论】:

    • 酷!非常感谢!
    【解决方案2】:

    这是一个 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

    【讨论】:

      【解决方案3】:

      根据documentation,可以选择在线或批量模式进行预测,但不能选择目标设备。如前所述,“预测服务会分配资源来运行您的作业。”

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-25
        • 2018-04-15
        • 1970-01-01
        • 2018-05-03
        • 1970-01-01
        • 2022-10-19
        • 2020-03-31
        • 2021-09-25
        相关资源
        最近更新 更多