Open gtfaiwxm opened 3 years ago
Could you try com.intel.analytics.zoo.serving.http.JsonUtil.fromJson[Predictions]
?
@qiuxin2012 Where can I find this API of com.intel.analytics.zoo.serving.http.JsonUtil.fromJson?
Moreover, I want to know that how to use the com.intel.analytics.zoo.serving.http.JsonUtil.fromJson[Predictions]. I enter this command directly on the command ? Thanks.
https://github.com/intel-analytics/analytics-zoo/blob/master/zoo/src/main/scala/com/intel/analytics/zoo/serving/http/serializers.scala AZ use this JacksonJsonSerializer to serialize predition result. BTW, which language is your client using?
Thanks. I use python
The response is standard json format, you can use any json lib in python to parse it:
{
'predictions': [
'{value=data=[0.0,1.0,0.99930465,0.2667401,0.2137495,0.51740575,0.7415706,...,0.0,0.0,0.0,0.0],shape=[1,200,7];}'
]
}
and you will get a array of predictions, each item of the array is also a json object, you can also parse it,
data=[
0.0,
1.0,
0.99930465,
0.2667401,
0.2137495,
0.51740575,
0.7415706,
...,
0.0,
0.0,
0.0,
0.0
],
shape=[
1,
200,
7
];
@glorysdj Hi, I use the code to parse json file, the error is occured. `import json
data = { 'predictions': [ '{value=data=[0.0,1.0,0.99930465,0.2667401,0.2137495,0.51740575,0.7415706,0.0,1.0,0.99930465,0.2667401,0.2137495,0.51740575,0.7415706],shape=[1,2,7];}' ] }
data_temp = data['predictions'][0] print(data_temp) result = json.loads(data_temp)
Traceback (most recent call last):
File "d:/code/json_test.py", line 11, in
Hi @gtfaiwxm it seems like still has ' before and after the string, could you please try to remove ' in the data_temp ? data_temp = data_temp .replace("'","")
Hi @glorysdj The ' before and after the string is normal, because string needs ' before and after in python. data_temp = data_temp .replace("'","") This command has no effect.
please try this:
import json
str = " { 'predictions': [ '{value=data=[0.0,1.0,0.99930465,0.2667401,0.2137495,0.51740575,0.7415706,0.0,1.0,0.99930465,0.2667401,0.2137495,0.51740575,0.7415706],shape=[1,2,7];}' ]}"
str = str.replace("\'", "\"")
result = json.loads(str)
predictions = result['predictions']
for prediction in predictions:
prediction = prediction.replace("value=","").replace(";","")
prediction = prediction.replace('data=','"data":').replace('shape=','"shape":')
prediction_result = json.loads(prediction)
print(prediction_result)
@Litchilitchy we should add a python api to parse response to tensor results.
Hi. Does you add a python api to parse response to tensor results in cluster-serving?
not yet, we are working on notebook tutorials which will show a example of json processing, after that we will add a pyton api for this.
Ok, If you haved add the python api in cluster-serving,I hope you can tell me. Thanks
@gtfaiwxm we used to store just the string value e.g. [[1,2],[3,3]]
but it turns out to be too slow.
you can get the data array and shape array and just use np.array(data, shape=shape)
to construct the array.
Although this seems not user friendly but it increase the performance.
Any better idea please share with us, thanks.
The result of http api is now value=a_json_string
, you could parse a_json_string
by a json parser.
@gtfaiwxm is the issue fixed on your side? or any more questions? if no more questions, we will close the issue soon.
When I use the http API of cluster-serving, I obtain the json response: {'predictions': ['{value=data=[0.0,1.0,0.99930465,0.2667401,0.2137495,0.51740575,0.7415706,...,0.0,0.0,0.0,0.0],shape=[1,200,7];}']}. How do I parse the results of non-standard json?