Class SegmentObjectsFromONNXModel
Object
AnchorBean<SegmentStackIntoObjectsPooled<OnnxModel>>
InitializableBean<SegmentStackIntoObjectsPooled<OnnxModel>,ImageInitialization>
ImageBean<SegmentStackIntoObjectsPooled<OnnxModel>>
SegmentationBean<SegmentStackIntoObjectsPooled<OnnxModel>>
SegmentStackIntoObjectsPooled<OnnxModel>
SegmentStackIntoObjectsScaleDecode<ai.onnxruntime.OnnxTensor,OnnxModel>
SegmentObjectsFromONNXModel
public class SegmentObjectsFromONNXModel
extends SegmentStackIntoObjectsScaleDecode<ai.onnxruntime.OnnxTensor,OnnxModel>
Performs instance-segmentation using the ONNX Runtime and an
.onnx
model file.- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateModelPool
(ConcurrencyPlan plan, Logger logger) Creates the model pool (to be used by multiple threads).protected ai.onnxruntime.OnnxTensor
deriveInput
(Stack stack, Optional<double[]> subtractMeans) Derives the input tensor from an image.The name of the input in the ONNX model.Relative-path to the model file in ONNX form, relative to the models/ directory in the Anchor distribution.The name of the tensor in the model which the input-image is mapped to.boolean
If true, a 4-dimensional tensor is created (with the first dimension describing a batch-size of 1), instead of the usual 3-dimensional tensor describing channel, height, width.boolean
If true, the channels are placed as the final position of the tensor (**after** width/height) instead of **before** width/height.boolean
When true, rather than readingmodelPath
from the file-system, it is read from Java resources on the class-path.void
setIncludeBatchDimension
(boolean includeBatchDimension) If true, a 4-dimensional tensor is created (with the first dimension describing a batch-size of 1), instead of the usual 3-dimensional tensor describing channel, height, width.void
setInputName
(String inputName) The name of the input in the ONNX model.void
setInterleaveChannels
(boolean interleaveChannels) If true, the channels are placed as the final position of the tensor (**after** width/height) instead of **before** width/height.void
setModelPath
(String modelPath) Relative-path to the model file in ONNX form, relative to the models/ directory in the Anchor distribution.void
setReadFromResources
(boolean readFromResources) When true, rather than readingmodelPath
from the file-system, it is read from Java resources on the class-path.Methods inherited from class org.anchoranalysis.image.inference.bean.segment.instance.SegmentStackIntoObjectsScaleDecode
getClassLabelsPath, getDecode, getDisplayer, getInterpolator, getScaleInput, getSubtractMean, segment, setClassLabelsPath, setDecode, setDisplayer, setInterpolator, setScaleInput, setSubtractMean
Methods inherited from class org.anchoranalysis.image.inference.bean.segment.instance.SegmentStackIntoObjectsPooled
resolve, segment
Methods inherited from class org.anchoranalysis.bean.initializable.InitializableBean
getInitialization, getLogger, getPropertyInitializer, initialize, initializeRecursive, initRecursiveWithInitializer, isInitialized, onInitialization
Methods inherited from class org.anchoranalysis.bean.AnchorBean
checkMisconfigured, describeBean, describeChildren, duplicateBean, fields, findFieldsOfClass, getBeanName, getLocalPath, localise, toString
-
Constructor Details
-
SegmentObjectsFromONNXModel
public SegmentObjectsFromONNXModel()
-
-
Method Details
-
createModelPool
public ConcurrentModelPool<OnnxModel> createModelPool(ConcurrencyPlan plan, Logger logger) throws CreateModelFailedException Description copied from class:SegmentStackIntoObjectsPooled
Creates the model pool (to be used by multiple threads).- Specified by:
createModelPool
in classSegmentStackIntoObjectsPooled<OnnxModel>
- Parameters:
plan
- the number and types of processors available for concurrent execution.logger
- the logger.- Returns:
- the newly created model pool.
- Throws:
CreateModelFailedException
- if a model cannot be created.
-
deriveInput
protected ai.onnxruntime.OnnxTensor deriveInput(Stack stack, Optional<double[]> subtractMeans) throws OperationFailedException Description copied from class:SegmentStackIntoObjectsScaleDecode
Derives the input tensor from an image.- Specified by:
deriveInput
in classSegmentStackIntoObjectsScaleDecode<ai.onnxruntime.OnnxTensor,
OnnxModel> - Parameters:
stack
- the image which is mapped into an input tensor.subtractMeans
- respective intensity values that are subtracted from the voxels before being added to the tensor (respectively for each channel).- Returns:
- the tensor, representing the input image.
- Throws:
OperationFailedException
- if an input tensor cannot be created.
-
inputName
Description copied from class:SegmentStackIntoObjectsScaleDecode
The name of the tensor in the model which the input-image is mapped to.- Specified by:
inputName
in classSegmentStackIntoObjectsScaleDecode<ai.onnxruntime.OnnxTensor,
OnnxModel> - Returns:
- the name.
-
getModelPath
Relative-path to the model file in ONNX form, relative to the models/ directory in the Anchor distribution.If
readFromResources==true
, it is read instead from resources on the class-path. -
setModelPath
Relative-path to the model file in ONNX form, relative to the models/ directory in the Anchor distribution.If
readFromResources==true
, it is read instead from resources on the class-path. -
isReadFromResources
public boolean isReadFromResources()When true, rather than readingmodelPath
from the file-system, it is read from Java resources on the class-path. -
setReadFromResources
public void setReadFromResources(boolean readFromResources) When true, rather than readingmodelPath
from the file-system, it is read from Java resources on the class-path. -
getInputName
The name of the input in the ONNX model. -
setInputName
The name of the input in the ONNX model. -
isIncludeBatchDimension
public boolean isIncludeBatchDimension()If true, a 4-dimensional tensor is created (with the first dimension describing a batch-size of 1), instead of the usual 3-dimensional tensor describing channel, height, width. -
setIncludeBatchDimension
public void setIncludeBatchDimension(boolean includeBatchDimension) If true, a 4-dimensional tensor is created (with the first dimension describing a batch-size of 1), instead of the usual 3-dimensional tensor describing channel, height, width. -
isInterleaveChannels
public boolean isInterleaveChannels()If true, the channels are placed as the final position of the tensor (**after** width/height) instead of **before** width/height.Consequently, in terms of raw order in a
FloatBuffer
, RGB values become interleaved. -
setInterleaveChannels
public void setInterleaveChannels(boolean interleaveChannels) If true, the channels are placed as the final position of the tensor (**after** width/height) instead of **before** width/height.Consequently, in terms of raw order in a
FloatBuffer
, RGB values become interleaved.
-