Package ai.djl.modality.cv.translator
Class Sam2Translator
java.lang.Object
ai.djl.modality.cv.translator.Sam2Translator
- All Implemented Interfaces:
NoBatchifyTranslator<Sam2Translator.Sam2Input,,DetectedObjects> PostProcessor<DetectedObjects>,PreProcessor<Sam2Translator.Sam2Input>,Translator<Sam2Translator.Sam2Input,DetectedObjects>
public class Sam2Translator
extends Object
implements NoBatchifyTranslator<Sam2Translator.Sam2Input,DetectedObjects>
A
Translator that handles mask generation task.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe builder for Sam2Translator.static final classA class represents the segment anything input. -
Constructor Summary
ConstructorsConstructorDescriptionSam2Translator(Sam2Translator.Builder builder) Constructs aSam2Translatorinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic Sam2Translator.Builderbuilder()Creates a builder to build aSam2Translator.static Sam2Translator.BuilderCreates a builder to build aSam2Translatorwith specified arguments.voidprepare(TranslatorContext ctx) Prepares the translator with the manager and model to use.processInput(TranslatorContext ctx, Sam2Translator.Sam2Input input) Processes the input and converts it to NDList.processOutput(TranslatorContext ctx, NDList list) Processes the output NDList to the corresponding output object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.djl.translate.NoBatchifyTranslator
getBatchifierMethods inherited from interface ai.djl.translate.Translator
batchProcessInput, batchProcessOutput, getExpansions
-
Constructor Details
-
Sam2Translator
Constructs aSam2Translatorinstance.
-
-
Method Details
-
prepare
Prepares the translator with the manager and model to use.- Specified by:
preparein interfaceTranslator<Sam2Translator.Sam2Input,DetectedObjects> - Parameters:
ctx- the context for thePredictor.- Throws:
IOExceptionModelException
-
processInput
Processes the input and converts it to NDList.- Specified by:
processInputin interfacePreProcessor<Sam2Translator.Sam2Input>- Parameters:
ctx- the toolkit for creating the input NDArrayinput- the input object- Returns:
- the
NDListafter pre-processing - Throws:
Exception- if an error occurs during processing input
-
processOutput
Processes the output NDList to the corresponding output object.- Specified by:
processOutputin interfacePostProcessor<DetectedObjects>- Parameters:
ctx- the toolkit used for post-processinglist- the output NDList after inference, usually immutable in engines like PyTorch. @see Issue 1774- Returns:
- the output object of expected type
-
builder
Creates a builder to build aSam2Translator.- Returns:
- a new builder
-
builder
Creates a builder to build aSam2Translatorwith specified arguments.- Parameters:
arguments- arguments to specify builder options- Returns:
- a new builder
-