Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.RuntimeException: Unexpected code Response{protocol=http/1.1, code=400, message=Bad Request, url=http://localhost:8501/v1/models/myfruit:predict} #2215

Closed
x13872140520 opened this issue Apr 8, 2024 · 6 comments
Assignees
Labels
stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response type:bug

Comments

@x13872140520
Copy link

System information
operating system:
win11 64bit
tensorflow/serving version:
2.14.1
TFserving Deployment mode:
RESTful API
python requirements.txt:
tensorflow-cpu == 2.3.0 pyqt5 pillow opencv-python matplotlib

Describe the problem

Hello everyone, my demand is to build an interface with java, the front-end transmits an arbitrary image, java uses tensorflow for java or tensorflow serving to use the model to make predictions, java gets the prediction results and returns to the front-end.
Now I am ready to experiment with python to train the model, save the model as saved_model, and then set up tensorflow serving. Now the local docker container has been successfully started.

Image

The python code for model training is copied online, and the specific code is as follows:

PKU{ W4NKMQERFEW23GQ}X

The model training is also trained, and it is predictable in the python version using the h5 format. The model information is as follows:

Weixin Screenshot_20240408144143

java as the client request code:

QQ截图20240408144632

java is having trouble making requests to tensorflow serving and is not sure what to do. The error is as follows:
java.lang.RuntimeException: Unexpected code Response{protocol=http/1.1, code=400, message=Bad Request, url=http://localhost:8501/v1/models/myfruit:predict}

Look at https://tensorflow.google.cn/tfx/serving/api_rest#classify_and_regress_api here document as is can use base64 as parameters.
I tried the following formats, all failed, all reported similar to 400 errors
Weixin Screenshot_20240408144510

I am a java novice, tensorflow is also a novice, a lot of operations, basic terminology is not clear, do not know what knowledge is missing. Thank you for your generous advice. Do the parameters in sensory model training have a strong relationship with tfserving entry here? How do I organize parameters?

@singhniraj08 singhniraj08 self-assigned this Apr 10, 2024
@singhniraj08
Copy link

@x13872140520, The error indicates that the Java client code for sending REST request to TF Serving API is sending a bad request. Please make sure you are making request in correct format. Here is a python example for making REST request to your model in TF Serving. Thank you!

Copy link

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Apr 30, 2024
@x13872140520
Copy link
Author

x13872140520 commented May 7, 2024

@singhniraj08 Thanks for the answer, this problem is solved, the problem is that the code training the model needs to add base64 related processing, as follow:
Image

and then it can return the result of probability distribution as follow:
TensorFlow Serving response: {
"predictions": [[0.0142633133, 0.000105166473, 0.0256272946, 0.00341447047, 0.157596678, 0.00203850493, 0.561303079, 0.000357849116, 0.00741964, 0.227874041]
]
}。 but the new problem is that no matter what picture is predicted, this probability distribution is always the 7th largest.
I use the folder name as a label, to achieve the classification of pictures, everything in the python code environment is running well, can be correctly trained and predicted.

@google-ml-butler google-ml-butler bot removed stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response labels May 7, 2024
@singhniraj08
Copy link

@x13872140520, The probability distribution issue would be caused by some issue in model or when interpreting predictions from client side. Please make sure the model predictions are working correctly. And since there are no issues pending from Tensorflow Serving side, requesting you to close this issue. Thank you!

Copy link

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label May 16, 2024
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response type:bug
Projects
None yet
Development

No branches or pull requests

2 participants