🤖 AIによる機械翻訳(非公式) — これは OpenCV 5.0.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.voiddisableKVCache()Disables KV-Cache for all AttentionOnnxI layersjava.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.voidenableKVCache()Enables KV-Cache for all AttentionOnnxI layersvoidenableWinograd​(boolean useWinograd)Enables or disables the Winograd compute branch.voidfinalizeNet()Finalizes the network configuration and prepares it for inference.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​(java.util.List<MatOfInt> netInputShapes, MatOfInt netInputTypes)Computes FLOP for whole loaded model with specified input shapes.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.voidgetLayerShapes​(java.util.List<MatOfInt> netInputShapes, MatOfInt netInputTypes, int layerId, java.util.List<MatOfInt> inLayerShapes, java.util.List<MatOfInt> outLayerShapes)The only overload of getLayerShapes that should be kept in 5.xvoidgetLayerTypes​(java.util.List<java.lang.String> layersTypes)Returns list of types for layer used in model.voidgetMemoryConsumption​(java.util.List<MatOfInt> netInputShapes, MatOfInt netInputTypes, long[] weights, long[] blobs)Computes bytes number which are required to store all weights and intermediate blobs for model.longgetNativeObjAddr()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)voidgetPerfProfile​(java.util.List<java.lang.String> names, java.util.List<java.lang.String> timems, java.util.List<java.lang.String> counts)Returns profiling data captured during the last forward pass.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.voidprintPerfProfile()Prints the profile captured during the last forward pass in a formatted table using CV_LOG_INFO.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.voidresetKVCache()Resets KV-Cache for all AttentionOnnxI layersvoidsetInput​(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)Sets the parameter blob of a layer identified by its name or output tensor name.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- 出力を取得したいレイヤ群の名前
-
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_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 | | + | |
-
finalizeNet
public void finalizeNet()
Finalizes the network configuration and prepares it for inference. This method must be called after setting backend/target via setPreferableBackend() and setPreferableTarget(), and before the first forward() call. It creates the underlying execution session (e.g. ONNX Runtime session) on the configured backend/target. If not called explicitly, the first forward() will call it automatically. Calling finalizeNet() early lets you pay the one-time setup cost at a predictable point and catch configuration errors before inference.
-
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)Sets the parameter blob of a layer identified by its name or output tensor name.- 引数:
layerName- レイヤー名(従来エンジン)またはONNXの生の出力テンソル名(ENGINE_NEW)。numParam- 更新する定数の重み入力のインデックス(0 = カーネル、1 = バイアスなど)。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- 戻り値:
- 自動生成
-
getLayerShapes
public void getLayerShapes​(java.util.List<MatOfInt> netInputShapes, MatOfInt netInputTypes, int layerId, java.util.List<MatOfInt> inLayerShapes, java.util.List<MatOfInt> outLayerShapes)
The only overload of getLayerShapes that should be kept in 5.x- 引数:
netInputShapes- 自動生成netInputTypes- 自動生成layerId- 自動生成inLayerShapes- 自動生成outLayerShapes- 自動生成
-
getFLOPS
public long getFLOPS​(java.util.List<MatOfInt> netInputShapes, MatOfInt netInputTypes)
Computes FLOP for whole loaded model with specified input shapes.- 引数:
netInputShapes- すべてのネット入力に対する形状のベクトル。netInputTypes- ネットワークの全入力に対する型のベクトル。- 戻り値:
- 計算された FLOP。
-
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​(java.util.List<MatOfInt> netInputShapes, MatOfInt netInputTypes, long[] weights, long[] blobs)
Computes bytes number which are required to store all weights and intermediate blobs for model.- 引数:
netInputShapes- すべてのネット入力に対する形状のベクトル。netInputTypes- ネットワークの全入力に対する型のベクトル。weights- 重みの結果バイト列を格納する出力引数。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- すべてのレイヤーのティック計時を格納するベクトル。- 戻り値:
- モデル推論の総ティック数。
-
enableKVCache
public void enableKVCache()
Enables KV-Cache for all AttentionOnnxI layers
-
disableKVCache
public void disableKVCache()
Disables KV-Cache for all AttentionOnnxI layers
-
resetKVCache
public void resetKVCache()
Resets KV-Cache for all AttentionOnnxI layers
-
getPerfProfile
public void getPerfProfile​(java.util.List<java.lang.String> names, java.util.List<java.lang.String> timems, java.util.List<java.lang.String> counts)Returns profiling data captured during the last forward pass. Entries are sorted by time in descending order. Empty vectors are returned if profiling is disabled (DNN_PROFILE_NONE).- 引数:
names- 自動生成timems- 自動生成counts- 自動生成
-
printPerfProfile
public void printPerfProfile()
Prints the profile captured during the last forward pass in a formatted table using CV_LOG_INFO. In DNN_PROFILE_DETAILED mode, prints per-layer label, time, and percentage. In DNN_PROFILE_SUMMARY mode, prints per-type count, time, and percentage. Does nothing if profiling is disabled (DNN_PROFILE_NONE) or all timings are zero.
-
-