OpenCV  4.1.2
Open Source Computer Vision
Public Member Functions | List of all members
cv::dnn::ClassificationModel Class Reference

This class represents high-level API for classification models. More...

#include <opencv2/dnn/dnn.hpp>

Inheritance diagram for cv::dnn::ClassificationModel:
cv::dnn::Model cv::dnn::Net

Public Member Functions

 ClassificationModel (const String &model, const String &config="")
 Create classification model from network represented in one of the supported formats. An order of model and config arguments does not matter. More...
 
 ClassificationModel (const Net &network)
 Create model from deep learning network. More...
 
std::pair< int, float > classify (InputArray frame)
 Given the input frame, create input blob, run net and return top-1 prediction. More...
 
void classify (InputArray frame, int &classId, float &conf)
 
- Public Member Functions inherited from cv::dnn::Model
 Model ()
 Default constructor. More...
 
 Model (const String &model, const String &config="")
 Create model from deep learning network represented in one of the supported formats. An order of model and config arguments does not matter. More...
 
 Model (const Net &network)
 Create model from deep learning network. More...
 
void predict (InputArray frame, OutputArrayOfArrays outs)
 Given the input frame, create input blob, run net and return the output blobs. More...
 
ModelsetInputCrop (bool crop)
 Set flag crop for frame. More...
 
ModelsetInputMean (const Scalar &mean)
 Set mean value for frame. More...
 
void setInputParams (double scale=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false)
 Set preprocessing parameters for frame. More...
 
ModelsetInputScale (double scale)
 Set scalefactor value for frame. More...
 
ModelsetInputSize (const Size &size)
 Set input size for frame. More...
 
ModelsetInputSize (int width, int height)
 Set input size for frame. More...
 
ModelsetInputSwapRB (bool swapRB)
 Set flag swapRB for frame. More...
 
- Public Member Functions inherited from cv::dnn::Net
 Net ()
 Default constructor. More...
 
 ~Net ()
 Destructor frees the net only if there aren't references to the net anymore. More...
 
int addLayer (const String &name, const String &type, LayerParams &params)
 Adds new layer to the net. More...
 
int addLayerToPrev (const String &name, const String &type, LayerParams &params)
 Adds new layer and connects its first input to the first output of previously added layer. More...
 
void connect (String outPin, String inpPin)
 Connects output of the first layer to input of the second layer. More...
 
void connect (int outLayerId, int outNum, int inpLayerId, int inpNum)
 Connects #outNum output of the first layer to #inNum input of the second layer. More...
 
String dump ()
 Dump net to String. More...
 
void dumpToFile (const String &path)
 Dump net structure, hyperparameters, backend, target and fusion to dot file. More...
 
bool empty () const
 
void enableFusion (bool fusion)
 Enables or disables layer fusion in the network. More...
 
Mat forward (const String &outputName=String())
 Runs forward pass to compute output of layer with name outputName. More...
 
void forward (OutputArrayOfArrays outputBlobs, const String &outputName=String())
 Runs forward pass to compute output of layer with name outputName. More...
 
void forward (OutputArrayOfArrays outputBlobs, const std::vector< String > &outBlobNames)
 Runs forward pass to compute outputs of layers listed in outBlobNames. More...
 
void forward (std::vector< std::vector< Mat > > &outputBlobs, const std::vector< String > &outBlobNames)
 Runs forward pass to compute outputs of layers listed in outBlobNames. More...
 
AsyncArray forwardAsync (const String &outputName=String())
 Runs forward pass to compute output of layer with name outputName. More...
 
int64 getFLOPS (const std::vector< MatShape > &netInputShapes) const
 Computes FLOP for whole loaded model with specified input shapes. More...
 
int64 getFLOPS (const MatShape &netInputShape) const
 
int64 getFLOPS (const int layerId, const std::vector< MatShape > &netInputShapes) const
 
int64 getFLOPS (const int layerId, const MatShape &netInputShape) const
 
Ptr< LayergetLayer (LayerId layerId)
 Returns pointer to layer with specified id or name which the network use. More...
 
int getLayerId (const String &layer)
 Converts string name of the layer to the integer identifier. More...
 
std::vector< Ptr< Layer > > getLayerInputs (LayerId layerId)
 Returns pointers to input layers of specific layer. More...
 
std::vector< StringgetLayerNames () const
 
int getLayersCount (const String &layerType) const
 Returns count of layers of specified type. More...
 
void getLayerShapes (const MatShape &netInputShape, const int layerId, std::vector< MatShape > &inLayerShapes, std::vector< MatShape > &outLayerShapes) const
 Returns input and output shapes for layer with specified id in loaded model; preliminary inferencing isn't necessary. More...
 
void getLayerShapes (const std::vector< MatShape > &netInputShapes, const int layerId, std::vector< MatShape > &inLayerShapes, std::vector< MatShape > &outLayerShapes) const
 
void getLayersShapes (const std::vector< MatShape > &netInputShapes, std::vector< int > &layersIds, std::vector< std::vector< MatShape > > &inLayersShapes, std::vector< std::vector< MatShape > > &outLayersShapes) const
 Returns input and output shapes for all layers in loaded model; preliminary inferencing isn't necessary. More...
 
void getLayersShapes (const MatShape &netInputShape, std::vector< int > &layersIds, std::vector< std::vector< MatShape > > &inLayersShapes, std::vector< std::vector< MatShape > > &outLayersShapes) const
 
void getLayerTypes (std::vector< String > &layersTypes) const
 Returns list of types for layer used in model. More...
 
void getMemoryConsumption (const std::vector< MatShape > &netInputShapes, size_t &weights, size_t &blobs) const
 Computes bytes number which are required to store all weights and intermediate blobs for model. More...
 
void getMemoryConsumption (const MatShape &netInputShape, size_t &weights, size_t &blobs) const
 
void getMemoryConsumption (const int layerId, const std::vector< MatShape > &netInputShapes, size_t &weights, size_t &blobs) const
 
void getMemoryConsumption (const int layerId, const MatShape &netInputShape, size_t &weights, size_t &blobs) const
 
void getMemoryConsumption (const std::vector< MatShape > &netInputShapes, std::vector< int > &layerIds, std::vector< size_t > &weights, std::vector< size_t > &blobs) const
 Computes bytes number which are required to store all weights and intermediate blobs for each layer. More...
 
void getMemoryConsumption (const MatShape &netInputShape, std::vector< int > &layerIds, std::vector< size_t > &weights, std::vector< size_t > &blobs) const
 
Mat getParam (LayerId layer, int numParam=0)
 Returns parameter blob of the layer. More...
 
int64 getPerfProfile (std::vector< double > &timings)
 Returns overall time for inference and timings (in ticks) for layers. Indexes in returned vector correspond to layers ids. Some layers can be fused with others, in this case zero ticks count will be return for that skipped layers. More...
 
std::vector< int > getUnconnectedOutLayers () const
 Returns indexes of layers with unconnected outputs. More...
 
std::vector< StringgetUnconnectedOutLayersNames () const
 Returns names of layers with unconnected outputs. More...
 
void setHalideScheduler (const String &scheduler)
 Compile Halide layers. More...
 
void setInput (InputArray blob, const String &name="", double scalefactor=1.0, const Scalar &mean=Scalar())
 Sets the new input value for the network. More...
 
void setInputsNames (const std::vector< String > &inputBlobNames)
 Sets outputs names of the network input pseudo layer. More...
 
void setParam (LayerId layer, int numParam, const Mat &blob)
 Sets the new value for the learned param of the layer. More...
 
void setPreferableBackend (int backendId)
 Ask network to use specific computation backend where it supported. More...
 
void setPreferableTarget (int targetId)
 Ask network to make computations on specific target device. More...
 

Additional Inherited Members

- Public Types inherited from cv::dnn::Net
typedef DictValue LayerId
 Container for strings and integers. More...
 
- Static Public Member Functions inherited from cv::dnn::Net
static Net readFromModelOptimizer (const String &xml, const String &bin)
 Create a network from Intel's Model Optimizer intermediate representation. More...
 
- Protected Attributes inherited from cv::dnn::Model
Ptr< Impl > impl
 

Detailed Description

This class represents high-level API for classification models.

ClassificationModel allows to set params for preprocessing input image. ClassificationModel creates net from file with trained weights and config, sets preprocessing input, runs forward pass and return top-1 prediction.

Constructor & Destructor Documentation

§ ClassificationModel() [1/2]

cv::dnn::ClassificationModel::ClassificationModel ( const String model,
const String config = "" 
)
Python:
<dnn_ClassificationModel object>=cv.dnn_ClassificationModel(model[, config])
<dnn_ClassificationModel object>=cv.dnn_ClassificationModel(network)

Create classification model from network represented in one of the supported formats. An order of model and config arguments does not matter.

Parameters
[in]modelBinary file contains trained weights.
[in]configText file contains network configuration.

§ ClassificationModel() [2/2]

cv::dnn::ClassificationModel::ClassificationModel ( const Net network)
Python:
<dnn_ClassificationModel object>=cv.dnn_ClassificationModel(model[, config])
<dnn_ClassificationModel object>=cv.dnn_ClassificationModel(network)

Create model from deep learning network.

Parameters
[in]networkNet object.

Member Function Documentation

§ classify() [1/2]

std::pair<int, float> cv::dnn::ClassificationModel::classify ( InputArray  frame)
Python:
classId, conf=cv.dnn_ClassificationModel.classify(frame)

Given the input frame, create input blob, run net and return top-1 prediction.

Parameters
[in]frameThe input image.

§ classify() [2/2]

void cv::dnn::ClassificationModel::classify ( InputArray  frame,
int &  classId,
float &  conf 
)
Python:
classId, conf=cv.dnn_ClassificationModel.classify(frame)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


The documentation for this class was generated from the following file: