All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.lookoutvision.model.DetectAnomalyResult Maven / Gradle / Ivy

/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.lookoutvision.model;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* The prediction results from a call to DetectAnomalies. DetectAnomalyResult includes * classification information for the prediction (IsAnomalous and Confidence). If the model * you use is an image segementation model, DetectAnomalyResult also includes segmentation information ( * Anomalies and AnomalyMask). Classification information is calculated separately from * segmentation information and you shouldn't assume a relationship between them. *

*/ @Generated("software.amazon.awssdk:codegen") public final class DetectAnomalyResult implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField SOURCE_FIELD = SdkField. builder(MarshallingType.SDK_POJO) .memberName("Source").getter(getter(DetectAnomalyResult::source)).setter(setter(Builder::source)) .constructor(ImageSource::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Source").build()).build(); private static final SdkField IS_ANOMALOUS_FIELD = SdkField. builder(MarshallingType.BOOLEAN) .memberName("IsAnomalous").getter(getter(DetectAnomalyResult::isAnomalous)).setter(setter(Builder::isAnomalous)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("IsAnomalous").build()).build(); private static final SdkField CONFIDENCE_FIELD = SdkField. builder(MarshallingType.FLOAT) .memberName("Confidence").getter(getter(DetectAnomalyResult::confidence)).setter(setter(Builder::confidence)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Confidence").build()).build(); private static final SdkField> ANOMALIES_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("Anomalies") .getter(getter(DetectAnomalyResult::anomalies)) .setter(setter(Builder::anomalies)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Anomalies").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(Anomaly::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final SdkField ANOMALY_MASK_FIELD = SdkField. builder(MarshallingType.SDK_BYTES) .memberName("AnomalyMask").getter(getter(DetectAnomalyResult::anomalyMask)).setter(setter(Builder::anomalyMask)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AnomalyMask").build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(SOURCE_FIELD, IS_ANOMALOUS_FIELD, CONFIDENCE_FIELD, ANOMALIES_FIELD, ANOMALY_MASK_FIELD)); private static final long serialVersionUID = 1L; private final ImageSource source; private final Boolean isAnomalous; private final Float confidence; private final List anomalies; private final SdkBytes anomalyMask; private DetectAnomalyResult(BuilderImpl builder) { this.source = builder.source; this.isAnomalous = builder.isAnomalous; this.confidence = builder.confidence; this.anomalies = builder.anomalies; this.anomalyMask = builder.anomalyMask; } /** *

* The source of the image that was analyzed. direct means that the images was supplied from the local * computer. No other values are supported. *

* * @return The source of the image that was analyzed. direct means that the images was supplied from * the local computer. No other values are supported. */ public final ImageSource source() { return source; } /** *

* True if Amazon Lookout for Vision classifies the image as containing an anomaly, otherwise false. *

* * @return True if Amazon Lookout for Vision classifies the image as containing an anomaly, otherwise false. */ public final Boolean isAnomalous() { return isAnomalous; } /** *

* The confidence that Lookout for Vision has in the accuracy of the classification in IsAnomalous. *

* * @return The confidence that Lookout for Vision has in the accuracy of the classification in * IsAnomalous. */ public final Float confidence() { return confidence; } /** * For responses, this returns true if the service returned a value for the Anomalies property. This DOES NOT check * that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is * useful because the SDK will never return a null collection or map, but you may need to differentiate between the * service returning nothing (or null) and the service returning an empty collection or map. For requests, this * returns true if a value for the property was specified in the request builder, and false if a value was not * specified. */ public final boolean hasAnomalies() { return anomalies != null && !(anomalies instanceof SdkAutoConstructList); } /** *

* If the model is an image segmentation model, Anomalies contains a list of anomaly types found in the * image. There is one entry for each type of anomaly found (even if multiple instances of an anomaly type exist on * the image). The first element in the list is always an anomaly type representing the image background * ('background') and shouldn't be considered an anomaly. Amazon Lookout for Vision automatically add the background * anomaly type to the response, and you don't need to declare a background anomaly type in your dataset. *

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasAnomalies} method. *

* * @return If the model is an image segmentation model, Anomalies contains a list of anomaly types * found in the image. There is one entry for each type of anomaly found (even if multiple instances of an * anomaly type exist on the image). The first element in the list is always an anomaly type representing * the image background ('background') and shouldn't be considered an anomaly. Amazon Lookout for Vision * automatically add the background anomaly type to the response, and you don't need to declare a background * anomaly type in your dataset.

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. */ public final List anomalies() { return anomalies; } /** *

* If the model is an image segmentation model, AnomalyMask contains pixel masks that covers all * anomaly types found on the image. Each anomaly type has a different mask color. To map a color to an anomaly * type, see the color field of the PixelAnomaly object. *

*

* An image classification model doesn't return an Anomalies list. *

* * @return If the model is an image segmentation model, AnomalyMask contains pixel masks that covers * all anomaly types found on the image. Each anomaly type has a different mask color. To map a color to an * anomaly type, see the color field of the PixelAnomaly object.

*

* An image classification model doesn't return an Anomalies list. */ public final SdkBytes anomalyMask() { return anomalyMask; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public final int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(source()); hashCode = 31 * hashCode + Objects.hashCode(isAnomalous()); hashCode = 31 * hashCode + Objects.hashCode(confidence()); hashCode = 31 * hashCode + Objects.hashCode(hasAnomalies() ? anomalies() : null); hashCode = 31 * hashCode + Objects.hashCode(anomalyMask()); return hashCode; } @Override public final boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public final boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof DetectAnomalyResult)) { return false; } DetectAnomalyResult other = (DetectAnomalyResult) obj; return Objects.equals(source(), other.source()) && Objects.equals(isAnomalous(), other.isAnomalous()) && Objects.equals(confidence(), other.confidence()) && hasAnomalies() == other.hasAnomalies() && Objects.equals(anomalies(), other.anomalies()) && Objects.equals(anomalyMask(), other.anomalyMask()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public final String toString() { return ToString.builder("DetectAnomalyResult").add("Source", source()).add("IsAnomalous", isAnomalous()) .add("Confidence", confidence()).add("Anomalies", hasAnomalies() ? anomalies() : null) .add("AnomalyMask", anomalyMask()).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "Source": return Optional.ofNullable(clazz.cast(source())); case "IsAnomalous": return Optional.ofNullable(clazz.cast(isAnomalous())); case "Confidence": return Optional.ofNullable(clazz.cast(confidence())); case "Anomalies": return Optional.ofNullable(clazz.cast(anomalies())); case "AnomalyMask": return Optional.ofNullable(clazz.cast(anomalyMask())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((DetectAnomalyResult) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* The source of the image that was analyzed. direct means that the images was supplied from the * local computer. No other values are supported. *

* * @param source * The source of the image that was analyzed. direct means that the images was supplied from * the local computer. No other values are supported. * @return Returns a reference to this object so that method calls can be chained together. */ Builder source(ImageSource source); /** *

* The source of the image that was analyzed. direct means that the images was supplied from the * local computer. No other values are supported. *

* This is a convenience method that creates an instance of the {@link ImageSource.Builder} avoiding the need to * create one manually via {@link ImageSource#builder()}. * *

* When the {@link Consumer} completes, {@link ImageSource.Builder#build()} is called immediately and its result * is passed to {@link #source(ImageSource)}. * * @param source * a consumer that will call methods on {@link ImageSource.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #source(ImageSource) */ default Builder source(Consumer source) { return source(ImageSource.builder().applyMutation(source).build()); } /** *

* True if Amazon Lookout for Vision classifies the image as containing an anomaly, otherwise false. *

* * @param isAnomalous * True if Amazon Lookout for Vision classifies the image as containing an anomaly, otherwise false. * @return Returns a reference to this object so that method calls can be chained together. */ Builder isAnomalous(Boolean isAnomalous); /** *

* The confidence that Lookout for Vision has in the accuracy of the classification in IsAnomalous. *

* * @param confidence * The confidence that Lookout for Vision has in the accuracy of the classification in * IsAnomalous. * @return Returns a reference to this object so that method calls can be chained together. */ Builder confidence(Float confidence); /** *

* If the model is an image segmentation model, Anomalies contains a list of anomaly types found in * the image. There is one entry for each type of anomaly found (even if multiple instances of an anomaly type * exist on the image). The first element in the list is always an anomaly type representing the image * background ('background') and shouldn't be considered an anomaly. Amazon Lookout for Vision automatically add * the background anomaly type to the response, and you don't need to declare a background anomaly type in your * dataset. *

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. *

* * @param anomalies * If the model is an image segmentation model, Anomalies contains a list of anomaly types * found in the image. There is one entry for each type of anomaly found (even if multiple instances of * an anomaly type exist on the image). The first element in the list is always an anomaly type * representing the image background ('background') and shouldn't be considered an anomaly. Amazon * Lookout for Vision automatically add the background anomaly type to the response, and you don't need * to declare a background anomaly type in your dataset.

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. * @return Returns a reference to this object so that method calls can be chained together. */ Builder anomalies(Collection anomalies); /** *

* If the model is an image segmentation model, Anomalies contains a list of anomaly types found in * the image. There is one entry for each type of anomaly found (even if multiple instances of an anomaly type * exist on the image). The first element in the list is always an anomaly type representing the image * background ('background') and shouldn't be considered an anomaly. Amazon Lookout for Vision automatically add * the background anomaly type to the response, and you don't need to declare a background anomaly type in your * dataset. *

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. *

* * @param anomalies * If the model is an image segmentation model, Anomalies contains a list of anomaly types * found in the image. There is one entry for each type of anomaly found (even if multiple instances of * an anomaly type exist on the image). The first element in the list is always an anomaly type * representing the image background ('background') and shouldn't be considered an anomaly. Amazon * Lookout for Vision automatically add the background anomaly type to the response, and you don't need * to declare a background anomaly type in your dataset.

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. * @return Returns a reference to this object so that method calls can be chained together. */ Builder anomalies(Anomaly... anomalies); /** *

* If the model is an image segmentation model, Anomalies contains a list of anomaly types found in * the image. There is one entry for each type of anomaly found (even if multiple instances of an anomaly type * exist on the image). The first element in the list is always an anomaly type representing the image * background ('background') and shouldn't be considered an anomaly. Amazon Lookout for Vision automatically add * the background anomaly type to the response, and you don't need to declare a background anomaly type in your * dataset. *

*

* If the list has one entry ('background'), no anomalies were found on the image. *

*

*

* An image classification model doesn't return an Anomalies list. *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.lookoutvision.model.Anomaly.Builder} avoiding the need to create one * manually via {@link software.amazon.awssdk.services.lookoutvision.model.Anomaly#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.lookoutvision.model.Anomaly.Builder#build()} is called immediately and * its result is passed to {@link #anomalies(List)}. * * @param anomalies * a consumer that will call methods on * {@link software.amazon.awssdk.services.lookoutvision.model.Anomaly.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #anomalies(java.util.Collection) */ Builder anomalies(Consumer... anomalies); /** *

* If the model is an image segmentation model, AnomalyMask contains pixel masks that covers all * anomaly types found on the image. Each anomaly type has a different mask color. To map a color to an anomaly * type, see the color field of the PixelAnomaly object. *

*

* An image classification model doesn't return an Anomalies list. *

* * @param anomalyMask * If the model is an image segmentation model, AnomalyMask contains pixel masks that covers * all anomaly types found on the image. Each anomaly type has a different mask color. To map a color to * an anomaly type, see the color field of the PixelAnomaly object.

*

* An image classification model doesn't return an Anomalies list. * @return Returns a reference to this object so that method calls can be chained together. */ Builder anomalyMask(SdkBytes anomalyMask); } static final class BuilderImpl implements Builder { private ImageSource source; private Boolean isAnomalous; private Float confidence; private List anomalies = DefaultSdkAutoConstructList.getInstance(); private SdkBytes anomalyMask; private BuilderImpl() { } private BuilderImpl(DetectAnomalyResult model) { source(model.source); isAnomalous(model.isAnomalous); confidence(model.confidence); anomalies(model.anomalies); anomalyMask(model.anomalyMask); } public final ImageSource.Builder getSource() { return source != null ? source.toBuilder() : null; } public final void setSource(ImageSource.BuilderImpl source) { this.source = source != null ? source.build() : null; } @Override public final Builder source(ImageSource source) { this.source = source; return this; } public final Boolean getIsAnomalous() { return isAnomalous; } public final void setIsAnomalous(Boolean isAnomalous) { this.isAnomalous = isAnomalous; } @Override public final Builder isAnomalous(Boolean isAnomalous) { this.isAnomalous = isAnomalous; return this; } public final Float getConfidence() { return confidence; } public final void setConfidence(Float confidence) { this.confidence = confidence; } @Override public final Builder confidence(Float confidence) { this.confidence = confidence; return this; } public final List getAnomalies() { List result = AnomalyListCopier.copyToBuilder(this.anomalies); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setAnomalies(Collection anomalies) { this.anomalies = AnomalyListCopier.copyFromBuilder(anomalies); } @Override public final Builder anomalies(Collection anomalies) { this.anomalies = AnomalyListCopier.copy(anomalies); return this; } @Override @SafeVarargs public final Builder anomalies(Anomaly... anomalies) { anomalies(Arrays.asList(anomalies)); return this; } @Override @SafeVarargs public final Builder anomalies(Consumer... anomalies) { anomalies(Stream.of(anomalies).map(c -> Anomaly.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } public final ByteBuffer getAnomalyMask() { return anomalyMask == null ? null : anomalyMask.asByteBuffer(); } public final void setAnomalyMask(ByteBuffer anomalyMask) { anomalyMask(anomalyMask == null ? null : SdkBytes.fromByteBuffer(anomalyMask)); } @Override public final Builder anomalyMask(SdkBytes anomalyMask) { this.anomalyMask = anomalyMask; return this; } @Override public DetectAnomalyResult build() { return new DetectAnomalyResult(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy