Applications - Detections
  • 06 Feb 2024
  • 8 Minutes to read
  • Dark
    Light

Applications - Detections

  • Dark
    Light

Article summary

The Application Detections endpoint returns the latest assertions on media from either a user or the application's current best model.

Application Detection Objects

Field

media object

A Cogniac Media item.

focus map

(optional) Map or object identifying the portion or subregion of the media, (e.g. a particular box area or range of frames) with which the subject-media association is asserted.    If the entire media is processed, this field will be null.

detections array

A list of subject-media assertion objects.

other_media array

(optional) List of other media objects that may be related to this subject-media association.

updated_at float

The timestamp of the latest assertion on this media in the context of this application.

Subject-Media Assertion Object

Field

Example

Description

subject_uid string

"cat_123"

The ID of the subject.

detection_id string

"1hg2Srt8c"

Unique ID of the user or model detection.

user_id string

"user@cogniac.co"

(optional) Username of the user that created the subject-media assertion.    If the record is a model assertion this field will be null.

model_id string

"Hpo-h-1ec0-to5dGrTAN9QeV6djep-CN_mtsv0_2000.tgz"

(optional) ID of the model that created the subject-media assertion.    If the record is a user assertion this field will be null.

app_id string

"a765rtyg"

(optional) ID of an application, the context in which the assertion was created.    In the case that an assertion was made out of an application context, e.g. a media item was directly captured to a subject, this field will be null.

app_data_type string

"box_set"

(optional) String representing the application-type-specific context of the subject-media association.

app_data object

{  "box":  {"x0": 20,  "y0": 56,  "x1": 535,  "y1": 249},  "probability": 0.95  }

(optional) Application-type-specific meta data for the subject-media association.

prev_prob float

0.87

(optional) Likelihood of the subject-media (and optional focus) association in the previous assertion.

probability float

0.99

The current likelihood of the association between the subject and the media (plus optional focus).    This probability is independent of the app_data, i.e. the overall probability that the subject is associated with the media and focus, regardless of correctness of app_data.

uncal_prob float

1.0

The assertion probability by either a user or model.    In the event that the app_data contains multiple predictions this is a single, summarized number for user presentation purposes. Summarization is application specific.

created_at unix timestamp

1234567890

Time at which the assertion was created.

Retrieving Application Detections

The following query parameters are supported:

Argument

Example

Description

start float

1234567890.0

(optional) Unix timestamp. Return media updated after this timestamp.    Defaults to 0.

end float

1234567890.0

(optional) Unix timestamp. Return media updated prior to this timestamp.    Defaults to current time.

probability_upper float

0.75

(optional) Subject-media association probability ceiling.    Defaults to 1.0.

probability_lower float

0.25

(optional) Subject-media association probability floor.    Defaults to 0.0.

limit integer

10

(optional) Number of results to return per page.    Defaults to 10.

reverse boolean

True

(optional)    True = return results in descending order based on assertion timestamp.    False = return results in ascending order.    Defaults to False.

consensus_none boolean

True

(optional) When set to True, will return only media assertions that have not reached consensus.    This is useful for alternate feedback interfaces where it is undesirable to display items that have already reached consensus.    Defaults to False.

only_user boolean

True

(optional) When set to True, will return only media assertions made by users.    Defaults to False.    only_user and only_model cannot both be set to True.

only_model boolean

False

(optional) When set to True, will return only media assertions made by the latest best model.    Defaults to False.    only_user and only_model cannot both be set to True.

GET /1/applications/{application_id}/detections
Host: https://api.cogniac.io

Example: Retrieve Application Detections

curl -X GET https://api.cogniac.io/1/applications/di71rG94/detections?limit=10&reverse=true \
-H "Authorization: Bearer abcdefg.hijklmnop.qrstuvwxyz"
import cogniac
from pprint import pprint

app_id = '0Am1V3kr'
# connect to the tenant
cc = cogniac.CogniacConnection(username="test@cogniac.co", 
                               password="abcdefghijk", 
                               tenant_id="skjdfh853k4jt")

# get the app object
my_app = cc.get_application(app_id)

# the detections method returns an iterator of app detections
detections = my_app.detections(limit=1, reverse=True)
for detection in detections:
  pprint(detection)
{
  "data": [
   {'detections': [{'app_data': None,
                 'app_data_type': None,
                 'app_id': 'yii3tm2g',
                 'assertion_prefix': 'RPSuDaRJOX5wi998cVxAmI9',
                 'created_at': 1693951026.527223,
                 'detection_id': 'RPSuDaRJOX5wi998cVxAmI9:0',
                 'focus': None,
                 'media_id': '2C9OUC8BEXURYEFMABYHGSWEUBIM',
                 'model_id': 'InitialModel_yii3tm2g_OxxbyP.tgz',
                 'model_image_id': 'InitialModel_yii3tm2g_OxxbyP.tgz:5431c7e',
                 'origin': None,
                 'prev_prob': 0.5000034855833563,
                 'probability': 0.5000034855833563,
                 'subject_uid': 'dog5333_6ggqjf',
                 'uncal_prob': 1.0,
                 'user_id': None}],
 'focus': None,
 'force_feedback': True,
 'force_review': False,
 'media': {'author': None,
           'author_profile_url': None,
           'bits_per_pixel': 8,
           'created_at': 1693950644.539737,
           'domain_unit': '39eece0dd462c4bd9545b995222046b4',
           'duration': None,
           'external_media_id': None,
           'filename': '174d2108eea9b488.jpg',
           'fps': None,
           'frame': None,
           'frame_durations': [],
           'frame_preview_map': {},
           'image_height': 737,
           'image_width': 1024,
           'license': None,
           'md5': '39eece0dd462c4bd9545b995222046b4',
           'media_format': 'JPEG',
           'media_id': '2C9OUC8BEXURYEFMABYHGSWEUBIM',
           'media_src': 'web_app',
           'media_timestamp': 1671569480.424,
           'media_url': 'https://api.cogniac.io/1/media/download/2C9OUC8BEXURYEFMABYHGSWEUBIM/2C9OUC8BEXURYEFMABYHGSWEUBIM',
           'meta_tags': None,
           'network_camera_id': None,
           'num_channels': 3,
           'num_frames': None,
           'original_landing_url': None,
           'original_url': None,
           'parent_media_id': None,
           'parent_media_ids': [],
           'preview_url': None,
           'resize_urls': {'454': 'https://api.cogniac.io/1/media/download/2C9OUC8BEXURYEFMABYHGSWEUBIM/2C9OUC8BEXURYEFMABYHGSWEUBIM_max_454'},
           'sequence_ix': None,
           'set_assignment': 'validation',
           'size': 172109.0,
           'source_url': None,
           'status': 'success',
           'tenant_id': 'd16jdqt1h71f',
           'time_base': None,
           'title': None,
           'trigger_id': None,
           'uploaded_by_user': 'user@cogniac.co',
           'video': False,
           'video_context': None},
 'media_list': [{'author': None,
                 'author_profile_url': None,
                 'bits_per_pixel': 8,
                 'created_at': 1693950644.539737,
                 'domain_unit': '39eece0dd462c4bd9545b995222046b4',
                 'duration': None,
                 'external_media_id': None,
                 'filename': '174d2108eea9b488.jpg',
                 'fps': None,
                 'frame': None,
                 'frame_durations': [],
                 'frame_preview_map': {},
                 'image_height': 737,
                 'image_width': 1024,
                 'license': None,
                 'md5': '39eece0dd462c4bd9545b995222046b4',
                 'media_format': 'JPEG',
                 'media_id': '2C9OUC8BEXURYEFMABYHGSWEUBIM',
                 'media_src': 'web_app',
                 'media_timestamp': 1671569480.424,
                 'media_url': 'https://api.cogniac.io/1/media/download/2C9OUC8BEXURYEFMABYHGSWEUBIM/2C9OUC8BEXURYEFMABYHGSWEUBIM',
                 'meta_tags': None,
                 'network_camera_id': None,
                 'num_channels': 3,
                 'num_frames': None,
                 'original_landing_url': None,
                 'original_url': None,
                 'parent_media_id': None,
                 'parent_media_ids': [],
                 'preview_url': None,
                 'resize_urls': {'454': 'https://api.cogniac.io/1/media/download/2C9OUC8BEXURYEFMABYHGSWEUBIM/2C9OUC8BEXURYEFMABYHGSWEUBIM_max_454'},
                 'sequence_ix': None,
                 'set_assignment': 'validation',
                 'size': 172109.0,
                 'source_url': None,
                 'status': 'success',
                 'tenant_id': 'd16jdqt1h71f',
                 'time_base': None,
                 'title': None,
                 'trigger_id': None,
                 'uploaded_by_user': 'user@cogniac.co',
                 'video': False,
                 'video_context': None}],
 'other_media': [],
 'updated_at': 1693951026.527223}

Detection Post URLs

In addition to polling for recent Application detections, you can also specify callback URLs to receive postback detections in realtime as they occur. Please enter your listening URL's in the detection_post_urls field of the Application object, for example "detection_post_urls":["http://127.0.0.1:9999/my_model_output.net", "https://product_model_detections.co"].

Posts are retried for thirty seconds, but URL's that fail retried posts after thirty seconds are blacklisted for five minutes.

The detection callback post will will only be sent if a subject probability is over the configured detection threshold (0.5 by default).

{
    "media": {"media_id": "dfc37db6723376ab953b10cd40097a68"
            "parent_media_ids": ['c8ee0f4f05f3fdcf36f69a3fd81fd84f'],
           },
  "focus":{
        "box": {"x0": 50, "x1": 275, "y0": 634, "y1": 870}
      },
  "subjects":[
    {
      "subject_uid":"dog",
      "probability":0.79,
      "updated_at": 1481857269.646634
      
    },
    {
      "subject_uid":"cat",
      "probability":0.49,
      "updated_at": 1481857269.646634      
    }  
  ]
}


Was this article helpful?