Dnn
Objective-C
@interface Dnn : NSObject
Swift
class Dnn : NSObject
The Dnn module
Member classes: DictValue, Layer, Net, Model, ClassificationModel, KeypointsModel, SegmentationModel, DetectionModel
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p image values.
swapRBflag which indicates that swap first and last channels in 3-channel image is necessary.
cropflag which indicates whether image will be cropped after resize or not
ddepthDepth of output blob. Choose CV_32F or CV_8U. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p image values.
swapRBflag which indicates that swap first and last channels in 3-channel image is necessary.
cropflag which indicates whether image will be cropped after resize or not if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p image values.
swapRBflag which indicates that swap first and last channels in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p image values. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels).
sizespatial size for output image to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p image values. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels). to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p image values. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imageinput image (with 1-, 3- or 4-channels). to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p images values.
swapRBflag which indicates that swap first and last channels in 3-channel image is necessary.
cropflag which indicates whether image will be cropped after resize or not
ddepthDepth of output blob. Choose CV_32F or CV_8U. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p images values.
swapRBflag which indicates that swap first and last channels in 3-channel image is necessary.
cropflag which indicates whether image will be cropped after resize or not if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p images values.
swapRBflag which indicates that swap first and last channels in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels).
sizespatial size for output image
meanscalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p images values. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels).
sizespatial size for output image to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p images values. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels). to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
scalefactormultiplier for @p images values. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
Parameters
imagesinput images (all with 1-, 3- or 4-channels). to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. in 3-channel image is necessary. if @p crop is true, input image is resized so one side after resize is equal to corresponding dimension in @p size and another one is equal or larger. Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
Return Value
4-dimensional Mat with NCHW dimensions order.
-
Loads blob which was serialized as torch.Tensor object of Torch7 framework.
Warning
This function has the same limitations as readNetFromTorch(). -
Read deep learning network represented in one of the supported formats. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Declaration
Objective-C
+ (nonnull Net *)readNet:(nonnull NSString *)framework bufferModel:(nonnull ByteVector *)bufferModel bufferConfig:(nonnull ByteVector *)bufferConfig;Swift
class func readNet(framework: String, bufferModel: ByteVector, bufferConfig: ByteVector) -> NetParameters
frameworkName of origin framework.
bufferModelA buffer with a content of binary file with weights
bufferConfigA buffer with a content of text file contains network configuration.
Return Value
Net object.
-
Read deep learning network represented in one of the supported formats. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Declaration
Objective-C
+ (nonnull Net *)readNet:(nonnull NSString *)framework bufferModel:(nonnull ByteVector *)bufferModel;Swift
class func readNet(framework: String, bufferModel: ByteVector) -> NetParameters
frameworkName of origin framework.
bufferModelA buffer with a content of binary file with weights
Return Value
Net object.
-
Read deep learning network represented in one of the supported formats.
*.caffemodel(Caffe, http://caffe.berkeleyvision.org/)*.pb(TensorFlow, https://www.tensorflow.org/)*.t7|*.net(Torch, http://torch.ch/)*.weights(Darknet, https://pjreddie.com/darknet/)*.bin(DLDT, https://software.intel.com/openvino-toolkit)*.onnx(ONNX, https://onnx.ai/)*.prototxt(Caffe, http://caffe.berkeleyvision.org/)*.pbtxt(TensorFlow, https://www.tensorflow.org/)*.cfg(Darknet, https://pjreddie.com/darknet/)*.xml(DLDT, https://software.intel.com/openvino-toolkit)
This function automatically detects an origin framework of trained model and calls an appropriate function such REF: readNetFromCaffe, REF: readNetFromTensorflow, REF: readNetFromTorch or REF: readNetFromDarknet. An order of @p model and @p config arguments does not matter.
Declaration
Objective-C
+ (nonnull Net *)readNet:(nonnull NSString *)model config:(nonnull NSString *)config framework:(nonnull NSString *)framework;Swift
class func readNet(model: String, config: String, framework: String) -> NetParameters
modelBinary file contains trained weights. The following file extensions are expected for models from different frameworks:
configText file contains network configuration. It could be a file with the following extensions:
frameworkExplicit framework name tag to determine a format.
Return Value
Net object.
-
Read deep learning network represented in one of the supported formats.
*.caffemodel(Caffe, http://caffe.berkeleyvision.org/)*.pb(TensorFlow, https://www.tensorflow.org/)*.t7|*.net(Torch, http://torch.ch/)*.weights(Darknet, https://pjreddie.com/darknet/)*.bin(DLDT, https://software.intel.com/openvino-toolkit)*.onnx(ONNX, https://onnx.ai/)*.prototxt(Caffe, http://caffe.berkeleyvision.org/)*.pbtxt(TensorFlow, https://www.tensorflow.org/)*.cfg(Darknet, https://pjreddie.com/darknet/)*.xml(DLDT, https://software.intel.com/openvino-toolkit)
This function automatically detects an origin framework of trained model and calls an appropriate function such REF: readNetFromCaffe, REF: readNetFromTensorflow, REF: readNetFromTorch or REF: readNetFromDarknet. An order of @p model and @p config arguments does not matter.
Declaration
Objective-C
+ (nonnull Net *)readNet:(nonnull NSString *)model config:(nonnull NSString *)config;Swift
class func readNet(model: String, config: String) -> NetParameters
modelBinary file contains trained weights. The following file extensions are expected for models from different frameworks:
configText file contains network configuration. It could be a file with the following extensions:
Return Value
Net object.
-
Read deep learning network represented in one of the supported formats.
*.caffemodel(Caffe, http://caffe.berkeleyvision.org/)*.pb(TensorFlow, https://www.tensorflow.org/)*.t7|*.net(Torch, http://torch.ch/)*.weights(Darknet, https://pjreddie.com/darknet/)*.bin(DLDT, https://software.intel.com/openvino-toolkit)*.onnx(ONNX, https://onnx.ai/) file with the following extensions:*.prototxt(Caffe, http://caffe.berkeleyvision.org/)*.pbtxt(TensorFlow, https://www.tensorflow.org/)*.cfg(Darknet, https://pjreddie.com/darknet/)*.xml(DLDT, https://software.intel.com/openvino-toolkit)
This function automatically detects an origin framework of trained model and calls an appropriate function such REF: readNetFromCaffe, REF: readNetFromTensorflow, REF: readNetFromTorch or REF: readNetFromDarknet. An order of @p model and @p config arguments does not matter.
Declaration
Objective-C
+ (nonnull Net *)readNet:(nonnull NSString *)model;Swift
class func readNet(model: String) -> NetParameters
modelBinary file contains trained weights. The following file extensions are expected for models from different frameworks:
Return Value
Net object.
-
Reads a network model stored in Caffe framework’s format.
Declaration
Objective-C
+ (nonnull Net *)readNetFromCaffeFile:(nonnull NSString *)prototxt caffeModel:(nonnull NSString *)caffeModel;Swift
class func readNetFromCaffe(prototxt: String, caffeModel: String) -> NetParameters
prototxtpath to the .prototxt file with text description of the network architecture.
caffeModelpath to the .caffemodel file with learned network.
Return Value
Net object.
-
Reads a network model stored in Caffe framework’s format.
Declaration
Objective-C
+ (nonnull Net *)readNetFromCaffeFile:(nonnull NSString *)prototxt;Swift
class func readNetFromCaffe(prototxt: String) -> NetParameters
prototxtpath to the .prototxt file with text description of the network architecture.
Return Value
Net object.
-
Reads a network model stored in Caffe model in memory.
Declaration
Objective-C
+ (nonnull Net *)readNetFromCaffeBuffer:(nonnull ByteVector *)bufferProto bufferModel:(nonnull ByteVector *)bufferModel;Swift
class func readNetFromCaffe(bufferProto: ByteVector, bufferModel: ByteVector) -> NetParameters
bufferProtobuffer containing the content of the .prototxt file
bufferModelbuffer containing the content of the .caffemodel file
Return Value
Net object.
-
Reads a network model stored in Caffe model in memory.
Declaration
Objective-C
+ (nonnull Net *)readNetFromCaffeBuffer:(nonnull ByteVector *)bufferProto;Swift
class func readNetFromCaffe(bufferProto: ByteVector) -> NetParameters
bufferProtobuffer containing the content of the .prototxt file
Return Value
Net object.
-
Reads a network model stored in Darknet model files.
Declaration
Objective-C
+ (nonnull Net *)readNetFromDarknetFile:(nonnull NSString *)cfgFile darknetModel:(nonnull NSString *)darknetModel;Swift
class func readNetFromDarknet(cfgFile: String, darknetModel: String) -> NetParameters
cfgFilepath to the .cfg file with text description of the network architecture.
darknetModelpath to the .weights file with learned network.
Return Value
Net object.
-
Reads a network model stored in Darknet model files.
Declaration
Objective-C
+ (nonnull Net *)readNetFromDarknetFile:(nonnull NSString *)cfgFile;Swift
class func readNetFromDarknet(cfgFile: String) -> NetParameters
cfgFilepath to the .cfg file with text description of the network architecture.
Return Value
Net object.
-
Reads a network model stored in Darknet model files.
Declaration
Objective-C
+ (nonnull Net *)readNetFromDarknetBuffer:(nonnull ByteVector *)bufferCfg bufferModel:(nonnull ByteVector *)bufferModel;Swift
class func readNetFromDarknet(bufferCfg: ByteVector, bufferModel: ByteVector) -> NetParameters
bufferCfgA buffer contains a content of .cfg file with text description of the network architecture.
bufferModelA buffer contains a content of .weights file with learned network.
Return Value
Net object.
-
Reads a network model stored in Darknet model files.
Declaration
Objective-C
+ (nonnull Net *)readNetFromDarknetBuffer:(nonnull ByteVector *)bufferCfg;Swift
class func readNetFromDarknet(bufferCfg: ByteVector) -> NetParameters
bufferCfgA buffer contains a content of .cfg file with text description of the network architecture.
Return Value
Net object.
-
Load a network from Intel’s Model Optimizer intermediate representation.
Declaration
Objective-C
+ (nonnull Net *)readNetFromModelOptimizer:(nonnull NSString *)xml bin:(nonnull NSString *)bin;Swift
class func readNetFromModelOptimizer(xml: String, bin: String) -> NetParameters
xmlXML configuration file with network’s topology.
binBinary file with trained weights.
Return Value
Net object. Networks imported from Intel’s Model Optimizer are launched in Intel’s Inference Engine backend.
-
Load a network from Intel’s Model Optimizer intermediate representation.
Declaration
Objective-C
+ (nonnull Net *)readNetFromModelOptimizer: (nonnull ByteVector *)bufferModelConfig bufferWeights:(nonnull ByteVector *)bufferWeights;Swift
class func readNetFromModelOptimizer(bufferModelConfig: ByteVector, bufferWeights: ByteVector) -> NetParameters
bufferModelConfigBuffer contains XML configuration with network’s topology.
bufferWeightsBuffer contains binary data with trained weights.
Return Value
Net object. Networks imported from Intel’s Model Optimizer are launched in Intel’s Inference Engine backend.
-
Reads a network model ONNX.
Declaration
Objective-C
+ (nonnull Net *)readNetFromONNXFile:(nonnull NSString *)onnxFile;Swift
class func readNetFromONNX(onnxFile: String) -> NetParameters
onnxFilepath to the .onnx file with text description of the network architecture.
Return Value
Network object that ready to do forward, throw an exception in failure cases.
-
Reads a network model from ONNX in-memory buffer.
Declaration
Objective-C
+ (nonnull Net *)readNetFromONNXBuffer:(nonnull ByteVector *)buffer;Swift
class func readNetFromONNX(buffer: ByteVector) -> NetParameters
bufferin-memory buffer that stores the ONNX model bytes.
Return Value
Network object that ready to do forward, throw an exception in failure cases.
-
Reads a network model stored in TensorFlow framework’s format.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTensorflowFile:(nonnull NSString *)model config:(nonnull NSString *)config;Swift
class func readNetFromTensorflow(model: String, config: String) -> NetParameters
modelpath to the .pb file with binary protobuf description of the network architecture
configpath to the .pbtxt file that contains text graph definition in protobuf format. Resulting Net object is built by text graph using weights from a binary one that let us make it more flexible.
Return Value
Net object.
-
Reads a network model stored in TensorFlow framework’s format.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTensorflowFile:(nonnull NSString *)model;Swift
class func readNetFromTensorflow(model: String) -> NetParameters
modelpath to the .pb file with binary protobuf description of the network architecture Resulting Net object is built by text graph using weights from a binary one that let us make it more flexible.
Return Value
Net object.
-
Reads a network model stored in TensorFlow framework’s format.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTensorflowBuffer:(nonnull ByteVector *)bufferModel bufferConfig:(nonnull ByteVector *)bufferConfig;Swift
class func readNetFromTensorflow(bufferModel: ByteVector, bufferConfig: ByteVector) -> NetParameters
bufferModelbuffer containing the content of the pb file
bufferConfigbuffer containing the content of the pbtxt file
Return Value
Net object.
-
Reads a network model stored in TensorFlow framework’s format.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTensorflowBuffer:(nonnull ByteVector *)bufferModel;Swift
class func readNetFromTensorflow(bufferModel: ByteVector) -> NetParameters
bufferModelbuffer containing the content of the pb file
Return Value
Net object.
-
Reads a network model stored in Torch7 framework’s format.
Note
Ascii mode of Torch serializer is more preferable, because binary mode extensively use
longtype of C language, which has various bit-length on different systems.The loading file must contain serialized nn.Module object with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors.
List of supported layers (i.e. object instances derived from Torch nn.Module class):
- nn.Sequential
- nn.Parallel
- nn.Concat
- nn.Linear
- nn.SpatialConvolution
- nn.SpatialMaxPooling, nn.SpatialAveragePooling
- nn.ReLU, nn.TanH, nn.Sigmoid
- nn.Reshape
- nn.SoftMax, nn.LogSoftMax
Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTorch:(nonnull NSString *)model isBinary:(BOOL)isBinary evaluate:(BOOL)evaluate;Swift
class func readNetFromTorch(model: String, isBinary: Bool, evaluate: Bool) -> NetParameters
modelpath to the file, dumped from Torch by using torch.save() function.
isBinaryspecifies whether the network was serialized in ascii mode or binary.
evaluatespecifies testing phase of network. If true, it’s similar to evaluate() method in Torch.
Return Value
Net object.
-
Reads a network model stored in Torch7 framework’s format.
Note
Ascii mode of Torch serializer is more preferable, because binary mode extensively use
longtype of C language, which has various bit-length on different systems.The loading file must contain serialized nn.Module object with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors.
List of supported layers (i.e. object instances derived from Torch nn.Module class):
- nn.Sequential
- nn.Parallel
- nn.Concat
- nn.Linear
- nn.SpatialConvolution
- nn.SpatialMaxPooling, nn.SpatialAveragePooling
- nn.ReLU, nn.TanH, nn.Sigmoid
- nn.Reshape
- nn.SoftMax, nn.LogSoftMax
Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTorch:(nonnull NSString *)model isBinary:(BOOL)isBinary;Swift
class func readNetFromTorch(model: String, isBinary: Bool) -> NetParameters
modelpath to the file, dumped from Torch by using torch.save() function.
isBinaryspecifies whether the network was serialized in ascii mode or binary.
Return Value
Net object.
-
Reads a network model stored in Torch7 framework’s format.
Note
Ascii mode of Torch serializer is more preferable, because binary mode extensively use
longtype of C language, which has various bit-length on different systems.The loading file must contain serialized nn.Module object with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors.
List of supported layers (i.e. object instances derived from Torch nn.Module class):
- nn.Sequential
- nn.Parallel
- nn.Concat
- nn.Linear
- nn.SpatialConvolution
- nn.SpatialMaxPooling, nn.SpatialAveragePooling
- nn.ReLU, nn.TanH, nn.Sigmoid
- nn.Reshape
- nn.SoftMax, nn.LogSoftMax
Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.
Declaration
Objective-C
+ (nonnull Net *)readNetFromTorch:(nonnull NSString *)model;Swift
class func readNetFromTorch(model: String) -> NetParameters
modelpath to the file, dumped from Torch by using torch.save() function.
Return Value
Net object.
-
Returns Inference Engine internal backend API.
See values of
CV_DNN_BACKEND_INFERENCE_ENGINE_*macros.Default value is controlled through
OPENCV_DNN_BACKEND_INFERENCE_ENGINE_TYPEruntime parameter (environment variable).Declaration
Objective-C
+ (nonnull NSString *)getInferenceEngineBackendType;Swift
class func getInferenceEngineBackendType() -> String -
Returns Inference Engine VPU type.
See values of
CV_DNN_INFERENCE_ENGINE_VPU_TYPE_*macros.Declaration
Objective-C
+ (nonnull NSString *)getInferenceEngineVPUType;Swift
class func getInferenceEngineVPUType() -> String -
Specify Inference Engine internal backend API.
See values of
CV_DNN_BACKEND_INFERENCE_ENGINE_*macros.Declaration
Objective-C
+ (nonnull NSString *)setInferenceEngineBackendType: (nonnull NSString *)newBackendType;Swift
class func setInferenceEngineBackendType(newBackendType: String) -> StringReturn Value
previous value of internal backend API
-
Performs non maximum suppression given boxes and corresponding scores.
Declaration
Objective-C
+ (void)NMSBoxes:(nonnull NSArray<Rect2d *> *)bboxes scores:(nonnull FloatVector *)scores score_threshold:(float)score_threshold nms_threshold:(float)nms_threshold indices:(nonnull IntVector *)indices eta:(float)eta top_k:(int)top_k;Swift
class func NMSBoxes(bboxes: [Rect2d], scores: FloatVector, score_threshold: Float, nms_threshold: Float, indices: IntVector, eta: Float, top_k: Int32)Parameters
bboxesa set of bounding boxes to apply NMS.
scoresa set of corresponding confidences.
score_thresholda threshold used to filter boxes by score.
nms_thresholda threshold used in non maximum suppression.
indicesthe kept indices of bboxes after NMS.
etaa coefficient in adaptive threshold formula:
nms\_threshold_{i+1}=eta\cdot nms\_threshold_i. -
Performs non maximum suppression given boxes and corresponding scores.
Declaration
Objective-C
+ (void)NMSBoxes:(nonnull NSArray<Rect2d *> *)bboxes scores:(nonnull FloatVector *)scores score_threshold:(float)score_threshold nms_threshold:(float)nms_threshold indices:(nonnull IntVector *)indices eta:(float)eta;Swift
class func NMSBoxes(bboxes: [Rect2d], scores: FloatVector, score_threshold: Float, nms_threshold: Float, indices: IntVector, eta: Float)Parameters
bboxesa set of bounding boxes to apply NMS.
scoresa set of corresponding confidences.
score_thresholda threshold used to filter boxes by score.
nms_thresholda threshold used in non maximum suppression.
indicesthe kept indices of bboxes after NMS.
etaa coefficient in adaptive threshold formula:
nms\_threshold_{i+1}=eta\cdot nms\_threshold_i. -
Performs non maximum suppression given boxes and corresponding scores.
Declaration
Objective-C
+ (void)NMSBoxes:(nonnull NSArray<Rect2d *> *)bboxes scores:(nonnull FloatVector *)scores score_threshold:(float)score_threshold nms_threshold:(float)nms_threshold indices:(nonnull IntVector *)indices;Swift
class func NMSBoxes(bboxes: [Rect2d], scores: FloatVector, score_threshold: Float, nms_threshold: Float, indices: IntVector)Parameters
bboxesa set of bounding boxes to apply NMS.
scoresa set of corresponding confidences.
score_thresholda threshold used to filter boxes by score.
nms_thresholda threshold used in non maximum suppression.
indicesthe kept indices of bboxes after NMS.
-
Declaration
Objective-C
+ (void)NMSBoxesRotated:(NSArray<RotatedRect*>*)bboxes scores:(FloatVector*)scores score_threshold:(float)score_threshold nms_threshold:(float)nms_threshold indices:(IntVector*)indices eta:(float)eta top_k:(int)top_k NS_SWIFT_NAME(NMSBoxes(bboxes:scores:score_threshold:nms_threshold:indices:eta:top_k:));Swift
class func NMSBoxes(bboxes: [RotatedRect], scores: FloatVector, score_threshold: Float, nms_threshold: Float, indices: IntVector, eta: Float, top_k: Int32) -
Declaration
Objective-C
+ (void)NMSBoxesRotated:(NSArray<RotatedRect*>*)bboxes scores:(FloatVector*)scores score_threshold:(float)score_threshold nms_threshold:(float)nms_threshold indices:(IntVector*)indices eta:(float)eta NS_SWIFT_NAME(NMSBoxes(bboxes:scores:score_threshold:nms_threshold:indices:eta:));Swift
class func NMSBoxes(bboxes: [RotatedRect], scores: FloatVector, score_threshold: Float, nms_threshold: Float, indices: IntVector, eta: Float) -
Declaration
Objective-C
+ (void)NMSBoxesRotated:(NSArray<RotatedRect*>*)bboxes scores:(FloatVector*)scores score_threshold:(float)score_threshold nms_threshold:(float)nms_threshold indices:(IntVector*)indices NS_SWIFT_NAME(NMSBoxes(bboxes:scores:score_threshold:nms_threshold:indices:));Swift
class func NMSBoxes(bboxes: [RotatedRect], scores: FloatVector, score_threshold: Float, nms_threshold: Float, indices: IntVector) -
Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std::vectorcv::Mat).
Declaration
Objective-C
+ (void)imagesFromBlob:(nonnull Mat *)blob_ images_:(nonnull NSMutableArray<Mat *> *)images_;Swift
class func imagesFromBlob(blob_: Mat, images_: NSMutableArray)Parameters
blob_4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from which you would like to extract the images.
images_array of 2D Mat containing the images extracted from the blob in floating point precision (CV_32F). They are non normalized neither mean added. The number of returned images equals the first dimension of the blob (batch size). Every image has a number of channels equals to the second dimension of the blob (depth).
-
Release a Myriad device (binded by OpenCV).
Single Myriad device cannot be shared across multiple processes which uses Inference Engine’s Myriad plugin.
Declaration
Objective-C
+ (void)resetMyriadDevice;Swift
class func resetMyriadDevice() -
Convert all weights of Caffe network to half precision floating point.
Note
Shrinked model has no origin float32 weights so it can’t be used in origin Caffe framework anymore. However the structure of data is taken from NVidia’s Caffe fork: https://github.com/NVIDIA/caffe. So the resulting model may be used there.
Declaration
Objective-C
+ (void)shrinkCaffeModel:(nonnull NSString *)src dst:(nonnull NSString *)dst layersTypes:(nonnull NSArray<NSString *> *)layersTypes;Swift
class func shrinkCaffeModel(src: String, dst: String, layersTypes: [String])Parameters
srcPath to origin model from Caffe framework contains single precision floating point weights (usually has
.caffemodelextension).dstPath to destination model with updated weights.
layersTypesSet of layers types which parameters will be converted. By default, converts only Convolutional and Fully-Connected layers’ weights.
-
Convert all weights of Caffe network to half precision floating point.
Note
Shrinked model has no origin float32 weights so it can’t be used in origin Caffe framework anymore. However the structure of data is taken from NVidia’s Caffe fork: https://github.com/NVIDIA/caffe. So the resulting model may be used there.
Declaration
Objective-C
+ (void)shrinkCaffeModel:(nonnull NSString *)src dst:(nonnull NSString *)dst;Swift
class func shrinkCaffeModel(src: String, dst: String)Parameters
srcPath to origin model from Caffe framework contains single precision floating point weights (usually has
.caffemodelextension).dstPath to destination model with updated weights. By default, converts only Convolutional and Fully-Connected layers’ weights.
-
Create a text representation for a binary network stored in protocol buffer format.
Note
To reduce output file size, trained weights are not included.
Declaration
Objective-C
+ (void)writeTextGraph:(nonnull NSString *)model output:(nonnull NSString *)output;Swift
class func writeTextGraph(model: String, output: String)Parameters
modelA path to binary network.
outputA path to output text file to be created.
View on GitHub
Dnn Class Reference