- 14 Nov 2024
- 5 Minutes to read
- Print
- DarkLight
Process (inference api)
- Updated on 14 Nov 2024
- 5 Minutes to read
- Print
- DarkLight
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.
Argument | Description | Example |
---|---|---|
external_media_id | (optional) arbitrary external id for this media. | test-one-jpg-tag |
media_timestamp | (optional) actual timestamp of media creation/occurrence time | 1604007056.62 |
uploaded_by_user | (optional) user originating request | support_user@cogniac.co |
domain_unit | (optional) domain id for set assignment grouping or allowing correlation between groups of images | "test-domain-1 |
source_url | (optional) a URL of where to fetch an image from. The image is a string | |
custom_data | (optional) a string of opaque data associated with the input media. | '{'alpha': 1983.39, 'time': 'now}' |
Responses
Status Code | Description |
---|---|
200 | Successful completion. Data returned as JSON object. |
4xx | 401 - Missing Bearer token in the Authorization header |
500 | 500 - Cannot parse input data - form data incorrect |
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': 'foouser@cogniac.co',
'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
}'
Below is an example JSON-formatted response for a pipeline composed of box detection and classification apps. 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'foobar@cogniac.co'},
{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'foobar@cogniac.co'}]}