Package qupath.opencv.dnn
Class OpenCVDnn
- All Implemented Interfaces:
AutoCloseable
,UriResource
,DnnModel
Wrapper for an OpenCV Net, including essential metadata about how it should be used.
The main purpose of this is to support serializing models to JSON... kind of. In truth currently the paths to the original model files are serialized, since (to my knowledge) there is no way to save and reload a Net directly.
- Author:
- Pete Bankhead
-
Nested Class Summary
-
Field Summary
Fields inherited from interface qupath.opencv.dnn.DnnModel
DEFAULT_INPUT_NAME, DEFAULT_OUTPUT_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic OpenCVDnn.Builder
Create a new builder.<T extends Model>
TBuild a model.<T extends Model>
TBuild a model, specifying theOpenCVDnn.ModelType
.buildNet()
Build the OpenCVNet
.void
close()
Close this model if it will not be needed again.Get the function that can convert one or more OpenCV Mats into a blob supported by the prediction function for the first (or only) input.getBlobFunction
(String name) Get the function that can convert one or more OpenCV Mats into a blob supported by the prediction function for a specified input layer.Get the path to the model configuration, if required.Get the framework used to create the model.getMean()
Get means which should be subtracted for preprocessing.Get the type of the model that would be built withbuildModel()
.Get the path to the model.getName()
Get a user-readable name for this model, or null if no name is specified.Get the prediction function that can apply a prediction with one or more blobs as input.getScale()
Get scale factors to be applied to preprocess input.getURIs()
Get all the URIs required for this resource.void
initializeModel
(Model model) Initialize the model with the same preprocessing defined here (i.e.boolean
updateURIs
(Map<URI, URI> replacements) Update the specified URIs.Methods inherited from class qupath.opencv.dnn.AbstractDnnModel
batchPredict, predict, predict
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface qupath.lib.io.UriResource
getUris, updateUris
-
Constructor Details
-
OpenCVDnn
public OpenCVDnn()
-
-
Method Details
-
buildNet
Build the OpenCVNet
. This is a lower-level function thanbuildModel()
, which provides more options to query the network architecture but does not incorporate any preprocessing steps.- Returns:
-
buildModel
Build a model, specifying theOpenCVDnn.ModelType
.- Type Parameters:
T
-- Parameters:
type
-- Returns:
- See Also:
-
buildModel
Build a model. The return type is determined by theOpenCVDnn.ModelType
.- Type Parameters:
T
-- Returns:
- See Also:
-
initializeModel
Initialize the model with the same preprocessing defined here (i.e. input size, mean, scale, crop, swapRB).- Parameters:
model
-
-
getName
Get a user-readable name for this model, or null if no name is specified.- Returns:
-
getScale
Get scale factors to be applied to preprocess input.- Returns:
- the scale value if specified, or null if default scaling should be used
- See Also:
-
getModelType
Get the type of the model that would be built withbuildModel()
.- Returns:
-
getMean
Get means which should be subtracted for preprocessing.- Returns:
- the mean value if specified, or null if OpenCV's default should be used (likely to be zero)
- See Also:
-
getModelUri
Get the path to the model.- Returns:
-
getConfigUri
Get the path to the model configuration, if required.- Returns:
-
getFramework
Get the framework used to create the model.- Returns:
-
builder
Create a new builder.- Parameters:
pathModel
-- Returns:
-
getURIs
Description copied from interface:UriResource
Get all the URIs required for this resource. This is often an empty or singleton list.- Specified by:
getURIs
in interfaceUriResource
- Returns:
- the required URIs
- Throws:
IOException
-
updateURIs
Description copied from interface:UriResource
Update the specified URIs.Warning! This should be used sparingly, particularly for objects that are otherwise immutable. It is intended only for correcting paths that have become invalid (e.g. because of files being relocated or transferred between computers) before first use of the object. It should not be used to manipulate an object after construction. Indeed, some implementations may throw an
UnsupportedOperationException
if called too late.- Specified by:
updateURIs
in interfaceUriResource
- Parameters:
replacements
- replacement map, where the key gives the current URI and the value gives its replacement.- Returns:
- true if URIs were changed, false otherwise
- Throws:
IOException
-
getBlobFunction
Description copied from class:AbstractDnnModel
Get the function that can convert one or more OpenCV Mats into a blob supported by the prediction function for the first (or only) input.- Specified by:
getBlobFunction
in classAbstractDnnModel<Mat>
- Returns:
-
getBlobFunction
Description copied from class:AbstractDnnModel
Get the function that can convert one or more OpenCV Mats into a blob supported by the prediction function for a specified input layer.- Specified by:
getBlobFunction
in classAbstractDnnModel<Mat>
- Parameters:
name
-- Returns:
-
getPredictionFunction
Description copied from class:AbstractDnnModel
Get the prediction function that can apply a prediction with one or more blobs as input.- Specified by:
getPredictionFunction
in classAbstractDnnModel<Mat>
- Returns:
-
close
Description copied from interface:DnnModel
Close this model if it will not be needed again. Subclasses that require cleanup may override this. The default implementation does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDnnModel
- Throws:
Exception
-