AI for Earth Species Classification API

API change history

API for identifying the species of plants and animals in images.

Predict

Performs classification and optionally detection on a given image. A successful response will contain a list of predictions containing taxonomic information about each possible species. The list of predictions will always be in order of descending confidence so that the first item in the list of predictions is the most likely species classification.

The each prediction will contain the scientific name of the species and the confidence of the prediction. It may also contain the following optional fields:

  • class
  • class_common
  • family
  • family_common
  • genus
  • genus_common
  • kingdom
  • kingdom_common
  • order
  • order_common
  • phylum
  • phylum_common
  • subspecies
  • subspecies_common
  • suborder
  • suborder_common
  • subphylum
  • subphylum_common

The the bounding box JSON object specified according to the pixel values x_min, y_min, x_max, y_max, where the point 0, 0 is the top left corner of the image.

Request

Request URL

Request parameters

  • (optional)
    integer

    Number of results to return for a given image. Default is 1.

  • (optional)
    string

    The prediction mode for the request. By default the operation performs classification and detection on the image. The accepted values are:

    • classifyOnly - Only perform classification on the image.
    • classifyAndDetect (default) - Perform both classification and detection on the image.

Request headers

  • (optional)
    string
    Media type of the body sent to the API.
  • string
    Subscription key which provides access to this API. Found in your Profile.

Request body

The predict method accepts binary image data in JPEG, TIFF, or PNG format or a JSON body containing a URL to an image. The maximum image size is 6MB.

Responses

200 OK

The predict method returns a list of K predictions. The object will contain the common and scientific name for the species, genus, family, order, class, phylum and kingdom for the predicted species.

Representations

{
    "bboxes": [
        {
            "confidence": 96.41780853271484,
            "x_max": 1137.232666015625,
            "x_min": 284.5081787109375,
            "y_max": 746.4176025390625,
            "y_min": 91.25875854492188
        }
    ],
    "predictions": [
        {
            "class": "Mammalia",
            "class_common": "Mammals",
            "confidence": 46.91891372203827,
            "family": "Felidae",
            "family_common": "Felines",
            "genus": "Leopardus",
            "genus_common": "Neotropical Spotted Cats",
            "kingdom": "Animalia",
            "kingdom_common": "Animals",
            "order": "Carnivora",
            "order_common": "Carnivorans",
            "phylum": "Chordata",
            "phylum_common": "Chordates",
            "species": "Leopardus pardalis",
            "species_common": "Ocelot",
            "subphylum": "Vertebrata",
            "subphylum_common": "Vertebrates"
        },
        {
            "class": "Mammalia",
            "class_common": "Mammals",
            "confidence": 18.56187731027603,
            "family": "Equidae",
            "family_common": "Equines",
            "genus": "Equus",
            "genus_common": "Horses, Asses, and Zebras",
            "kingdom": "Animalia",
            "kingdom_common": "Animals",
            "order": "Perissodactyla",
            "order_common": "Odd-toed Ungulates",
            "phylum": "Chordata",
            "phylum_common": "Chordates",
            "species": "Equus quagga",
            "species_common": "Plains Zebra",
            "subphylum": "Vertebrata",
            "subphylum_common": "Vertebrates"
        },
        {
            "class": "Mammalia",
            "class_common": "Mammals",
            "confidence": 5.143467336893082,
            "family": "Felidae",
            "family_common": "Felines",
            "genus": "Lynx",
            "genus_common": "Lynxes",
            "kingdom": "Animalia",
            "kingdom_common": "Animals",
            "order": "Carnivora",
            "order_common": "Carnivorans",
            "phylum": "Chordata",
            "phylum_common": "Chordates",
            "species": "Lynx rufus",
            "species_common": "Bobcat",
            "subphylum": "Vertebrata",
            "subphylum_common": "Vertebrates"
        },
        {
            "class": "Mammalia",
            "class_common": "Mammals",
            "confidence": 3.212125226855278,
            "family": "Felidae",
            "family_common": "Felines",
            "genus": "Felis",
            "genus_common": "",
            "kingdom": "Animalia",
            "kingdom_common": "Animals",
            "order": "Carnivora",
            "order_common": "Carnivorans",
            "phylum": "Chordata",
            "phylum_common": "Chordates",
            "species": "Felis catus",
            "species_common": "Domestic Cat",
            "subphylum": "Vertebrata",
            "subphylum_common": "Vertebrates"
        },
        {
            "class": "Mammalia",
            "class_common": "Mammals",
            "confidence": 1.681293547153473,
            "family": "Felidae",
            "family_common": "Felines",
            "genus": "Puma",
            "genus_common": "",
            "kingdom": "Animalia",
            "kingdom_common": "Animals",
            "order": "Carnivora",
            "order_common": "Carnivorans",
            "phylum": "Chordata",
            "phylum_common": "Chordates",
            "species": "Puma concolor",
            "species_common": "Mountain Lion",
            "subphylum": "Vertebrata",
            "subphylum_common": "Vertebrates"
        }
    ]
}

415 Unsupported Media Type

413 Request Entity Too Large

Representations

Code samples

@ECHO OFF

curl -v -X POST "https://aiforearth.azure-api.net/species-recognition/v0.1/predict?topK=1&predictMode=classifyAndDetect"
-H "Content-Type: application/octet-stream"
-H "Ocp-Apim-Subscription-Key: {subscription key}"

--data-ascii "{body}" 
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            MakeRequest();
            Console.WriteLine("Hit ENTER to exit...");
            Console.ReadLine();
        }
        
        static async void MakeRequest()
        {
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");

            // Request parameters
            queryString["topK"] = "1";
            queryString["predictMode"] = "classifyAndDetect";
            var uri = "https://aiforearth.azure-api.net/species-recognition/v0.1/predict?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes("{body}");

            using (var content = new ByteArrayContent(byteData))
            {
               content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
               response = await client.PostAsync(uri, content);
            }

        }
    }
}	
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://aiforearth.azure-api.net/species-recognition/v0.1/predict");

            builder.setParameter("topK", "1");
            builder.setParameter("predictMode", "classifyAndDetect");

            URI uri = builder.build();
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "application/octet-stream");
            request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");


            // Request body
            StringEntity reqEntity = new StringEntity("{body}");
            request.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
    $(function() {
        var params = {
            // Request parameters
            "topK": "1",
            "predictMode": "classifyAndDetect",
        };
      
        $.ajax({
            url: "https://aiforearth.azure-api.net/species-recognition/v0.1/predict?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Content-Type","application/octet-stream");
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSString* path = @"https://aiforearth.azure-api.net/species-recognition/v0.1/predict";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                         @"topK=1",
                         @"predictMode=classifyAndDetect",
                      ];
    
    NSString* string = [array componentsJoinedByString:@"&"];
    path = [path stringByAppendingFormat:@"?%@", string];

    NSLog(@"%@", path);

    NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
    [_request setHTTPMethod:@"POST"];
    // Request headers
    [_request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
    [_request setValue:@"{subscription key}" forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"];
    // Request body
    [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];

    if (nil != error)
    {
        NSLog(@"Error: %@", error);
    }
    else
    {
        NSError* error = nil;
        NSMutableDictionary* json = nil;
        NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
        NSLog(@"%@", dataString);
        
        if (nil != _connectionData)
        {
            json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
        }
        
        if (error || !json)
        {
            NSLog(@"Could not parse loaded json with error:%@", error);
        }
        
        NSLog(@"%@", json);
        _connectionData = nil;
    }
    
    [pool drain];

    return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://aiforearth.azure-api.net/species-recognition/v0.1/predict');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/octet-stream',
    'Ocp-Apim-Subscription-Key' => '{subscription key}',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'topK' => '1',
    'predictMode' => 'classifyAndDetect',
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("{body}");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>
########### Python 2.7 #############
import httplib, urllib, base64

headers = {
    # Request headers
    'Content-Type': 'application/octet-stream',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.urlencode({
    # Request parameters
    'topK': '1',
    'predictMode': 'classifyAndDetect',
})

try:
    conn = httplib.HTTPSConnection('aiforearth.azure-api.net')
    conn.request("POST", "/species-recognition/v0.1/predict?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'application/octet-stream',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
    # Request parameters
    'topK': '1',
    'predictMode': 'classifyAndDetect',
})

try:
    conn = http.client.HTTPSConnection('aiforearth.azure-api.net')
    conn.request("POST", "/species-recognition/v0.1/predict?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################
require 'net/http'

uri = URI('https://aiforearth.azure-api.net/species-recognition/v0.1/predict')

query = URI.encode_www_form({
    # Request parameters
    'topK' => '1',
    'predictMode' => 'classifyAndDetect'
})
if query.length > 0
  if uri.query && uri.query.length > 0
    uri.query += '&' + query
  else
    uri.query = query
  end
end

request = Net::HTTP::Post.new(uri.request_uri)
# Request headers
request['Content-Type'] = 'application/octet-stream'
# Request headers
request['Ocp-Apim-Subscription-Key'] = '{subscription key}'
# Request body
request.body = "{body}"

response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
end

puts response.body