Dnn

Objective-C

@interface Dnn : NSObject

Swift

class Dnn : NSObject

The Dnn module

Member classes: DictValue, Layer, Net, Model, ClassificationModel, KeypointsModel, SegmentationModel, DetectionModel

Member enums: Backend, Target

Methods

  • 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image
                       scalefactor:(double)scalefactor
                              size:(nonnull Size2i *)size
                              mean:(nonnull Scalar *)mean
                            swapRB:(BOOL)swapRB
                              crop:(BOOL)crop
                            ddepth:(int)ddepth;

    Swift

    class func blobFromImage(image: Mat, scalefactor: Double, size: Size2i, mean: Scalar, swapRB: Bool, crop: Bool, ddepth: Int32) -> Mat

    Parameters

    image

    input image (with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier for @p image values.

    swapRB

    flag which indicates that swap first and last channels in 3-channel image is necessary.

    crop

    flag which indicates whether image will be cropped after resize or not

    ddepth

    Depth 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image
                       scalefactor:(double)scalefactor
                              size:(nonnull Size2i *)size
                              mean:(nonnull Scalar *)mean
                            swapRB:(BOOL)swapRB
                              crop:(BOOL)crop;

    Swift

    class func blobFromImage(image: Mat, scalefactor: Double, size: Size2i, mean: Scalar, swapRB: Bool, crop: Bool) -> Mat

    Parameters

    image

    input image (with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier for @p image values.

    swapRB

    flag which indicates that swap first and last channels in 3-channel image is necessary.

    crop

    flag 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image
                       scalefactor:(double)scalefactor
                              size:(nonnull Size2i *)size
                              mean:(nonnull Scalar *)mean
                            swapRB:(BOOL)swapRB;

    Swift

    class func blobFromImage(image: Mat, scalefactor: Double, size: Size2i, mean: Scalar, swapRB: Bool) -> Mat

    Parameters

    image

    input image (with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier for @p image values.

    swapRB

    flag 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image
                       scalefactor:(double)scalefactor
                              size:(nonnull Size2i *)size
                              mean:(nonnull Scalar *)mean;

    Swift

    class func blobFromImage(image: Mat, scalefactor: Double, size: Size2i, mean: Scalar) -> Mat

    Parameters

    image

    input image (with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image
                       scalefactor:(double)scalefactor
                              size:(nonnull Size2i *)size;

    Swift

    class func blobFromImage(image: Mat, scalefactor: Double, size: Size2i) -> Mat

    Parameters

    image

    input image (with 1-, 3- or 4-channels).

    size

    spatial 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.

    scalefactor

    multiplier 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image
                       scalefactor:(double)scalefactor;

    Swift

    class func blobFromImage(image: Mat, scalefactor: Double) -> Mat

    Parameters

    image

    input 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.

    scalefactor

    multiplier 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

    Objective-C

    + (nonnull Mat *)blobFromImage:(nonnull Mat *)image;

    Swift

    class func blobFromImage(image: Mat) -> Mat

    Parameters

    image

    input 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images
                        scalefactor:(double)scalefactor
                               size:(nonnull Size2i *)size
                               mean:(nonnull Scalar *)mean
                             swapRB:(BOOL)swapRB
                               crop:(BOOL)crop
                             ddepth:(int)ddepth;

    Swift

    class func blobFromImages(images: [Mat], scalefactor: Double, size: Size2i, mean: Scalar, swapRB: Bool, crop: Bool, ddepth: Int32) -> Mat

    Parameters

    images

    input images (all with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier for @p images values.

    swapRB

    flag which indicates that swap first and last channels in 3-channel image is necessary.

    crop

    flag which indicates whether image will be cropped after resize or not

    ddepth

    Depth 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images
                        scalefactor:(double)scalefactor
                               size:(nonnull Size2i *)size
                               mean:(nonnull Scalar *)mean
                             swapRB:(BOOL)swapRB
                               crop:(BOOL)crop;

    Swift

    class func blobFromImages(images: [Mat], scalefactor: Double, size: Size2i, mean: Scalar, swapRB: Bool, crop: Bool) -> Mat

    Parameters

    images

    input images (all with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier for @p images values.

    swapRB

    flag which indicates that swap first and last channels in 3-channel image is necessary.

    crop

    flag 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images
                        scalefactor:(double)scalefactor
                               size:(nonnull Size2i *)size
                               mean:(nonnull Scalar *)mean
                             swapRB:(BOOL)swapRB;

    Swift

    class func blobFromImages(images: [Mat], scalefactor: Double, size: Size2i, mean: Scalar, swapRB: Bool) -> Mat

    Parameters

    images

    input images (all with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier for @p images values.

    swapRB

    flag 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images
                        scalefactor:(double)scalefactor
                               size:(nonnull Size2i *)size
                               mean:(nonnull Scalar *)mean;

    Swift

    class func blobFromImages(images: [Mat], scalefactor: Double, size: Size2i, mean: Scalar) -> Mat

    Parameters

    images

    input images (all with 1-, 3- or 4-channels).

    size

    spatial size for output image

    mean

    scalar 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.

    scalefactor

    multiplier 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images
                        scalefactor:(double)scalefactor
                               size:(nonnull Size2i *)size;

    Swift

    class func blobFromImages(images: [Mat], scalefactor: Double, size: Size2i) -> Mat

    Parameters

    images

    input images (all with 1-, 3- or 4-channels).

    size

    spatial 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.

    scalefactor

    multiplier 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images
                        scalefactor:(double)scalefactor;

    Swift

    class func blobFromImages(images: [Mat], scalefactor: Double) -> Mat

    Parameters

    images

    input 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.

    scalefactor

    multiplier 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

    Objective-C

    + (nonnull Mat *)blobFromImages:(nonnull NSArray<Mat *> *)images;

    Swift

    class func blobFromImages(images: [Mat]) -> Mat

    Parameters

    images

    input 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.

  • Creates blob from .pb file.

    Declaration

    Objective-C

    + (nonnull Mat *)readTensorFromONNX:(nonnull NSString *)path;

    Swift

    class func readTensorFromONNX(path: String) -> Mat

    Parameters

    path

    to the .pb file with input tensor.

    Return Value

    Mat.

  • Loads blob which was serialized as torch.Tensor object of Torch7 framework.

    Warning

    This function has the same limitations as readNetFromTorch().

    Declaration

    Objective-C

    + (nonnull Mat *)readTorchBlob:(nonnull NSString *)filename
                          isBinary:(BOOL)isBinary;

    Swift

    class func readTorchBlob(filename: String, isBinary: Bool) -> Mat
  • Loads blob which was serialized as torch.Tensor object of Torch7 framework.

    Warning

    This function has the same limitations as readNetFromTorch().

    Declaration

    Objective-C

    + (nonnull Mat *)readTorchBlob:(nonnull NSString *)filename;

    Swift

    class func readTorchBlob(filename: String) -> Mat
  • 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) -> Net

    Parameters

    framework

    Name of origin framework.

    bufferModel

    A buffer with a content of binary file with weights

    bufferConfig

    A 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) -> Net

    Parameters

    framework

    Name of origin framework.

    bufferModel

    A buffer with a content of binary file with weights

    Return Value

    Net object.

  • Read deep learning network represented in one of the supported formats.

    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) -> Net

    Parameters

    model

    Binary file contains trained weights. The following file extensions are expected for models from different frameworks:

    config

    Text file contains network configuration. It could be a file with the following extensions:

    framework

    Explicit framework name tag to determine a format.

    Return Value

    Net object.

  • Read deep learning network represented in one of the supported formats.

    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) -> Net

    Parameters

    model

    Binary file contains trained weights. The following file extensions are expected for models from different frameworks:

    config

    Text 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.

    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) -> Net

    Parameters

    model

    Binary 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) -> Net

    Parameters

    prototxt

    path to the .prototxt file with text description of the network architecture.

    caffeModel

    path 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) -> Net

    Parameters

    prototxt

    path 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) -> Net

    Parameters

    bufferProto

    buffer containing the content of the .prototxt file

    bufferModel

    buffer 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) -> Net

    Parameters

    bufferProto

    buffer 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) -> Net

    Parameters

    cfgFile

    path to the .cfg file with text description of the network architecture.

    darknetModel

    path 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) -> Net

    Parameters

    cfgFile

    path 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) -> Net

    Parameters

    bufferCfg

    A buffer contains a content of .cfg file with text description of the network architecture.

    bufferModel

    A 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) -> Net

    Parameters

    bufferCfg

    A 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) -> Net

    Parameters

    xml

    XML configuration file with network’s topology.

    bin

    Binary 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) -> Net

    Parameters

    bufferModelConfig

    Buffer contains XML configuration with network’s topology.

    bufferWeights

    Buffer 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) -> Net

    Parameters

    onnxFile

    path 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) -> Net

    Parameters

    buffer

    in-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) -> Net

    Parameters

    model

    path to the .pb file with binary protobuf description of the network architecture

    config

    path 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) -> Net

    Parameters

    model

    path 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) -> Net

    Parameters

    bufferModel

    buffer containing the content of the pb file

    bufferConfig

    buffer 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) -> Net

    Parameters

    bufferModel

    buffer 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 long type 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) -> Net

    Parameters

    model

    path to the file, dumped from Torch by using torch.save() function.

    isBinary

    specifies whether the network was serialized in ascii mode or binary.

    evaluate

    specifies 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 long type 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) -> Net

    Parameters

    model

    path to the file, dumped from Torch by using torch.save() function.

    isBinary

    specifies 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 long type 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) -> Net

    Parameters

    model

    path 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_TYPE runtime 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) -> String

    Return 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

    bboxes

    a set of bounding boxes to apply NMS.

    scores

    a set of corresponding confidences.

    score_threshold

    a threshold used to filter boxes by score.

    nms_threshold

    a threshold used in non maximum suppression.

    indices

    the kept indices of bboxes after NMS.

    eta

    a 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

    bboxes

    a set of bounding boxes to apply NMS.

    scores

    a set of corresponding confidences.

    score_threshold

    a threshold used to filter boxes by score.

    nms_threshold

    a threshold used in non maximum suppression.

    indices

    the kept indices of bboxes after NMS.

    eta

    a 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

    bboxes

    a set of bounding boxes to apply NMS.

    scores

    a set of corresponding confidences.

    score_threshold

    a threshold used to filter boxes by score.

    nms_threshold

    a threshold used in non maximum suppression.

    indices

    the 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

    src

    Path to origin model from Caffe framework contains single precision floating point weights (usually has .caffemodel extension).

    dst

    Path to destination model with updated weights.

    layersTypes

    Set 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

    src

    Path to origin model from Caffe framework contains single precision floating point weights (usually has .caffemodel extension).

    dst

    Path 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

    model

    A path to binary network.

    output

    A path to output text file to be created.