🤖 AIによる機械翻訳(非公式) — これは OpenCV 4.13.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。
Package org.opencv.dnn
クラス Net
- java.lang.Object
-
- org.opencv.dnn.Net
public class Net extends java.lang.Objectこのクラスは包括的な人工ニューラルネットワークの作成と操作を可能にする。ニューラルネットワークは有向非巡回グラフ(DAG)として表現され、頂点はLayerのインスタンス、エッジは各レイヤの入力と出力の関係を指定する。各ネットワークレイヤは、そのネットワーク内で一意の整数idと一意の文字列名を持つ。LayerIdはレイヤ名またはレイヤidのいずれかを格納できる。このクラスはインスタンスの参照カウントをサポートする。すなわち、コピーは同一のインスタンスを指す。
-
-
フィールドの要約
フィールド Modifier and Type Field Description protected longnativeObj
-
メソッドの要約
すべてのメソッド 静的メソッド インスタンスメソッド 具象メソッド 非推奨メソッド Modifier and Type Method Description static Net__fromPtr__​(long addr)voidconnect​(java.lang.String outPin, java.lang.String inpPin)Connects output of the first layer to input of the second layer.java.lang.Stringdump()Dump net to StringvoiddumpToFile​(java.lang.String path)Dump net structure, hyperparameters, backend, target and fusion to dot filevoiddumpToPbtxt​(java.lang.String path)Dump net structure, hyperparameters, backend, target and fusion to pbtxt filebooleanempty()Returns true if there are no layers in the network.voidenableFusion​(boolean fusion)Enables or disables layer fusion in the network.voidenableWinograd​(boolean useWinograd)Enables or disables the Winograd compute branch.Matforward()Runs forward pass to compute output of layer with nameoutputName.Matforward​(java.lang.String outputName)Runs forward pass to compute output of layer with nameoutputName.voidforward​(java.util.List<Mat> outputBlobs)Runs forward pass to compute output of layer with nameoutputName.voidforward​(java.util.List<Mat> outputBlobs, java.lang.String outputName)Runs forward pass to compute output of layer with nameoutputName.voidforward​(java.util.List<Mat> outputBlobs, java.util.List<java.lang.String> outBlobNames)Runs forward pass to compute outputs of layers listed inoutBlobNames.voidforwardAndRetrieve​(java.util.List<java.util.List<Mat>> outputBlobs, java.util.List<java.lang.String> outBlobNames)Runs forward pass to compute outputs of layers listed inoutBlobNames.longgetFLOPS​(int layerId, java.util.List<MatOfInt> netInputShapes)longgetFLOPS​(int layerId, MatOfInt netInputShape)longgetFLOPS​(java.util.List<MatOfInt> netInputShapes)Computes FLOP for whole loaded model with specified input shapes.longgetFLOPS​(MatOfInt netInputShape)voidgetInputDetails​(MatOfFloat scales, MatOfInt zeropoints)Returns input scale and zeropoint for a quantized Net.LayergetLayer​(int layerId)Returns pointer to layer with specified id or name which the network use.LayergetLayer​(java.lang.String layerName)Deprecated.Use int getLayerId(const String &layer)LayergetLayer​(DictValue layerId)Deprecated.to be removedintgetLayerId​(java.lang.String layer)Converts string name of the layer to the integer identifier.java.util.List<java.lang.String>getLayerNames()intgetLayersCount​(java.lang.String layerType)Returns count of layers of specified type.voidgetLayersShapes​(java.util.List<MatOfInt> netInputShapes, MatOfInt layersIds, java.util.List<java.util.List<MatOfInt>> inLayersShapes, java.util.List<java.util.List<MatOfInt>> outLayersShapes)Returns input and output shapes for all layers in loaded model; preliminary inferencing isn't necessary.voidgetLayersShapes​(MatOfInt netInputShape, MatOfInt layersIds, java.util.List<java.util.List<MatOfInt>> inLayersShapes, java.util.List<java.util.List<MatOfInt>> outLayersShapes)voidgetLayerTypes​(java.util.List<java.lang.String> layersTypes)Returns list of types for layer used in model.voidgetMemoryConsumption​(int layerId, java.util.List<MatOfInt> netInputShapes, long[] weights, long[] blobs)voidgetMemoryConsumption​(int layerId, MatOfInt netInputShape, long[] weights, long[] blobs)voidgetMemoryConsumption​(MatOfInt netInputShape, long[] weights, long[] blobs)longgetNativeObjAddr()voidgetOutputDetails​(MatOfFloat scales, MatOfInt zeropoints)Returns output scale and zeropoint for a quantized Net.MatgetParam​(int layer)Returns parameter blob of the layer.MatgetParam​(int layer, int numParam)Returns parameter blob of the layer.MatgetParam​(java.lang.String layerName)MatgetParam​(java.lang.String layerName, int numParam)longgetPerfProfile​(MatOfDouble timings)Returns overall time for inference and timings (in ticks) for layers.MatOfIntgetUnconnectedOutLayers()Returns indexes of layers with unconnected outputs.java.util.List<java.lang.String>getUnconnectedOutLayersNames()Returns names of layers with unconnected outputs.Netquantize​(java.util.List<Mat> calibData, int inputsDtype, int outputsDtype)Returns a quantized Net from a floating-point Net.Netquantize​(java.util.List<Mat> calibData, int inputsDtype, int outputsDtype, boolean perChannel)Returns a quantized Net from a floating-point Net.static NetreadFromModelOptimizer​(java.lang.String xml, java.lang.String bin)Create a network from Intel's Model Optimizer intermediate representation (IR).static NetreadFromModelOptimizer​(MatOfByte bufferModelConfig, MatOfByte bufferWeights)Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).intregisterOutput​(java.lang.String outputName, int layerId, int outputPort)Registers network output with name Function may create additional 'Identity' layer.voidsetHalideScheduler​(java.lang.String scheduler)Compile Halide layers.voidsetInput​(Mat blob)Sets the new input value for the networkvoidsetInput​(Mat blob, java.lang.String name)Sets the new input value for the networkvoidsetInput​(Mat blob, java.lang.String name, double scalefactor)Sets the new input value for the networkvoidsetInput​(Mat blob, java.lang.String name, double scalefactor, Scalar mean)Sets the new input value for the networkvoidsetInputShape​(java.lang.String inputName, MatOfInt shape)Specify shape of network input.voidsetInputsNames​(java.util.List<java.lang.String> inputBlobNames)Sets outputs names of the network input pseudo layer.voidsetParam​(int layer, int numParam, Mat blob)Sets the new value for the learned param of the layer.voidsetParam​(java.lang.String layerName, int numParam, Mat blob)voidsetPreferableBackend​(int backendId)Ask network to use specific computation backend where it supported.voidsetPreferableTarget​(int targetId)Ask network to make computations on specific target device.
-
-
-
メソッドの詳細
-
getNativeObjAddr
public long getNativeObjAddr()
-
__fromPtr__
public static Net __fromPtr__​(long addr)
-
readFromModelOptimizer
public static Net readFromModelOptimizer​(java.lang.String xml, java.lang.String bin)
Create a network from Intel's Model Optimizer intermediate representation (IR).- 引数:
xml- ネットワークのトポロジーを記述した XML 構成ファイル。bin- 学習済み重みを含むバイナリファイル。IntelのModel Optimizerからインポートされたネットワークは、IntelのInference Engineバックエンドで実行される。- 戻り値:
- 自動生成
-
readFromModelOptimizer
public static Net readFromModelOptimizer​(MatOfByte bufferModelConfig, MatOfByte bufferWeights)
Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).- 引数:
bufferModelConfig- モデルの構成を含むバッファ。bufferWeights- モデルの学習済み重みを含むバッファ。- 戻り値:
- Net オブジェクト。
-
empty
public boolean empty()
Returns true if there are no layers in the network.- 戻り値:
- 自動生成
-
dump
public java.lang.String dump()
Dump net to String- 戻り値:
- 構造、ハイパーパラメータ、バックエンド、ターゲット、フュージョンを表す文字列。このメソッドはsetInput()の後に呼び出す。正しいバックエンド、ターゲット、フュージョンを確認するには、forward()の後に実行する。
-
dumpToFile
public void dumpToFile​(java.lang.String path)
Dump net structure, hyperparameters, backend, target and fusion to dot file- 引数:
path- .dot拡張子を持つ出力ファイルへのパス SEE: dump()
-
dumpToPbtxt
public void dumpToPbtxt​(java.lang.String path)
Dump net structure, hyperparameters, backend, target and fusion to pbtxt file- 引数:
path- .pbtxt拡張子を持つ出力ファイルへのパス Netron (https://netron.app) を使って対象ファイルを開き、モデルを可視化する。このメソッドはsetInput()の後に呼び出す。正しいバックエンド、ターゲット、フュージョンを確認するには、forward()の後に実行する。
-
getLayerId
public int getLayerId​(java.lang.String layer)
Converts string name of the layer to the integer identifier.- 引数:
layer- 自動生成- 戻り値:
- レイヤの id。レイヤが見つからなかった場合は -1。
-
getLayerNames
public java.util.List<java.lang.String> getLayerNames()
-
getLayer
public Layer getLayer​(int layerId)
Returns pointer to layer with specified id or name which the network use.- 引数:
layerId- 自動生成- 戻り値:
- 自動生成
-
getLayer
@Deprecated public Layer getLayer​(java.lang.String layerName)
Deprecated.Use int getLayerId(const String &layer)- 引数:
layerName- 自動生成- 戻り値:
- 自動生成
-
getLayer
@Deprecated public Layer getLayer​(DictValue layerId)
Deprecated.to be removed- 引数:
layerId- 自動生成- 戻り値:
- 自動生成
-
connect
public void connect​(java.lang.String outPin, java.lang.String inpPin)Connects output of the first layer to input of the second layer.- 引数:
outPin- 1つ目のレイヤ出力の記述子。inpPin- 2つ目のレイヤ入力の記述子。記述子は次のテンプレートに従う <DFN><layer_name>[.input_number]</DFN>: - テンプレートの1つ目の部分 <DFN>layer_name</DFN> は追加されたレイヤの文字列名である。この部分が空の場合、ネットワーク入力の擬似レイヤが使用される。- テンプレートの2つ目の省略可能な部分 <DFN>input_number</DFN> は、レイヤ入力の番号またはそのラベルのいずれかである。この部分が省略された場合、1つ目のレイヤ入力が使用される。SEE: setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex()
-
registerOutput
public int registerOutput​(java.lang.String outputName, int layerId, int outputPort)Registers network output with name Function may create additional 'Identity' layer.- 引数:
outputName- 出力の識別子layerId- 2つ目のレイヤの識別子outputPort- 2つ目のレイヤ入力の番号- 戻り値:
- 束縛されたレイヤのインデックス (layerId と同じか、新たに作成されたもの)
-
setInputsNames
public void setInputsNames​(java.util.List<java.lang.String> inputBlobNames)
Sets outputs names of the network input pseudo layer. Each net always has special own the network input pseudo layer with id=0. This layer stores the user blobs only and don't make any computations. In fact, this layer provides the only way to pass user data into the network. As any other layer, this layer can label its outputs and this function provides an easy way to do this.- 引数:
inputBlobNames- 自動生成
-
setInputShape
public void setInputShape​(java.lang.String inputName, MatOfInt shape)Specify shape of network input.- 引数:
inputName- 自動生成shape- 自動生成
-
forward
public Mat forward​(java.lang.String outputName)
Runs forward pass to compute output of layer with nameoutputName.- 引数:
outputName- 出力を取得したいレイヤの名前- 戻り値:
- 指定されたレイヤの1つ目の出力のblob。デフォルトではネットワーク全体に対して順伝播を実行する。
-
forward
public Mat forward()
Runs forward pass to compute output of layer with nameoutputName.- 戻り値:
- 指定されたレイヤの1つ目の出力のblob。デフォルトではネットワーク全体に対して順伝播を実行する。
-
forward
public void forward​(java.util.List<Mat> outputBlobs, java.lang.String outputName)
Runs forward pass to compute output of layer with nameoutputName.- 引数:
outputBlobs- 指定されたレイヤのすべての出力blobを格納する。outputName- 出力を取得したいレイヤの名前。outputNameが空の場合、ネットワーク全体に対して順伝播を実行する。
-
forward
public void forward​(java.util.List<Mat> outputBlobs)
Runs forward pass to compute output of layer with nameoutputName.- 引数:
outputBlobs- 指定されたレイヤのすべての出力blobを格納する。outputNameが空の場合、ネットワーク全体に対して順伝播を実行する。
-
forward
public void forward​(java.util.List<Mat> outputBlobs, java.util.List<java.lang.String> outBlobNames)
Runs forward pass to compute outputs of layers listed inoutBlobNames.- 引数:
outputBlobs- 指定されたレイヤ群の1つ目の出力のblobを格納する。outBlobNames- 出力を取得したいレイヤ群の名前
-
forwardAndRetrieve
public void forwardAndRetrieve​(java.util.List<java.util.List<Mat>> outputBlobs, java.util.List<java.lang.String> outBlobNames)
Runs forward pass to compute outputs of layers listed inoutBlobNames.- 引数:
outputBlobs-outBlobNamesで指定された各レイヤのすべての出力blobを格納する。outBlobNames- 出力を取得したいレイヤ群の名前
-
quantize
public Net quantize​(java.util.List<Mat> calibData, int inputsDtype, int outputsDtype, boolean perChannel)
Returns a quantized Net from a floating-point Net.- 引数:
calibData- 量子化パラメータを計算するためのキャリブレーションデータ。inputsDtype- 量子化されたネットの入力のデータ型。CV_32F または CV_8S を指定できる。outputsDtype- 量子化されたネットの出力のデータ型。CV_32F または CV_8S を指定できる。perChannel- 量子化されたNetの量子化粒度。デフォルトは true で、これはモデルをチャンネル単位(channel-wise)で量子化することを意味する。false に設定すると、モデルをテンソル単位(tensor-wise)で量子化する。- 戻り値:
- 自動生成
-
quantize
public Net quantize​(java.util.List<Mat> calibData, int inputsDtype, int outputsDtype)
Returns a quantized Net from a floating-point Net.- 引数:
calibData- 量子化パラメータを計算するためのキャリブレーションデータ。inputsDtype- 量子化されたネットの入力のデータ型。CV_32F または CV_8S を指定できる。outputsDtype- 量子化されたネットの出力のデータ型。CV_32F または CV_8S を指定できる。チャンネル単位(channel-wise)で量子化する。false に設定すると、モデルをテンソル単位(tensor-wise)で量子化する。- 戻り値:
- 自動生成
-
getInputDetails
public void getInputDetails​(MatOfFloat scales, MatOfInt zeropoints)
Returns input scale and zeropoint for a quantized Net.- 引数:
scales- 入力スケールを返すための出力引数。zeropoints- 入力のゼロ点を返すための出力引数。
-
getOutputDetails
public void getOutputDetails​(MatOfFloat scales, MatOfInt zeropoints)
Returns output scale and zeropoint for a quantized Net.- 引数:
scales- 出力スケールを返すための出力引数。zeropoints- 出力のゼロ点を返すための出力引数。
-
setHalideScheduler
public void setHalideScheduler​(java.lang.String scheduler)
Compile Halide layers.- 引数:
scheduler- スケジューリング指示を含むYAMLファイルへのパス。SEE: setPreferableBackend Halideバックエンドをサポートするレイヤをスケジューリングする。その後、特定のターゲット向けにコンパイルする。スケジューリングファイルに記載されていないレイヤ、または手動スケジューリングが一切使用されていない場合は、自動スケジューリングが適用される。
-
setPreferableBackend
public void setPreferableBackend​(int backendId)
Ask network to use specific computation backend where it supported.- 引数:
backendId- バックエンドの識別子。SEE: Backend
-
setPreferableTarget
public void setPreferableTarget​(int targetId)
Ask network to make computations on specific target device.- 引数:
targetId- ターゲットの識別子。SEE: 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 | | + | | |
-
setInput
public void setInput​(Mat blob, java.lang.String name, double scalefactor, Scalar mean)
Sets the new input value for the network- 引数:
blob- 新しいblob。CV_32F または CV_8U のビット深度を持つ必要がある。name- 入力レイヤの名前。scalefactor- 省略可能な正規化スケール。mean- 省略可能な平均値の減算値。記述子の形式についてはSEE: connect(String, String) を参照。スケールまたは平均値が指定された場合、最終的な入力blobは次のように計算される: \(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)
-
setInput
public void setInput​(Mat blob, java.lang.String name, double scalefactor)
Sets the new input value for the network- 引数:
blob- 新しいblob。CV_32F または CV_8U のビット深度を持つ必要がある。name- 入力レイヤの名前。scalefactor- 省略可能な正規化スケール。記述子の形式についてはSEE: connect(String, String) を参照。スケールまたは平均値が指定された場合、最終的な入力blobは次のように計算される: \(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)
-
setInput
public void setInput​(Mat blob, java.lang.String name)
Sets the new input value for the network- 引数:
blob- 新しいblob。CV_32F または CV_8U のビット深度を持つ必要がある。name- 入力レイヤの名前。記述子の形式についてはSEE: connect(String, String) を参照。スケールまたは平均値が指定された場合、最終的な入力blobは次のように計算される: \(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)
-
setInput
public void setInput​(Mat blob)
Sets the new input value for the network- 引数:
blob- 新しいblob。CV_32F または CV_8U のビット深度を持つ必要がある。記述子の形式についてはSEE: connect(String, String) を参照。スケールまたは平均値が指定された場合、最終的な入力blobは次のように計算される: \(input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\)
-
setParam
public void setParam​(int layer, int numParam, Mat blob)Sets the new value for the learned param of the layer.- 引数:
layer- レイヤの名前またはid。numParam- Layer::blobs 配列におけるレイヤ引数のインデックス。blob- 新しい値。SEE: Layer::blobs 注意: 新しいblobの形状が以前の形状と異なる場合、以降の順伝播が失敗する可能性がある。
-
setParam
public void setParam​(java.lang.String layerName, int numParam, Mat blob)
-
getParam
public Mat getParam​(int layer, int numParam)
Returns parameter blob of the layer.- 引数:
layer- レイヤの名前またはid。numParam- Layer::blobs 配列におけるレイヤ引数のインデックス。SEE: Layer::blobs- 戻り値:
- 自動生成
-
getParam
public Mat getParam​(int layer)
Returns parameter blob of the layer.- 引数:
layer- レイヤの名前またはid。SEE: Layer::blobs- 戻り値:
- 自動生成
-
getParam
public Mat getParam​(java.lang.String layerName, int numParam)
-
getParam
public Mat getParam​(java.lang.String layerName)
-
getUnconnectedOutLayers
public MatOfInt getUnconnectedOutLayers()
Returns indexes of layers with unconnected outputs. FIXIT: Rework API to registerOutput() approach, deprecate this call- 戻り値:
- 自動生成
-
getUnconnectedOutLayersNames
public java.util.List<java.lang.String> getUnconnectedOutLayersNames()
Returns names of layers with unconnected outputs. FIXIT: Rework API to registerOutput() approach, deprecate this call- 戻り値:
- 自動生成
-
getLayersShapes
public void getLayersShapes​(java.util.List<MatOfInt> netInputShapes, MatOfInt layersIds, java.util.List<java.util.List<MatOfInt>> inLayersShapes, java.util.List<java.util.List<MatOfInt>> outLayersShapes)
Returns input and output shapes for all layers in loaded model; preliminary inferencing isn't necessary.- 引数:
netInputShapes- ネットワーク入力レイヤにおけるすべての入力blobの形状。layersIds- レイヤーIDを返す出力引数。inLayersShapes- 入力レイヤーの形状を返す出力引数。順序はlayersIdsと同じ。outLayersShapes- 出力レイヤーの形状を返す出力引数。順序はlayersIdsと同じ。
-
getLayersShapes
public void getLayersShapes​(MatOfInt netInputShape, MatOfInt layersIds, java.util.List<java.util.List<MatOfInt>> inLayersShapes, java.util.List<java.util.List<MatOfInt>> outLayersShapes)
-
getFLOPS
public long getFLOPS​(java.util.List<MatOfInt> netInputShapes)
Computes FLOP for whole loaded model with specified input shapes.- 引数:
netInputShapes- すべてのネット入力に対する形状のベクトル。- 戻り値:
- 計算された FLOP。
-
getFLOPS
public long getFLOPS​(MatOfInt netInputShape)
-
getFLOPS
public long getFLOPS​(int layerId, java.util.List<MatOfInt> netInputShapes)
-
getFLOPS
public long getFLOPS​(int layerId, MatOfInt netInputShape)
-
getLayerTypes
public void getLayerTypes​(java.util.List<java.lang.String> layersTypes)
Returns list of types for layer used in model.- 引数:
layersTypes- 型を返す出力引数。
-
getLayersCount
public int getLayersCount​(java.lang.String layerType)
Returns count of layers of specified type.- 引数:
layerType- 型。- 戻り値:
- レイヤの数
-
getMemoryConsumption
public void getMemoryConsumption​(MatOfInt netInputShape, long[] weights, long[] blobs)
-
getMemoryConsumption
public void getMemoryConsumption​(int layerId, java.util.List<MatOfInt> netInputShapes, long[] weights, long[] blobs)
-
getMemoryConsumption
public void getMemoryConsumption​(int layerId, MatOfInt netInputShape, long[] weights, long[] blobs)
-
enableFusion
public void enableFusion​(boolean fusion)
Enables or disables layer fusion in the network.- 引数:
fusion- フュージョンを有効にする場合はtrue、無効にする場合はfalse。フュージョンはデフォルトで有効。
-
enableWinograd
public void enableWinograd​(boolean useWinograd)
Enables or disables the Winograd compute branch. The Winograd compute branch can speed up 3x3 Convolution at a small loss of accuracy.- 引数:
useWinograd- Winograd演算ブランチを有効にする場合はtrue。デフォルトはtrue。
-
getPerfProfile
public long getPerfProfile​(MatOfDouble timings)
Returns overall time for inference and timings (in ticks) for layers. Indexes in returned vector correspond to layers ids. Some layers can be fused with others, in this case zero ticks count will be return for that skipped layers. Supported by DNN_BACKEND_OPENCV on DNN_TARGET_CPU only.- 引数:
timings- すべてのレイヤーのティック計時を格納するベクトル。- 戻り値:
- モデル推論の総ティック数。
-
-