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.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface qupath.opencv.dnn.DnnModel
DEFAULT_INPUT_NAME, DEFAULT_OUTPUT_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenCVDnn.BuilderCreate a new builder.<T extends Model>
TBuild a model.<T extends Model>
TBuild a model, specifying theOpenCVDnn.ModelType.buildNet()Build the OpenCVNet.voidclose()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.voidinitializeModel(Model model) Initialize the model with the same preprocessing defined here (i.e.booleanupdateURIs(Map<URI, URI> replacements) Update the specified URIs.Methods inherited from class qupath.opencv.dnn.AbstractDnnModel
batchPredict, predict, predictMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:UriResourceGet all the URIs required for this resource. This is often an empty or singleton list.- Specified by:
getURIsin interfaceUriResource- Returns:
- the required URIs
- Throws:
IOException
-
updateURIs
Description copied from interface:UriResourceUpdate 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
UnsupportedOperationExceptionif called too late.- Specified by:
updateURIsin 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:AbstractDnnModelGet 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:
getBlobFunctionin classAbstractDnnModel<Mat>- Returns:
-
getBlobFunction
Description copied from class:AbstractDnnModelGet 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:
getBlobFunctionin classAbstractDnnModel<Mat>- Parameters:
name-- Returns:
-
getPredictionFunction
Description copied from class:AbstractDnnModelGet the prediction function that can apply a prediction with one or more blobs as input.- Specified by:
getPredictionFunctionin classAbstractDnnModel<Mat>- Returns:
-
close
Description copied from interface:DnnModelClose this model if it will not be needed again. Subclasses that require cleanup may override this. The default implementation does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDnnModel- Throws:
Exception
-