_Originally posted by @gautamvasudevan in https://github.com/tensorflow/serving/issues/1133#issuecomment-436036928_
Hello, I did as the blog step by step, still doesn't work.
The response from serving is printed like this :
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:8501/v1/models/resnet:predict
And the post content is :
b'{ "error": "Failed to process element: 0 of \\\'instances\\\' list. Error: Invalid argument: Unable to base64 decode" }'
Then I did some search and changed 'resnet_client.py' line 52 from "base64.b64encode" to "base64.urlsafe_b64encode", the same error replied.
Thanks a lot for your noticing this.
I just copy-pasted the blog instructions, and it worked for me on both macOS and Ubuntu 16.04. Please post detailed instructions of how to reproduce your bug.
I just copy-pasted the blog instructions, and it worked for me on both macOS and Ubuntu 16.04. Please post detailed instructions of how to reproduce your bug.
@gautamvasudevan Thank you for reply, here is the step:
First, On macOS, downloaded the tar https://storage.googleapis.com/download.tensorflow.org/models/official/20181001_resnet/savedmodels/resnet_v2_fp32_savedmodel_NHWC_jpg.tar.gz, then unzipped it and placed at serving/models like this:
โโโ AUTHORS
โโโ CONTRIBUTING.md
โโโ LICENSE
โโโ README.md
โโโ RELEASE.md
...
โโโ models
โย ย โโโ mnist
โย ย โย ย โโโ 1
โย ย โย ย โโโ saved_model.pb
โย ย โย ย โโโ variables
โย ย โย ย โโโ variables.data-00000-of-00001
โย ย โย ย โโโ variables.index
โย ย โโโ resnet
โย ย โโโ 1538687457
โย ย โโโ saved_model.pb
โย ย โโโ variables
โย ย โโโ variables.data-00000-of-00001
โย ย โโโ variables.index
For the record the mnist runs OK.
Second, run
docker run -p 8501:8501 --name rfserving_resnet \
--mount type=bind,source=/Users/lee/workspace/serving/models/resnet,target=/models/resnet \
-e MODEL_NAME=resnet -t tensorflow/serving &
, and it looked well :
2018-11-05 20:15:34.666295: I tensorflow_serving/model_servers/server.cc:285] Running gRPC ModelServer at 0.0.0.0:8500 ...
[warn] getaddrinfo: address family for nodename not supported
[evhttp_server.cc : 235] RAW: Entering the event loop ...
2018-11-05 20:15:34.667968: I tensorflow_serving/model_servers/server.cc:301] Exporting HTTP/REST API at:localhost:8501 ...
Then, run the file resnet_client.py as the blog, there got the error :
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1664, in <module>
main()
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/lee/workspace/serving/tensorflow_serving/example/resnet_client.py", line 73, in <module>
main()
File "/Users/lee/workspace/serving/tensorflow_serving/example/resnet_client.py", line 57, in main
response.raise_for_status()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/models.py", line 939, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:8501/v1/models/resnet:predict
Follow the breakpoint, the error content from serving response:
b'{ "error": "Failed to process element: 0 of \\\'instances\\\' list. Error: Invalid argument: Unable to base64 decode" }'
The same error if changed base64 to urlsafe_base64.
Again, thanks a lot for your noticing this.
I would start completely from scratch and follow each line in the blog post exactly. Unfortunately it's very hard to tell what's wrong with your process since I don't know how you arrived at that configuration (it's definitely not what's specified in the blog post).
@gautamvasudevan Thank you for help. Now the resnet_client.py works. My env is python 3.6, after switch to python 2.7, it works. So I think this error maybe some encode/decode thing.
Here is a lame try but can works under python 3 env :
predict_request = '{"instances" : [{"b64": "%s"}]}' % base64.b64encode(dl_request.content).decode()
Thanks again.
@alatriste-lee - Thank you ! II had the same error, with python 3.6. Switching to 2.7 solved it. The change was needed only for running the client script.
Most helpful comment
@gautamvasudevan Thank you for help. Now the resnet_client.py works. My env is python 3.6, after switch to python 2.7, it works. So I think this error maybe some encode/decode thing.
Here is a lame try but can works under python 3 env :
predict_request = '{"instances" : [{"b64": "%s"}]}' % base64.b64encode(dl_request.content).decode()Thanks again.