Process (inference api)

Inference APIs available on an Edgeflow/Gateway

Edgeflow Inference API

The Gateway supports an inference API which returns detections from all models in a pipeline.

POST /1/process/{subject_uid}
HOST: http://<gateway ip address or hostname>:8000

The Edgeflow listens for HTTP POST requests on port 8000. The URL must include the input subject_uid of the first application in which inference is to begin. These subjects are configured as output subjects of an HTTP Input application (see the previous section on configuring this application).

Additional arguments can be provided as part of the form-data.
All responses are returned along with the HTTP status response.

ArgumentDescriptionExample
external_media_id
string
(optional) arbitrary external id for this media.test-one-jpg-tag
media_timestamp
float
(optional) actual timestamp of media creation/occurrence time1604007056.62
uploaded_by_user
string
(optional) user originating request[email protected]
domain_unit
string
(optional) domain id for set assignment grouping or allowing correlation between groups of images"test-domain-1
source_url
string
(optional) a URL of where to fetch an image from. The image is a stringhttp://localdomain.test.io/images/image.jpg
custom_data(optional) a string of opaque data associated with the input media.'{'alpha': 1983.39, 'time': 'now}'

Responses

Status CodeDescription
200Successful completion. Data returned as JSON object.
4xx401 - Missing Bearer token in the Authorization header
401 - Invalid Bearer token in the Authorization header - refresh the token
401 - Unable to parse input subject trigger
403 - Invalid tenant <tenant_id>
403 - Unable to extract PDF image
403 - Error downloading media from URL
404 - Subject ID not found - Output subject uid is not configured in the HTTP input application.
411 - Unable to parse subject assertion request
500500 - Cannot parse input data - form data incorrect
504 - Backend response timeout - timeout from downstream application(s) - the request took more than 60seconds. The downstream application(s) which did not respond are listed in the response message using the string format "Applications not responding: app_id_1,app_id2"
504 - Failed to parse detection - detection format from downstream applications

API usage example

import requests
from time import time
import simplejson as json

API_VERSION = 1
EDGEFLOW_IP="10.1.20.100"
URL_PREFIX = 'http://%s:8000/%d/' % (EDGEFLOW_IP, API_VERSION)
TIMEOUT_SECS = 20
SUBJECT_UID = "drone_images_6op"
filename = "testimg.jpg"
files = {'file': open(filename, 'rb')}
data = {"media_timestamp": time(),
        "external_media_id":"abcde-tag", 
        'uploaded_by_user': '[email protected]', 
        'domain_unit': 'test_domain_1',
        'custom_data': json.dumps({'test': "123test", 'tick': time()})}

resp = requests.post(URL_PREFIX + 'process/%s' % SUBJECT_UID, data=data, files=files, timeout=TIMEOUT_SECS)

if resp.status_code == 200:
  	detections = resp.json()
curl -X POST -F 'cat.jpg=@path/to/local/file/cat.jpg' \ http:10.1.20.100:8000/1/process/drone_images_6op \
-H "Content-Type: application/json" \
-d '{
 	"media_timestamp": 1589833.02
 }'

An example JSON formatted response for a pipeline composed of box detection and classification apps is shown below. The primary key is 'detections' whose value is a list of all detections for the pipeline associated with an input subject_uid.
Each detection entry contains the application_id reporting the detection, the model used, output subject_id, probability, and specific application data associated with the application. For example, a box detection app will report app_data_type as 'box_set' and a list of boxes in the app_data dictionary.

{u'detections': [{u'app_data': [{u'box': {u'x0': 1474,
                                          u'x1': 1554,
                                          u'y0': 1449,
                                          u'y1': 1487},
                                 u'probability': 0.8900902271270752},
                                {u'box': {u'x0': 705,
                                          u'x1': 781,
                                          u'y0': 988,
                                          u'y1': 1028},
                                 u'probability': 0.8875505924224854},
                                {u'box': {u'x0': 1979,
                                          u'x1': 2038,
                                          u'y0': 2417,
                                          u'y1': 2482},
                                          u'app_data_type': u'box_set',
                  u'app_id': u'z2PNlsAs',
                  u'assertion_prefix': u'spabepadrjic',
                  u'created_at': 1545864284.67,
                  u'detection_id': u'spabepadrjic:0',
                  u'focus': None,
                  u'model_id': u'Hpo-d-8e49-DmDT9hhuJOW_mtsv1_INT_10000.tgz',
                  u'subject_uid': u'vehicles_carbox_3gu',
                  u'uncal_prob': 0.8900902271270752,
                  u'user_id': u'[email protected]'},
                 {u'app_data': None,
                  u'app_data_type': None,
                  u'app_id': u'8H88vm4v',
                  u'assertion_prefix': u'spabepadrjic.ankz',
                  u'created_at': 1545864284.67,
                  u'detection_id': u'spabepadrjic.ankz:0',
                  u'focus': {u'box': {u'x0': 3977,
                                      u'x1': 3997,
                                      u'y0': 1670,
                                      u'y1': 1713}},
                  u'inference_focus': {u'box': {u'x0': 3773,
                                                u'x1': 4000,
                                                u'y0': 1578,
                                                u'y1': 1805}},                 
                  u'model_id': u'InitialModel_8H88vm4v_gKS6Vz.tgz',
                  u'subject_uid': u'vehiclestestoutput_6jo',
                  u'uncal_prob': 1.0,
                  u'user_id': u'[email protected]'}]}