Facial Emotion Recognition

POST https://apiv2.indico.io/fer/[batch]
Determine the emotions expressed in an image of a human face.

Current Version: 2

Private cloud endpoint

POST https://[cloud].indico.domains/fer/[batch]/

Arguments

data – refer to img format guide – required
[v or version] – Integer – optional (defaults to 2) – specify model version
[detect] – Boolean (defaults to False) – optional – When True, FER detects all faces in the image and returns their locations with a FER dictionary for each face (see Output for more information) When the image has a background or contains multiple faces, set this to true for best results.
[sensitivity] – Float (defaults to .8) – optional – The certainty threshold (between 0 and 1) the model uses to decide what to return as a face. Only used when detect is True.

For an example of how to pass keyword arguments to the indico API in a post request, see the example below.

Output

This function will return a dictionary with 6 key-value pairs. These key-value pairs represent the likelihood that each of 6 detectable emotions are expressed by the face in the analyzed image. The keys in the dictionary are strings containing the emotions (Angry, Sad, Neutral, Surprise, Fear, Happy) and the values are the probabilities that the face in the analyzed image is expressing each emotion.

Values less than 0.05 indicate that it is very unlikely the face is expressing the corresponding emotion.

Using the detect flag changes output format: When using the detect flag the results returned will be a list of dictionaries. Each dictionary in the list corresponds to a detected face. Each dictionary has two key-value pairs, the keys are “emotions” and “location”. The value of “emotions” is the same dictionary described above with 6 key-value pairs. The value of “location” is the bounding box of the detected face in the form [x position of top left corner, y position of top-left corner, width of bounding box, height of bounding box].

# single output
{
    'happy': 0.00004324968926091062,
    'sad': 0.007702528578033991,
    'angry': 0.0002575132225946431,
    'fear': 0.2071775132225946431,
    'surprise': 0.008160047807935744,
    'neutral': 0.00015069427192724994
}

# batch output
[
    {
        'happy': 0.00004324968926091062,
        'sad': 0.007702528578033991,
        'angry': 0.0002575132225946431,
        'fear': 0.2071775132225946431,
        'surprise': 0.008160047807935744,
        'neutral': 0.00015069427192724994
    }, 
    {
        'happy': 0.00004324968926091062,
        'sad': 0.007702528578033991,
        'angry': 0.0002575132225946431,
        'fear': 0.2071775132225946431,
        'surprise': 0.008160047807935744,
        'neutral': 0.00015069427192724994
    }
]

Example

// Single Example
fetch('https://apiv2.indico.io/fer', {
  method: 'POST',
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    data: '<IMAGE>',
    detect: true
  })
})
  .then(r => r.json())
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));

// Batch Example
fetch('https://apiv2.indico.io/fer/batch', {
  method: 'POST',
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    data: [
      '<IMAGE>',
      '<IMAGE>'
    ],
    detect: true
  })
})
  .then(r => r.json())
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));