BYOM Troubleshooting

Tips on troubleshooting your V7 external model integration

Here are some tips and tricks for troubleshooting your external model integration.

📘

Architecture

You will often connect your model with an intermediary step to do any necessary conversions e.g. a Flask app on a small EC2 server

Troubleshooting your Integration

  • Firstly, ensure your model is registered within the V7 platform correctly with the appropriate auth and endpoint
  • Make sure that the classes from your model are mapped to V7 classes. It is best practice to keep the class names spelt the same throughout and it is critical that the class names in the inference response are the same as those specified in the classes endpoint.
  • Check that your model activated in V7 and available for inference on your server
  • Was the request to your endpoint successful? You can check this by looking at the Usage Metrics for your model

  • The total time for inference must be within 30 seconds otherwise it will timeout.
  • If the above are correct, then it is worth checking to see whether your inference response matches the response schema.

Schema Validation

It's crucial to make sure that the model response sent back to V7 conforms to the response schema. Below is an example schema validation script and a JSON version of the response schema:

import json
import jsonschema
from jsonschema import validate

#Opening JSON BYOM schema
Schema_path = "/Path/To/Schema/byom-json-schema.json"
f = open(Schema_path)
json_schema = json.load(f)


def validate_json(json_data):
    try:
        validate(instance=json_data, schema=json_schema)
    except jsonschema.exceptions.ValidationError as err:
        print(err)
        err = "Given JSON data is InValid"
        return False, err

    message = "Given JSON data is Valid"
    return True, message


# Response for testing. Note that you should include the full payload
test_response = {
  "results":[
    {
      "confidence":1,
      "label":"test_polygon",
      "name":"test_polygon",
      "polygon":{
        "path":[
          {
            "x":677.0,
            "y":896.0
          },
          {
            "x":676.0,
            "y":896.0
          },
          {
            "x":675.0,
            "y":897.0
          },
          {
            "x":674.0,
            "y":897.0
          },
          {
            "x":675.0,
            "y":897.0
          },
          {
            "x":676.0,
            "y":898.0
          },
          {
            "x":675.0,
            "y":899.0
          },
          {
            "x":674.0,
            "y":899.0
          },
          {
            "x":671.0,
            "y":902.0
          }
        ]
      }
    }
  ],
  "status":"succeeded"
}


# Validation
is_valid, response = validate_json(test_response)
print(response)

Here is JSON version of the response schema which can be used in the above script

{
    "$id": "https://darwin.v7labs.com/schemas/external-models/inference-response.schema.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "Inference response",
    "description": "JSON response to an inference request. Encapsulates a list of results",
    "type": "object",
    "properties": {
      "results": {
        "items": {
          "properties": {
            "attributes": {
              "$ref": "#/$defs/attributes"
            },
            "bounding_box": {
              "$ref": "#/$defs/bounding_box"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "cuboid": {
              "$ref": "#/$defs/cuboid"
            },
            "directional_vector": {
              "$ref": "#/$defs/directional_vector"
            },
            "ellipse": {
              "$ref": "#/$defs/ellipse"
            },
            "keypoint": {
              "$ref": "#/$defs/keypoint"
            },
            "line": {
              "$ref": "#/$defs/line"
            },
            "name": {
              "type": "string"
            },
            "polygon": {
              "$ref": "#/$defs/polygon"
            },
            "skeleton": {
              "$ref": "#/$defs/skeleton"
            },
            "tag": {
              "type": "object"
            },
            "text": {
              "$ref": "#/$defs/text"
            }
          },
          "oneOf": [
            {
              "required": [
                "bounding_box"
              ]
            },
            {
              "required": [
                "cuboid"
              ]
            },
            {
              "required": [
                "directional_vector"
              ]
            },
            {
              "required": [
                "ellipse"
              ]
            },
            {
              "required": [
                "line"
              ]
            },
            {
              "required": [
                "keypoint"
              ]
            },
            {
              "required": [
                "polygon"
              ]
            },
            {
              "required": [
                "skeleton"
              ]
            },
            {
              "required": [
                "tag"
              ]
            }
          ],
          "required": [
            "name",
            "label",
            "confidence"
          ],
          "type": "object"
        },
        "type": "array"
      },
      "status": {
        "enum": [
          "succeeded",
          "failed"
        ],
        "type": "string"
      }
    },
    "required": [
      "status"
    ],
    "$defs": {
      "attributes": {
        "properties": {
          "attributes": {
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "attributes"
        ],
        "type": "array"
      },
      "bounding_box": {
        "properties": {
          "h": {
            "type": "number",
            "minimum": 0
          },
          "w": {
            "type": "number",
            "minimum": 0
          },
          "x": {
            "type": "number"
          },
          "y": {
            "type": "number"
          }
        },
        "required": [
          "h",
          "w",
          "x",
          "y"
        ],
        "type": "object"
      },
      "confidence": {
        "maximum": 1,
        "minimum": 0,
        "type": "number"
      },
      "cuboid": {
        "properties": {
          "back": {
            "$ref": "#/$defs/bounding_box"
          },
          "front": {
            "$ref": "#/$defs/bounding_box"
          }
        },
        "required": [
          "back",
          "front"
        ],
        "type": "object"
      },
      "directional_vector": {
        "properties": {
          "angle": {
            "minimum": 0,
            "type": "number"
          },
          "length": {
            "minimum": 0,
            "type": "number"
          }
        },
        "required": [
          "angle",
          "length"
        ],
        "type": "object"
      },
      "ellipse": {
        "properties": {
          "angle": {
            "minimum": 0,
            "type": "number"
          },
          "center": {
            "$ref": "#/$defs/keypoint"
          },
          "radius": {
            "$ref": "#/$defs/keypoint"
          }
        },
        "required": [
          "angle",
          "center",
          "radius"
        ],
        "type": "object"
      },
      "keypoint": {
        "properties": {
          "x": {
            "type": "number"
          },
          "y": {
            "type": "number"
          }
        },
        "required": [
          "x",
          "y"
        ],
        "type": "object"
      },
      "line": {
        "properties": {
          "path": {
            "items": {
              "$ref": "#/$defs/keypoint"
            }
          }
        },
        "required": [
          "path"
        ],
        "type": "object"
      },
      "polygon": {
        "$ref": "#/$defs/line"
      },
      "skeleton": {
        "properties": {
          "nodes": {
            "items": {
              "properties": {
                "occluded": {
                  "type": "boolean"
                },
                "x": {
                  "minimum": 0,
                  "type": "number"
                },
                "y": {
                  "minimum": 0,
                  "type": "number"
                }
              },
              "required": [
                "occluded",
                "x",
                "y"
              ],
              "type": "object"
            },
            "type": "array"
          }
        },
        "required": [
          "nodes"
        ],
        "type": "object"
      },
      "text": {
        "properties": {
          "text": {
            "type": "string"
          }
        },
        "required": [
          "text"
        ],
        "type": "object"
      }
    }
  }

Main Annotation Inference Response Examples

Below is a list of examples demonstrating how all the main annotation types should be entered in your response

Note: There is only one main annotation type per inference object

{
  "results":[
    {
      "confidence":1,
      "label":"test_polygon",
      "name":"test_polygon",
      "polygon":{
        "path":[
          {
            "x":677.0,
            "y":896.0
          },
          {
            "x":676.0,
            "y":896.0
          },
          {
            "x":675.0,
            "y":897.0
          },
          {
            "x":674.0,
            "y":897.0
          },
          {
            "x":675.0,
            "y":897.0
          },
          {
            "x":676.0,
            "y":898.0
          },
          {
            "x":675.0,
            "y":899.0
          },
          {
            "x":674.0,
            "y":899.0
          },
          {
            "x":671.0,
            "y":902.0
          }
        ]
      }
    },
    {
      "confidence":1,
      "label":"test_bbox",
      "name":"test_bbox",
      "bounding_box":{
                "h": 400,
                "w": 300,
                "x": 550,
                "y": 120
            }
    },
    {
      "confidence":1,
      "label":"test_tag",
      "name":"test_tag",
      "tag":{}
    },
    {
      "confidence":1,
      "label":"test_keypoint",
      "name":"test_keypoint",
      "keypoint":{
                "x": 550,
                "y": 120
            }
    },
    {
      "confidence":1,
      "label":"test_line",
      "name":"test_line",
      "line":{
        "path":[
          {
            "x": 25.79,
            "y": 135.3
          },
          {
            "x": 52.92,
            "y": 124.51
          },
          {
            "x": 60.31,
            "y": 141.77
          },
          {
            "x": 36.89,
            "y": 173.83
          },
          {
            "x": 35.66,
            "y": 154.41
          },
          {
            "x": 25.79,
            "y": 134.38
          },
          {
            "x": 81.27,
            "y": 143.01
          },
          {
            "x": 38.12,
            "y": 122.97
          },
          {
            "x": 25.79,
            "y": 134.38
          }
        ]
      }
    },
   {
      "confidence":1,
      "label":"test_cuboid",
      "name":"test_cuboid",
      "cuboid":{
        "back": {
          "h": 0.62,
          "w": 0.92,
          "x": 222.74,
          "y": 28.97
        },
        "front": {
          "h": 32.67,
          "w": 58.87,
          "x": 216.57,
          "y": 6.78
        }
      }
    },
    {
      "confidence":1,
      "label":"test_skeleton",
      "name":"test_skeleton",
      "skeleton":{
        "nodes": [
          {
            "name": "1",
            "occluded": False,
            "x": 130.4,
            "y": 160.25
          },
          {
            "name": "2",
            "occluded": False,
            "x": 198.63,
            "y": 161.18
          },
          {
            "name": "3",
            "occluded": False,
            "x": 216.19,
            "y": 182.97
          },
          {
            "name": "4",
            "occluded": False,
            "x": 215.86,
            "y": 134.1
          },
          {
            "name": "5",
            "occluded": False,
            "x": 120.27,
            "y": 136.59
          }
        ]
      }
    },
      {
      "confidence":1,
      "label":"test_ellipse",
      "name":"test_ellipse",
      "ellipse": {
        "angle": 0.73,
        "center": {
          "x": 49.83,
          "y": 34.21
        },
        "radius": {
          "x": 30.56,
          "y": 30.56
        }
      }
    }
  ],
  "status":"succeeded"
}

📘

Further Assistance

If you are still experiencing issues, then please reach out to our Support team on [email protected].

For customers on the Business and Pro tiers, you can request an enablement session with your CSM.