public class Net extends Object
Modifier and Type | Field and Description |
---|---|
protected long |
nativeObj |
Modifier | Constructor and Description |
---|---|
|
Net() |
protected |
Net(long addr) |
Modifier and Type | Method and Description |
---|---|
static Net |
__fromPtr__(long addr) |
void |
connect(String outPin,
String inpPin)
Connects output of the first layer to input of the second layer.
|
String |
dump()
Dump net to String
|
void |
dumpToFile(String path)
Dump net structure, hyperparameters, backend, target and fusion to dot file
|
boolean |
empty()
Returns true if there are no layers in the network.
|
void |
enableFusion(boolean fusion)
Enables or disables layer fusion in the network.
|
void |
enableWinograd(boolean useWinograd)
Enables or disables the Winograd compute branch.
|
protected void |
finalize() |
Mat |
forward()
Runs forward pass to compute output of layer with name
outputName . |
void |
forward(List<Mat> outputBlobs)
Runs forward pass to compute output of layer with name
outputName . |
void |
forward(List<Mat> outputBlobs,
List<String> outBlobNames)
Runs forward pass to compute outputs of layers listed in
outBlobNames . |
void |
forward(List<Mat> outputBlobs,
String outputName)
Runs forward pass to compute output of layer with name
outputName . |
Mat |
forward(String outputName)
Runs forward pass to compute output of layer with name
outputName . |
long |
getFLOPS(int layerId,
List<MatOfInt> netInputShapes) |
long |
getFLOPS(int layerId,
MatOfInt netInputShape) |
long |
getFLOPS(List<MatOfInt> netInputShapes)
Computes FLOP for whole loaded model with specified input shapes.
|
long |
getFLOPS(MatOfInt netInputShape) |
void |
getInputDetails(MatOfFloat scales,
MatOfInt zeropoints)
Returns input scale and zeropoint for a quantized Net.
|
Layer |
getLayer(DictValue layerId)
Deprecated.
to be removed
|
Layer |
getLayer(int layerId)
Returns pointer to layer with specified id or name which the network use.
|
Layer |
getLayer(String layerName)
Deprecated.
Use int getLayerId(const String &layer)
|
int |
getLayerId(String layer)
Converts string name of the layer to the integer identifier.
|
List<String> |
getLayerNames() |
int |
getLayersCount(String layerType)
Returns count of layers of specified type.
|
void |
getLayerTypes(List<String> layersTypes)
Returns list of types for layer used in model.
|
void |
getMemoryConsumption(int layerId,
List<MatOfInt> netInputShapes,
long[] weights,
long[] blobs) |
void |
getMemoryConsumption(int layerId,
MatOfInt netInputShape,
long[] weights,
long[] blobs) |
void |
getMemoryConsumption(MatOfInt netInputShape,
long[] weights,
long[] blobs) |
long |
getNativeObjAddr() |
void |
getOutputDetails(MatOfFloat scales,
MatOfInt zeropoints)
Returns output scale and zeropoint for a quantized Net.
|
Mat |
getParam(int layer)
Returns parameter blob of the layer.
|
Mat |
getParam(int layer,
int numParam)
Returns parameter blob of the layer.
|
Mat |
getParam(String layerName) |
Mat |
getParam(String layerName,
int numParam) |
long |
getPerfProfile(MatOfDouble timings)
Returns overall time for inference and timings (in ticks) for layers.
|
MatOfInt |
getUnconnectedOutLayers()
Returns indexes of layers with unconnected outputs.
|
List<String> |
getUnconnectedOutLayersNames()
Returns names of layers with unconnected outputs.
|
Net |
quantize(List<Mat> calibData,
int inputsDtype,
int outputsDtype)
Returns a quantized Net from a floating-point Net.
|
Net |
quantize(List<Mat> calibData,
int inputsDtype,
int outputsDtype,
boolean perChannel)
Returns a quantized Net from a floating-point Net.
|
static Net |
readFromModelOptimizer(MatOfByte bufferModelConfig,
MatOfByte bufferWeights)
Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).
|
static Net |
readFromModelOptimizer(String xml,
String bin)
Create a network from Intel's Model Optimizer intermediate representation (IR).
|
void |
setHalideScheduler(String scheduler)
Compile Halide layers.
|
void |
setInput(Mat blob)
Sets the new input value for the network
|
void |
setInput(Mat blob,
String name)
Sets the new input value for the network
|
void |
setInput(Mat blob,
String name,
double scalefactor)
Sets the new input value for the network
|
void |
setInput(Mat blob,
String name,
double scalefactor,
Scalar mean)
Sets the new input value for the network
|
void |
setInputShape(String inputName,
MatOfInt shape)
Specify shape of network input.
|
void |
setInputsNames(List<String> inputBlobNames)
Sets outputs names of the network input pseudo layer.
|
void |
setParam(int layer,
int numParam,
Mat blob)
Sets the new value for the learned param of the layer.
|
void |
setParam(String layerName,
int numParam,
Mat blob) |
void |
setPreferableBackend(int backendId)
Ask network to use specific computation backend where it supported.
|
void |
setPreferableTarget(int targetId)
Ask network to make computations on specific target device.
|
public long getNativeObjAddr()
public static Net __fromPtr__(long addr)
public static Net readFromModelOptimizer(String xml, String bin)
xml
- XML configuration file with network's topology.bin
- Binary file with trained weights.
Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine
backend.public static Net readFromModelOptimizer(MatOfByte bufferModelConfig, MatOfByte bufferWeights)
bufferModelConfig
- buffer with model's configuration.bufferWeights
- buffer with model's trained weights.public boolean empty()
public String dump()
public void dumpToFile(String path)
path
- path to output file with .dot extension
SEE: dump()public int getLayerId(String layer)
layer
- automatically generatedpublic Layer getLayer(int layerId)
layerId
- automatically generated@Deprecated public Layer getLayer(String layerName)
layerName
- automatically generated@Deprecated public Layer getLayer(DictValue layerId)
layerId
- automatically generatedpublic void connect(String outPin, String inpPin)
outPin
- descriptor of the first layer output.inpPin
- descriptor of the second layer input.
Descriptors have the following template <DFN><layer_name>[.input_number]</DFN>:
- the first part of the template <DFN>layer_name</DFN> is string name of the added layer.
If this part is empty then the network input pseudo layer will be used;
- the second optional part of the template <DFN>input_number</DFN>
is either number of the layer input, either label one.
If this part is omitted then the first layer input will be used.
SEE: setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex()public void setInputsNames(List<String> inputBlobNames)
inputBlobNames
- automatically generatedpublic void setInputShape(String inputName, MatOfInt shape)
inputName
- automatically generatedshape
- automatically generatedpublic Mat forward(String outputName)
outputName
.outputName
- name for layer which output is needed to getpublic Mat forward()
outputName
.public void forward(List<Mat> outputBlobs, String outputName)
outputName
.outputBlobs
- contains all output blobs for specified layer.outputName
- name for layer which output is needed to get
If outputName
is empty, runs forward pass for the whole network.public void forward(List<Mat> outputBlobs)
outputName
.outputBlobs
- contains all output blobs for specified layer.
If outputName
is empty, runs forward pass for the whole network.public void forward(List<Mat> outputBlobs, List<String> outBlobNames)
outBlobNames
.outputBlobs
- contains blobs for first outputs of specified layers.outBlobNames
- names for layers which outputs are needed to getpublic Net quantize(List<Mat> calibData, int inputsDtype, int outputsDtype, boolean perChannel)
calibData
- Calibration data to compute the quantization parameters.inputsDtype
- Datatype of quantized net's inputs. Can be CV_32F or CV_8S.outputsDtype
- Datatype of quantized net's outputs. Can be CV_32F or CV_8S.perChannel
- Quantization granularity of quantized Net. The default is true, that means quantize model
in per-channel way (channel-wise). Set it false to quantize model in per-tensor way (or tensor-wise).public Net quantize(List<Mat> calibData, int inputsDtype, int outputsDtype)
calibData
- Calibration data to compute the quantization parameters.inputsDtype
- Datatype of quantized net's inputs. Can be CV_32F or CV_8S.outputsDtype
- Datatype of quantized net's outputs. Can be CV_32F or CV_8S.
in per-channel way (channel-wise). Set it false to quantize model in per-tensor way (or tensor-wise).public void getInputDetails(MatOfFloat scales, MatOfInt zeropoints)
scales
- output parameter for returning input scales.zeropoints
- output parameter for returning input zeropoints.public void getOutputDetails(MatOfFloat scales, MatOfInt zeropoints)
scales
- output parameter for returning output scales.zeropoints
- output parameter for returning output zeropoints.public void setHalideScheduler(String scheduler)
scheduler
- Path to YAML file with scheduling directives.
SEE: setPreferableBackend
Schedule layers that support Halide backend. Then compile them for
specific target. For layers that not represented in scheduling file
or if no manual scheduling used at all, automatic scheduling will be applied.public void setPreferableBackend(int backendId)
backendId
- backend identifier.
SEE: Backendpublic void setPreferableTarget(int targetId)
targetId
- target identifier.
SEE: Target
List of supported combinations backend / target:
| | DNN_BACKEND_OPENCV | DNN_BACKEND_INFERENCE_ENGINE | DNN_BACKEND_HALIDE | DNN_BACKEND_CUDA |
|------------------------|--------------------|------------------------------|--------------------|-------------------|
| DNN_TARGET_CPU | + | + | + | |
| DNN_TARGET_OPENCL | + | + | + | |
| DNN_TARGET_OPENCL_FP16 | + | + | | |
| DNN_TARGET_MYRIAD | | + | | |
| DNN_TARGET_FPGA | | + | | |
| DNN_TARGET_CUDA | | | | + |
| DNN_TARGET_CUDA_FP16 | | | | + |
| DNN_TARGET_HDDL | | + | | |public void setInput(Mat blob, String name, double scalefactor, Scalar mean)
blob
- A new blob. Should have CV_32F or CV_8U depth.name
- A name of input layer.scalefactor
- An optional normalization scale.mean
- An optional mean subtraction values.
SEE: connect(String, String) to know format of the descriptor.
If scale or mean values are specified, a final input blob is computed
as:
\(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)public void setInput(Mat blob, String name, double scalefactor)
blob
- A new blob. Should have CV_32F or CV_8U depth.name
- A name of input layer.scalefactor
- An optional normalization scale.
SEE: connect(String, String) to know format of the descriptor.
If scale or mean values are specified, a final input blob is computed
as:
\(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)public void setInput(Mat blob, String name)
blob
- A new blob. Should have CV_32F or CV_8U depth.name
- A name of input layer.
SEE: connect(String, String) to know format of the descriptor.
If scale or mean values are specified, a final input blob is computed
as:
\(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)public void setInput(Mat blob)
blob
- A new blob. Should have CV_32F or CV_8U depth.
SEE: connect(String, String) to know format of the descriptor.
If scale or mean values are specified, a final input blob is computed
as:
\(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)public void setParam(int layer, int numParam, Mat blob)
layer
- name or id of the layer.numParam
- index of the layer parameter in the Layer::blobs array.blob
- the new value.
SEE: Layer::blobs
Note: If shape of the new blob differs from the previous shape,
then the following forward pass may fail.public Mat getParam(int layer, int numParam)
layer
- name or id of the layer.numParam
- index of the layer parameter in the Layer::blobs array.
SEE: Layer::blobspublic Mat getParam(int layer)
layer
- name or id of the layer.
SEE: Layer::blobspublic MatOfInt getUnconnectedOutLayers()
public List<String> getUnconnectedOutLayersNames()
public long getFLOPS(List<MatOfInt> netInputShapes)
netInputShapes
- vector of shapes for all net inputs.public long getFLOPS(MatOfInt netInputShape)
public long getFLOPS(int layerId, MatOfInt netInputShape)
public void getLayerTypes(List<String> layersTypes)
layersTypes
- output parameter for returning types.public int getLayersCount(String layerType)
layerType
- type.public void getMemoryConsumption(MatOfInt netInputShape, long[] weights, long[] blobs)
public void getMemoryConsumption(int layerId, List<MatOfInt> netInputShapes, long[] weights, long[] blobs)
public void getMemoryConsumption(int layerId, MatOfInt netInputShape, long[] weights, long[] blobs)
public void enableFusion(boolean fusion)
fusion
- true to enable the fusion, false to disable. The fusion is enabled by default.public void enableWinograd(boolean useWinograd)
useWinograd
- true to enable the Winograd compute branch. The default is true.public long getPerfProfile(MatOfDouble timings)
timings
- vector for tick timings for all layers.Copyright © 2024. All rights reserved.