Model

Objective-C

@interface Model : Net

Swift

class Model : Net

This class is presented high-level API for neural networks.

Model allows to set params for preprocessing input image. Model creates net from file with trained weights and config, sets preprocessing input and runs forward pass.

Member of Dnn

Methods

  • Create model from deep learning network.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithNetwork:(nonnull Net *)network;

    Swift

    init(network: Net)

    Parameters

    network

    Net object.

  • Create model from deep learning network represented in one of the supported formats. An order of @p model and @p config arguments does not matter.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithModel:(nonnull NSString *)model
                                   config:(nonnull NSString *)config;

    Swift

    init(model: String, config: String)

    Parameters

    model

    Binary file contains trained weights.

    config

    Text file contains network configuration.

  • Create model from deep learning network represented in one of the supported formats. An order of @p model and @p config arguments does not matter.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithModel:(nonnull NSString *)model;

    Swift

    init(model: String)

    Parameters

    model

    Binary file contains trained weights.

  • Set flag crop for frame.

    Declaration

    Objective-C

    - (nonnull Model *)setInputCrop:(BOOL)crop;

    Swift

    func setInputCrop(crop: Bool) -> Model

    Parameters

    crop

    Flag which indicates whether image will be cropped after resize or not.

  • Set mean value for frame.

    Declaration

    Objective-C

    - (nonnull Model *)setInputMean:(nonnull Scalar *)mean;

    Swift

    func setInputMean(mean: Scalar) -> Model

    Parameters

    mean

    Scalar with mean values which are subtracted from channels.

  • Set scalefactor value for frame.

    Declaration

    Objective-C

    - (nonnull Model *)setInputScale:(double)scale;

    Swift

    func setInputScale(scale: Double) -> Model

    Parameters

    scale

    Multiplier for frame values.

  • Set input size for frame.

    Note

    If shape of the new blob less than 0, then frame size not change.

    Declaration

    Objective-C

    - (nonnull Model *)setInputSize:(nonnull Size2i *)size;

    Swift

    func setInputSize(size: Size2i) -> Model

    Parameters

    size

    New input size.

  • Set input size for frame.

    Note

    If shape of the new blob less than 0, then frame size not change.

    Declaration

    Objective-C

    - (nonnull Model *)setInputSize:(int)width height:(int)height;

    Swift

    func setInputSize(width: Int32, height: Int32) -> Model

    Parameters

    width

    New input width.

    height

    New input height.

  • Set flag swapRB for frame.

    Declaration

    Objective-C

    - (nonnull Model *)setInputSwapRB:(BOOL)swapRB;

    Swift

    func setInputSwapRB(swapRB: Bool) -> Model

    Parameters

    swapRB

    Flag which indicates that swap first and last channels.

  • Given the @p input frame, create input blob, run net and return the output @p blobs.

    Declaration

    Objective-C

    - (void)predict:(nonnull Mat *)frame outs:(nonnull NSMutableArray<Mat *> *)outs;

    Swift

    func predict(frame: Mat, outs: NSMutableArray)

    Parameters

    outs

    Allocated output blobs, which will store results of the computation.

  • Set preprocessing parameters for frame.

    Declaration

    Objective-C

    - (void)setInputParams:(double)scale
                      size:(nonnull Size2i *)size
                      mean:(nonnull Scalar *)mean
                    swapRB:(BOOL)swapRB
                      crop:(BOOL)crop;

    Swift

    func setInputParams(scale: Double, size: Size2i, mean: Scalar, swapRB: Bool, crop: Bool)

    Parameters

    size

    New input size.

    mean

    Scalar with mean values which are subtracted from channels.

    scale

    Multiplier for frame values.

    swapRB

    Flag which indicates that swap first and last channels.

    crop

    Flag which indicates whether image will be cropped after resize or not. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean© )

  • Set preprocessing parameters for frame.

    Declaration

    Objective-C

    - (void)setInputParams:(double)scale
                      size:(nonnull Size2i *)size
                      mean:(nonnull Scalar *)mean
                    swapRB:(BOOL)swapRB;

    Swift

    func setInputParams(scale: Double, size: Size2i, mean: Scalar, swapRB: Bool)

    Parameters

    size

    New input size.

    mean

    Scalar with mean values which are subtracted from channels.

    scale

    Multiplier for frame values.

    swapRB

    Flag which indicates that swap first and last channels. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean© )

  • Set preprocessing parameters for frame.

    Declaration

    Objective-C

    - (void)setInputParams:(double)scale
                      size:(nonnull Size2i *)size
                      mean:(nonnull Scalar *)mean;

    Swift

    func setInputParams(scale: Double, size: Size2i, mean: Scalar)

    Parameters

    size

    New input size.

    mean

    Scalar with mean values which are subtracted from channels.

    scale

    Multiplier for frame values. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean© )

  • Set preprocessing parameters for frame.

    Declaration

    Objective-C

    - (void)setInputParams:(double)scale size:(nonnull Size2i *)size;

    Swift

    func setInputParams(scale: Double, size: Size2i)

    Parameters

    size

    New input size.

    scale

    Multiplier for frame values. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean© )

  • Set preprocessing parameters for frame.

    Declaration

    Objective-C

    - (void)setInputParams:(double)scale;

    Swift

    func setInputParams(scale: Double)

    Parameters

    scale

    Multiplier for frame values. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean© )

  • Set preprocessing parameters for frame. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean© )

    Declaration

    Objective-C

    - (void)setInputParams;

    Swift

    func setInputParams()