kibae / onnxruntime-server

ONNX Runtime Server: The ONNX Runtime Server is a server that provides TCP and HTTP/HTTPS REST APIs for ONNX inference.
MIT License
124 stars 7 forks source link

From cv2.Mat to image #65

Open kilievich-dmitriy-andreevich opened 1 month ago

kilievich-dmitriy-andreevich commented 1 month ago

Hello dear developers!

I ran into a problem when converting cv2.Mat in the picture

As I understand from your example,

"x": [ [ 1 ], [ 2 ], [ 3 ] ],
"y": [ [ 2 ], [ 3 ], [ 4 ] ],
"z": [ [ 3 ], [ 4 ], [ 5 ] ]

what (x y z) these are (R G B) colors. I'm converting an image like in example, but I get an error:

Response Status: 400 Bad Requests
Response body: {"error": "input images are not an array","error_type":"bad_request_error"}

Do you have any Python code that would be an example of checking from Mat images to json? Thank you in advance

kilievich-dmitriy-andreevich commented 1 month ago

session content:

HTTP/1.1 200 OK
Content-Type: application/json 
Content-Length: 209

{
  "created_at": 1727025141,
  "execution_count": 0,
  "inputs": {
    "images": "float32[1,3,1024,1024]"
  },
  "last_executed_at": 0,
  "model": "mod_A",
  "option": {
    "cuda": false
  },
  "outputs": {
    "output0": "float32[1,7,21504]"
  },
  "version": "v1"
}
kibae commented 1 month ago

Hi, @kilievich-dmitriy-andreevich

When attempting to run the ONNX session, you should send the following JSON as the post data:

{
  "images": [
    // shape 1
    [
      // shape 3
      [
        // shape 1024
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        ... // 1024 arrays
      ],
      [
        // shape 1024
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        ... // 1024 arrays
      ],
      [
        // shape 1024
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        [
          //shape 1024
          0,0,0,0,0,0, ... // 1024 float numbers
        ],
        ... // 1024 arrays
      ]
    ]
  ]
}

There is a (1024, 1024) shape in the data, which I assume refers to the width or height of the image.