如何在Seldon Core python客户端中正确配置以接收预测结果?

时间:2019-05-20 06:11:57

标签: kubernetes minikube kubeflow

我正在使用Minikube上的Seldon Core进行检出,并已成功在集群上部署了模型。 我使用以下代码进行了测试:

seldon-core-api-tester ../seldon-core/examples/models/keras_mnist/contract.json     `minikube ip` `kubectl get svc -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].spec.ports[0].nodePort}'`     --oauth-key oauth-key --oauth-secret oauth-secret -p

并获得了正确的预测结果,如下所示。

RECEIVED RESPONSE:
meta {
  puid: "gn83vb2ag419k547eqkhfduos2"
  requestPath {
    key: "mnist"
    value: "mnist:0.1"
  }
}
data {
  names: "t:0"
  names: "t:1"
  names: "t:2"
  names: "t:3"
  names: "t:4"
  names: "t:5"
  names: "t:6"
  names: "t:7"
  names: "t:8"
  names: "t:9"
  ndarray {
    values {
      list_value {
        values {
          number_value: 0.00026227490161545575
        }
        values {
          number_value: 0.0007252057548612356
        }
        values {
          number_value: 0.028986405581235886
        }
        values {
          number_value: 0.8030332922935486
        }
        values {
          number_value: 7.914198795333505e-05
        }
        values {
          number_value: 0.14541368186473846
        }
        values {
          number_value: 0.002676495350897312
        }
        values {
          number_value: 0.015001941472291946
        }
        values {
          number_value: 0.0034872409887611866
        }
        values {
          number_value: 0.00033424459979869425
        }
      }
    }
  }
}

但是,当我尝试使用python客户端时,

from seldon_core.seldon_client import SeldonClient
sc = SeldonClient(deployment_name="mnist",namespace="seldon", seldon_rest_endpoint= '127.0.0.1:30790')
r = sc.predict(transport="rest")

我收到此错误。

HTTPConnection object at 0xb2bb5a780>: Failed to establish a new connection: [Errno 61] Connection refused'))

有人可以帮助我找出问题所在吗?

$kubectl get svc
mnist-deployment-mnist   ClusterIP      10.99.10.81      <none>        8000/TCP,5001/TCP               2d22h
kubernetes                           ClusterIP      10.96.0.1        <none>        443/TCP                         4d22h
seldon-core-redis-master             ClusterIP      10.107.217.176   <none>        6379/TCP                        2d22h
seldon-core-seldon-apiserver         NodePort       10.106.34.6      <none>        8080:30790/TCP,5000:31866/TCP   2d22h
seldon-mnist-0-1-4249605       ClusterIP      10.101.205.227   <none>        9000/TCP                        2d22h

1 个答案:

答案 0 :(得分:0)

运行seldon-core-api-tester脚本时,将提供minikube ip作为参数(以及大使端口)。初始化客户端而不是127.0.0.1时,端点需要此地址。因此,首先在您的shell中运行

minikube ip

记下ip,然后找到大使端口

kubectl get svc ambassador -o jsonpath='{.spec.ports[0].nodePort}'

然后您的客户和通话会像这样

from seldon_core.seldon_client import SeldonClient
import numpy as np

# this is the ip from `minikube ip` and port from `kubectl get svc ambassador -o jsonpath='{.spec.ports[0].nodePort}'`
minikube_ambassador_endpoint = "192.168.99.108:32667"

deployment_name = "mnist"
namespace = "default"

sc = SeldonClient(
    gateway="ambassador",
    gateway_endpoint=minikube_ambassador_endpoint,
    transport="rest",
    deployment_name=deployment_name,
    namespace=namespace
)

response = sc.predict(
    data=np.ones((5,)), 
    deployment_name=deployment_name, 
    payload_type="ndarray"
)
print(response)