Search in sources :

Example 1 with IdentifyEntitiesResult

use of com.amplifyframework.predictions.result.IdentifyEntitiesResult in project amplify-android by aws-amplify.

the class AWSPredictionsIdentifyEntitiesTest method testIdentifyEntities.

/**
 * Assert general entity detection works.
 * @throws Exception if prediction fails
 */
@Test
// Jeff Bezos' current age
@SuppressWarnings("MagicNumber")
public void testIdentifyEntities() throws Exception {
    final Bitmap image = Assets.readAsBitmap("jeff_bezos.jpg");
    // Identify the entity inside given image and assert non-null result.
    IdentifyEntitiesResult result = (IdentifyEntitiesResult) predictions.identify(TYPE, image);
    assertNotNull(result);
    // Assert that at least one entity is detected
    assertFalse(Empty.check(result.getEntities()));
    EntityDetails entity = result.getEntities().get(0);
    // Assert features from detected entity
    FeatureAssert.assertMatches(GenderBinaryType.MALE, entity.getGender());
    FeatureAssert.assertMatches(EmotionType.HAPPY, Collections.max(entity.getEmotions()));
    assertNotNull(entity.getAgeRange());
    int jeffAge = 56;
    // When this test was created, Rekognition returned an age range containing Jeff's age.  The algorithm
    // recently changed to predict an age range of 37-55.  The goal of this test is to verify a sane response,
    // not verify the accurate of Rekognition, so we will add a 20 year buffer to the age range (e.g. if age range
    // is 37 to 55, the test will pass because 56 is still between 37-20 (17) and 55+20 (75)).
    int buffer = 20;
    assertTrue(jeffAge <= entity.getAgeRange().getHigh() + buffer);
    assertTrue(jeffAge >= entity.getAgeRange().getLow() - buffer);
}
Also used : IdentifyEntitiesResult(com.amplifyframework.predictions.result.IdentifyEntitiesResult) Bitmap(android.graphics.Bitmap) EntityDetails(com.amplifyframework.predictions.models.EntityDetails) Test(org.junit.Test)

Aggregations

Bitmap (android.graphics.Bitmap)1 EntityDetails (com.amplifyframework.predictions.models.EntityDetails)1 IdentifyEntitiesResult (com.amplifyframework.predictions.result.IdentifyEntitiesResult)1 Test (org.junit.Test)1