serving icon indicating copy to clipboard operation
serving copied to clipboard

Bad request when serving resnet API

Open louiselmps opened this issue 6 years ago • 1 comments

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux 18.04
  • TensorFlow Serving installed from (source or binary): Docker and apt package
  • TensorFlow Serving version: 1.13.0-rc1+dev.sha.f16e777

My custom object detection model is being served in a docker container. I am trying to make a request like sending an image to the ModelServer using the resnet_client.py file. But upon running the file i have encountered this error:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://172.17.0.2:8501/v1/models/macaroni_model:predict

It doesn't make sense that i got this error since i can perfectly curl the model version status of the model using curl http://172.17.0.2:8501/v1/models/macaroni_model and it gives no error. So how come in my client file it would give an error??

For reference this is how my resnet_client.py file looks like:

from __future__ import print_function
from urllib3.exceptions import InsecureRequestWarning

import base64
import requests
import os


proxyDict = {
 'http': 'http://lumapas.ml:3w890yH3R1G2@proxy:3128',
 'https': 'http://lumapas.ml:3w890yH3R1G2@proxy:3128',
}

requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# The server URL specifies the endpoint of your server running the ResNet
# model with the name "resnet" and using the predict interface.s
SERVER_URL = 'http://172.17.0.2:8501/v1/models/macaroni_model:predict'

# The image URL is the location of the image we should send to the server
IMAGE_URL = "http://pinchofyum.com/wp-content/uploads/Instant-Pot-Mac-and-Cheese-Square.jpg"

def main():
  # Download the image
  dl_request = requests.get(IMAGE_URL, proxies=proxyDict)
  dl_request.raise_for_status()

  # Compose a JSON Predict request (send JPEG image in base64).
  jpeg_bytes = base64.b64encode(dl_request.content).decode('utf-8')
  predict_request = '{"instances" : [{"b64": "%s"}]}' % jpeg_bytes

  # Send few requests to warm-up the model.
  for _ in range(3):
    response = requests.post(SERVER_URL, data=predict_request)
    response.raise_for_status()

  # Send few actual requests and report average latency.
  total_time = 0
  num_requests = 10
  for _ in range(num_requests):
    response = requests.post(SERVER_URL, data=predict_request)
    response.raise_for_status()
    total_time += response.elapsed.total_seconds()
    prediction = response.json()['predictions'][0]

  print('Prediction class: {}, avg latency: {} ms'.format(
      prediction['classes'], (total_time*1000)/num_requests))


if __name__ == '__main__':
  main()

This is what my SavedModel looks like:

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['detection_signature']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['inputs'] tensor_info:
        dtype: DT_UINT8
        shape: (-1, -1, -1, 3)
        name: image_tensor:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['detection_boxes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100, 4)
        name: detection_boxes:0
    outputs['detection_classes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100)
        name: detection_classes:0
    outputs['detection_scores'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100)
        name: detection_scores:0
    outputs['num_detections'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1)
        name: num_detections:0
  Method name is: tensorflow/serving/predict

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['inputs'] tensor_info:
        dtype: DT_UINT8
        shape: (-1, -1, -1, 3)
        name: image_tensor:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['detection_boxes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100, 4)
        name: detection_boxes:0
    outputs['detection_classes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100)
        name: detection_classes:0
    outputs['detection_scores'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100)
        name: detection_scores:0
    outputs['num_detections'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1)
        name: num_detections:0
  Method name is: tensorflow/serving/predict

louiselmps avatar Jun 02 '20 05:06 louiselmps

@netfs maybe you could help?

louiselmps avatar Jun 02 '20 05:06 louiselmps