# Edge API

# Background

When you create an Edge project and run "Build Edge" in Imagimob Studio, your AI model is converted into a self contained C (.c) file and Header (.h) file. This document specifies the API for interacting with the Edge model.

# Using the model

Before calling any other functions,initialize the model.

// Initialize the model before calling any other functions.
void IMAI_Init();

# Input data into the model

See IMAI_Compute() and IMAI_Enqueue() definitions below.

# Get output from the model

See IMAI_Compute() and IMAI_Dequeue() definitions below.

Note: If the Queue API is used, IMAI_Dequeue() should be called right after every call to IMAI_Enqueue().

# More details

The generated API varies depending on which preprocessing functions that are used and wether the timestamp API is on/off. See below.

Requested API with Timestamps Requested API without Timestamps
Zero Queue layers exist Function API Function API
One or more queue layers exist Queue API Queue No Time API

Q: Why is there no Function API with timestamps?
A: Only queues can withhold any data and thus change the timestamps.

# Function API

#define IMAI_API_FUNCTION

// Input data and get output (prediction) from the model
// @param data_in is a pointer to one data point to input to the model
// @param data_out contains the output from the model after the function 
// returns. 
//data_out[0] contains the confidence value output by the model for class 0.
void IMAI_compute(const float *data_in, float *data_out);

# Queue API

#define IMAI_API_QUEUE

// Input data and time into the model
// @param data_in is a pointer to one data point to input to the model
// @param time_in is a pointer to one (1) timestamp to input to the model
// Time is expressed as floats where the integer part represent seconds. 
// The fractional part represents fractions of a second.
int IMAI_enqueue(const float *data_in, const float *time_in);

// Get output (predictions) from the model
// @param data_out contains the output from the model after the function 
// returns.
// data_out[0] contains the confidence value output by the model for class 0.
//
// @param time_out is a pointer to the timestamp(s) belonging to the input that produced the output from the model.
// Time is expressed as floats where the integer part represent seconds. 
// The fractional part represents fractions of a second. Time out typically has two values were 
// time_out[0] contains the start time and time_out[1] represents the end time of the input 
// generating the prediciton.
int IMAI_dequeue(float *data_out, float *time_out);

# Queue No Time API

#define IMAI_API_QUEUE_NO_TIMESTAMPS

// Input data into the model
// @param data_in is a pointer to one data point to input to the model
int IMAI_enqueue(const float *data_in);

// Get output from the model
// data_out[0] contains the confidence value output by the model for class 0.
int IMAI_dequeue(float *data_out);