Skip to content

Commit

Permalink
Merge pull request #3095 from nadinet/sledon_client_add_raw_data
Browse files Browse the repository at this point in the history
Add raw_data parameter to SeldonClient predict
  • Loading branch information
seldondev authored Mar 26, 2021
2 parents 0f30676 + a31a2d5 commit be97543
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 62 deletions.
88 changes: 74 additions & 14 deletions examples/models/sklearn_iris/sklearn_iris.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -55,14 +55,14 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Context \"kind-kind\" modified.\r\n"
"Context \"docker-desktop\" modified.\r\n"
]
}
],
Expand All @@ -79,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -117,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -134,7 +134,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -153,7 +153,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -177,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -186,16 +186,16 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['{\"data\":{\"names\":[\"t:0\",\"t:1\",\"t:2\"],\"ndarray\":[[0.9548873249364059,0.04505474761562512,5.7927447968953825e-05]]},\"meta\":{}}']"
"['{\"data\":{\"names\":[\"t:0\",\"t:1\",\"t:2\"],\"ndarray\":[[0.9548873249364059,0.04505474761562512,5.7927447968953825e-05]]},\"meta\":{\"requestPath\":{\"sklearn-iris-classifier\":\"seldonio/sklearn-iris:0.2\"}}}']"
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -206,14 +206,14 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['{\"data\":{\"names\":[\"t:0\",\"t:1\",\"t:2\"],\"ndarray\":[[0.9548873249364059,0.04505474761562512,5.7927447968953825e-05]]},\"meta\":{}}']\n"
"['{\"data\":{\"names\":[\"t:0\",\"t:1\",\"t:2\"],\"ndarray\":[[0.9548873249364059,0.04505474761562512,5.7927447968953825e-05]]},\"meta\":{\"requestPath\":{\"sklearn-iris-classifier\":\"seldonio/sklearn-iris:0.2\"}}}']\n"
]
}
],
Expand All @@ -224,10 +224,70 @@
"assert(j[\"data\"][\"ndarray\"][0][0]>0.0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"REST request with raw_data"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'data': {'names': ['t:0', 't:1', 't:2'], 'ndarray': [[0.9548873249364059, 0.04505474761562512, 5.7927447968953825e-05]]}, 'meta': {'requestPath': {'sklearn-iris-classifier': 'seldonio/sklearn-iris:0.2'}}}\n"
]
}
],
"source": [
"from seldon_core.seldon_client import SeldonClient\n",
"sc = SeldonClient(deployment_name=\"seldon-deployment-example\",namespace=\"seldon\")\n",
"res = sc.predict(gateway=\"istio\",gateway_endpoint=\"localhost:8003\", transport=\"rest\",raw_data = {\"data\":{\"ndarray\":[[5.964,4.006,2.081,1.031]]}})\n",
"print(res.response)\n",
"assert(res.success==True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"gRCP request with proto raw_data"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success:True message:\n",
"Request:\n",
"{'data': {'ndarray': [[5.964, 4.006, 2.081, 1.031]]}}\n",
"Response:\n",
"{'meta': {'requestPath': {'sklearn-iris-classifier': 'seldonio/sklearn-iris:0.2'}}, 'data': {'names': ['t:0', 't:1', 't:2'], 'ndarray': [[0.9548873249364059, 0.04505474761562512, 5.7927447968953825e-05]]}}\n"
]
}
],
"source": [
"from seldon_core.utils import json_to_seldon_message\n",
"proto_raw_data = json_to_seldon_message({\"data\":{\"ndarray\":[[5.964,4.006,2.081,1.031]]}})\n",
"res = sc.predict(gateway=\"istio\",gateway_endpoint=\"localhost:8003\", transport=\"grpc\",raw_data = proto_raw_data)\n",
"print(res)\n",
"assert(res.success==True)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -265,7 +325,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.4"
},
"varInspector": {
"cols": {
Expand Down
Loading

0 comments on commit be97543

Please sign in to comment.