use of com.amplifyframework.predictions.models.Label in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectModerationLabels.
private List<Label> detectModerationLabels(ByteBuffer imageData) throws PredictionsException {
DetectModerationLabelsRequest request = new DetectModerationLabelsRequest().withImage(new Image().withBytes(imageData));
// Detect moderation labels in the given image via Amazon Rekognition
final DetectModerationLabelsResult result;
try {
result = rekognition.detectModerationLabels(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting moderation labels.", serviceException, "See attached service exception for more details.");
}
List<Label> labels = new ArrayList<>();
for (ModerationLabel moderationLabel : result.getModerationLabels()) {
Label label = Label.builder().value(moderationLabel.getName()).confidence(moderationLabel.getConfidence()).parentLabels(Collections.singletonList(moderationLabel.getParentName())).build();
labels.add(label);
}
return labels;
}
use of com.amplifyframework.predictions.models.Label in project amplify-android by aws-amplify.
the class AWSPredictionsIdentifyLabelsTest method testIdentifyLabels.
/**
* Assert label detection works.
* @throws Exception if prediction fails
*/
@Test
public void testIdentifyLabels() throws Exception {
final Bitmap image = Assets.readAsBitmap("jeff_bezos.jpg");
// Identify the labels inside given image and assert non-null result.
IdentifyLabelsResult result = (IdentifyLabelsResult) predictions.identify(LabelType.ALL, image);
assertNotNull(result);
// Assert that Jeff's portrait doesn't flag moderation :)
assertFalse(result.isUnsafeContent());
// Assert at least one label is detected as "Person"
assertFalse(Empty.check(result.getLabels()));
assertTrue(Observable.fromIterable(result.getLabels()).map(Label::getName).toList().blockingGet().contains("Person"));
}
use of com.amplifyframework.predictions.models.Label in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectLabels.
private List<Label> detectLabels(ByteBuffer imageData) throws PredictionsException {
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageData));
// Detect labels in the given image via Amazon Rekognition
final DetectLabelsResult result;
try {
result = rekognition.detectLabels(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting labels.", serviceException, "See attached service exception for more details.");
}
List<Label> labels = new ArrayList<>();
for (com.amazonaws.services.rekognition.model.Label rekognitionLabel : result.getLabels()) {
List<String> parents = new ArrayList<>();
for (Parent parent : rekognitionLabel.getParents()) {
parents.add(parent.getName());
}
List<RectF> boxes = new ArrayList<>();
for (Instance instance : rekognitionLabel.getInstances()) {
boxes.add(RekognitionResultTransformers.fromBoundingBox(instance.getBoundingBox()));
}
Label amplifyLabel = Label.builder().value(rekognitionLabel.getName()).confidence(rekognitionLabel.getConfidence()).parentLabels(parents).boxes(boxes).build();
labels.add(amplifyLabel);
}
return labels;
}
Aggregations