multi-model-server icon indicating copy to clipboard operation
multi-model-server copied to clipboard

Using application/json in the signature is not reflected in the api-description

Open ThomasDelteil opened this issue 6 years ago • 5 comments

Here is my signature.json

{
 "inputs": [
   {
     "data_name": "data",
     "data_shape": [0, 3, 224, 224]
   }
 ],
 "input_type": "application/json",
 "outputs": [
   {
     "data_name": "relu6",
     "data_shape": [0, 512]
   }
 ],
 "output_type": "application/json"
}

Here is my api-description

...
      "/visualsearch/predict": {
        "post": {
          "consumes": [
            "multipart/form-data"
          ], 
          "operationId": "visualsearch_predict", 
          "parameters": [
            {
              "description": "data should tensor with shape: [3, 224, 224]", 
              "in": "formData", 
              "name": "data", 
              "required": "true", 
              "schema": {
                "type": "string"
              }
            }
          ], 
          "produces": [
            "application/json"
          ], 
          "responses": {
            "200": {
              "description": "OK", 
              "schema": {
                "properties": {
                  "prediction": {
                    "type": "string"
                  }
                }, 
                "type": "object"
              }
            }
          }
        }
      }
    }, 
    "schemes": [
      "http"
    ], 
    "swagger": "2.0"
  }
}

ThomasDelteil avatar May 10 '18 00:05 ThomasDelteil

I can't get a JSON request to go through:

[INFO 2018-05-10 00:23:25,486 PID:87660 /home/ubuntu/anaconda3/lib/python3.6/site-packages/mms/serving_frontend.py:predict_callback:423] Request input: data should be json tensor.
[INFO 2018-05-10 00:23:25,486 PID:87660 /home/ubuntu/anaconda3/lib/python3.6/site-packages/mms/request_handler/flask_handler.py:get_form_data:111] Getting form data from request.
[ERROR 2018-05-10 00:23:25,486 PID:87660 /home/ubuntu/anaconda3/lib/python3.6/site-packages/mms/serving_frontend.py:predict_callback:433] malformed node or string: None

Here is the request:

Request URL: http://localhost:5000/visualsearch/predict
Request Method: POST
Status Code: 400 BAD REQUEST
Remote Address: [::1]:5000
Referrer Policy: no-referrer-when-downgrade
HTTP/1.0 400 BAD REQUEST
Content-Type: text/html
Content-Length: 146
Access-Control-Allow-Origin: http://localhost:1234
Vary: Origin
Server: Werkzeug/0.14.1 Python/3.6.3
Date: Thu, 10 May 2018 00:23:25 GMT
POST /visualsearch/predict HTTP/1.1
Host: localhost:5000
Connection: keep-alive
Content-Length: 106297
Accept: application/json, text/plain, */*
Origin: http://localhost:1234
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://localhost:1234/
Accept-Encoding: gzip, deflate, br
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
{"image":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADHCAYAAABcDhxLAAAgAElEQVR4XmS9B5Sk53UdeCvnXJ1zztM9OeeEOEQgCVEQCZIgKdIitba8Ek3ZZyWtbS0lSxApWWLSyqQsEkQiCGAAzCBMzrnD9HTOobor51zlc18NaHu3cXAmdVf9//e/cN99971S3Dj7TrG+oRZDQyNwOl0wGI2IRCIIhUK4e/s2+nt6MDs9jVQyifIyFy5cuIDOzk4cOnQI773/PhwOB06fPo1isQirxYwd27cimYhDr9ejvKwKU+OT8K2to7qqGpVVlfL6d4cH4QsG0dDYgKGhQWTTGeQKgEqtRiwWg9/vx87duzA/P49sNotoPIFcvoDdu/finXfeQT5fwJbNW/BgbByZXAH5AqAz6OHz+WA06LFt21YEfH6MjAxh+9bNqKwqg9tVhuvXr8k98Np27NiBSxcvopDPQ6vVIhSKwGI0oLGhDo8cO4Z8Po+f/fSfUFFRgdnZWfj9PvT29qCuvhbz83Pwen1IxdJyFnqDHmfPn0dTUzNC4RDiiTgKUCKdTiORSECpUkGpVCGVSiEcDiNXyMNiMaO+rg73709hYEMXAv6QXJfVbEbE74fNapVnoFQqYTSZUFNTg+XlZZisVpjNJty5ewcd7R2orK7CxUuXkC8WkEmnodaoYbFYoOOvJhOURQU8nmU0NzWju7UdGq0K6/51JFIJHH3kGCw2Gxw2OyLhGB6MPoDPF8T+Q4dgddpRWVsNvd4AhVqFcCwKnU4HtUqFfCaPeCQMtVK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zTP6OcAshkShow more

ThomasDelteil avatar May 10 '18 00:05 ThomasDelteil

Ok so there is a lack of clarity here IMO in the signature.json file. When you specify input type: application/json, it seems to mean that you will actually need send a formData content-type but that the content itself is in JSON. It also simply checks that the json payload in the form data is a list.

I would suggest to rework the signature file and API description to be a lot more lax as to what gets sent to the API: Allowing multiple parameters, sending pure JSON payloads. The sanity checks on the data format should happen after _preprocess is called to let the user pass several parameters and do their own encoding/transforming etc.

ThomasDelteil avatar May 10 '18 17:05 ThomasDelteil

We will look into this.

vdantu avatar May 10 '18 17:05 vdantu

@ThomasDelteil the request payload pasted above is not what MMS expects for JSON inputs.

lupesko avatar May 14 '18 04:05 lupesko

@lupesko yes I have figured that out now. To rephrase my issue (and current understanding) is:

  • The signature.json file lets you define an input_type as application/json.
  • However MMS expects always input to be sent with header Content-Type:multipart/form-data. This doesn't appear documented except in the api-description endpoint.

What is the issue? I think using the application/json value for the input_type whilst the actual expected Content-Type is multipart/form-data is confusing. The value application/json is a standard value of the Content-Type header, and here it is used to say that format of the form-data value is json.

In my view, the ideal solution is to allow user to define the Content-Type of their request, so that the client can use the much more common POST requests with application/json rather than using the form-data format.

If you want to remain with form-data I would suggest changing the input_type:application/json to input_type:json to make it clear this isn't about the Content-Type of the request, but the encoding of the data passed in the form.

I would also suggest to document the fact that the request is expected to be using multipart/form-data in the github repo documentation as well.

ThomasDelteil avatar May 14 '18 18:05 ThomasDelteil