OpenCV  4.9.0
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

Public Member Functions

 ClassificationModel ()
 
 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)
 
bool getEnableSoftmaxPostProcessing () const
 Get enable/disable softmax post processing option. More...
 
ClassificationModelsetEnableSoftmaxPostProcessing (bool enable)
 Set enable/disable softmax post processing option. More...
 
- Public Member Functions inherited from cv::dnn::Model
 Model ()
 
 Model (const Model &)=default
 
 Model (Model &&)=default
 
 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...
 
ModelenableWinograd (bool useWinograd)
 
Impl * getImpl () const
 
Impl & getImplRef () const
 
NetgetNetwork_ () const
 
NetgetNetwork_ ()
 
 operator Net & () const
 
Modeloperator= (const Model &)=default
 
Modeloperator= (Model &&)=default
 
void predict (InputArray frame, OutputArrayOfArrays outs) const
 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 (const Scalar &scale)
 Set scalefactor value for frame. More...
 
ModelsetInputSize (const Size &size)
 Set input size for frame. More...
 
ModelsetInputSize (int width, int height)
 
ModelsetInputSwapRB (bool swapRB)
 Set flag swapRB for frame. More...
 
ModelsetPreferableBackend (dnn::Backend backendId)
 
ModelsetPreferableTarget (dnn::Target targetId)
 

Additional Inherited Members

- 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/3]

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

◆ ClassificationModel() [2/3]

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

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() [3/3]

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

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:
cv.dnn.ClassificationModel.classify(frame) -> classId, conf

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:
cv.dnn.ClassificationModel.classify(frame) -> classId, conf

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

◆ getEnableSoftmaxPostProcessing()

bool cv::dnn::ClassificationModel::getEnableSoftmaxPostProcessing ( ) const
Python:
cv.dnn.ClassificationModel.getEnableSoftmaxPostProcessing() -> retval

Get enable/disable softmax post processing option.

This option defaults to false, softmax post processing is not applied within the classify() function.

◆ setEnableSoftmaxPostProcessing()

ClassificationModel& cv::dnn::ClassificationModel::setEnableSoftmaxPostProcessing ( bool  enable)
Python:
cv.dnn.ClassificationModel.setEnableSoftmaxPostProcessing(enable) -> retval

Set enable/disable softmax post processing option.

If this option is true, softmax is applied after forward inference within the classify() function to convert the confidences range to [0.0-1.0]. This function allows you to toggle this behavior. Please turn true when not contain softmax layer in model.

Parameters
[in]enableSet enable softmax post processing within the classify() function.

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