1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

removed classic engine

This commit is contained in:
Abhishek Gola
2026-06-19 13:14:32 +05:30
parent 49b8f7c03f
commit 46331314a5
25 changed files with 52 additions and 140 deletions
+6 -8
View File
@@ -53,7 +53,7 @@ std::string diagnosticKeys =
"{ model m | | Path to the model file. }"
"{ config c | | Path to the model configuration file. }"
"{ framework f | | [Optional] Name of the model framework. }"
"{ engine e | auto | [Optional] Graph negine selector: auto or classic or new}"
"{ engine e | new | [Optional] DNN engine selector: new (default) or ort}"
"{ input0_name | | [Optional] Name of input0. Use with input0_shape}"
"{ input0_shape | | [Optional] Shape of input0. Use with input0_name}"
"{ input1_name | | [Optional] Name of input1. Use with input1_shape}"
@@ -98,19 +98,17 @@ int main( int argc, const char** argv )
std::string input4_name = argParser.get<std::string>("input4_name");
std::string input4_shape = argParser.get<std::string>("input4_shape");
dnn::EngineType engine = dnn::ENGINE_AUTO;
dnn::EngineType engine = dnn::ENGINE_NEW;
if (argParser.has("engine"))
{
std::string eng_name = argParser.get<std::string>("engine");
if(eng_name == "auto")
engine = dnn::ENGINE_AUTO;
else if(eng_name == "classic")
engine = dnn::ENGINE_CLASSIC;
else if(eng_name == "new")
if(eng_name == "new")
engine = dnn::ENGINE_NEW;
else if(eng_name == "ort")
engine = dnn::ENGINE_ORT;
else
{
std::cerr << "Unknown DNN graph engine \"" << eng_name << "\"\n";
std::cerr << "Unknown DNN graph engine \"" << eng_name << "\" (use 'new' or 'ort')\n";
return -1;
}
}
+21 -35
View File
@@ -254,45 +254,31 @@ class LSTM2LayerImpl CV_FINAL : public LSTM2Layer
batchSize = input[0].size[0];
}
// ONNX LSTM inputs: X(0), W(1), R(2), B(3), sequence_lens(4),
// initial_h(5), initial_c(6), P(7). Inputs 3..7 are optional and
// may be present-but-empty (e.g. CNTK exports keep all 8 slots with
// empties for unused ones). Gather by presence/non-emptiness rather
// than by the raw input count so optional/empty inputs are ignored.
auto hasInput = [&](int idx) {
return idx < numInputs && !input[idx].empty();
};
std::vector<Mat> blobs_;
int hidShape [] = {1 + static_cast<int>(bidirectional), batchSize, numHidden};
int biasShape [] = {1 + static_cast<int>(bidirectional), 8 * numHidden};
blobs_.push_back(input[1].clone());
blobs_.push_back(input[2].clone());
switch (numInputs) {
case 3:
// X, W, R are given
// create bias
blobs_.push_back(Mat::zeros(2, biasShape, input[0].type()));
// create h0, c0
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
break;
case 4:
// X, W, R, B are given
blobs_.push_back(input[3]);
// create h0, c0
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
break;
case 7:
// X, W, R, B, h0, c0 are given
blobs_.push_back(input[3]);
blobs_.push_back(input[5]);
blobs_.push_back(input[6]);
break;
case 8:
// X, W, R, B, seqlen, h0, c0, P are given
blobs_.push_back(input[3]);
blobs_.push_back(input[5]);
blobs_.push_back(input[6]);
blobs_.push_back(input[7]);
break;
default:
CV_Error(Error::StsNotImplemented, "Insufficient inputs for LSTM layer. "
"Required inputs: X, W, R, B, seqLen, h0, c0 [, P for peephole]");
}
CV_Assert(numInputs >= 3); // X, W, R are mandatory
blobs_.push_back(input[1].clone()); // W
blobs_.push_back(input[2].clone()); // R
// B
blobs_.push_back(hasInput(3) ? input[3] : Mat::zeros(2, biasShape, input[0].type()));
// initial_h
blobs_.push_back(hasInput(5) ? input[5] : Mat::zeros(3, hidShape, input[0].type()));
// initial_c
blobs_.push_back(hasInput(6) ? input[6] : Mat::zeros(3, hidShape, input[0].type()));
// P (peephole) - only when the layer was configured to use it and the input is present
if (usePeephole && hasInput(7))
blobs_.push_back(input[7]);
// set outputs to 0
for (auto& out : output)
+3 -17
View File
@@ -777,22 +777,6 @@ bool ONNXImporter2::parseValueInfo(const opencv_onnx::ValueInfoProto& valueInfoP
} else {
// ONNX allows dimensions without dim_value and dim_param.
// Treat them as unnamed symbolic dimensions.
// NOTE: LSTM with unnamed dimensions is not ready in the new graph
// engine yet. The classic parser used to handle it, but it has been
// removed, so such models are reported as unsupported.
if (curr_graph_proto)
{
const int n_nodes = curr_graph_proto->node_size();
for (int i = 0; i < n_nodes; ++i)
{
const std::string& op = curr_graph_proto->node(i).op_type();
if (op == "LSTM")
{
raiseError();
return false;
}
}
}
val_j = net.findDim("", true);
}
//CV_Assert(0 <= val_j && val_j <= INT_MAX);
@@ -1364,7 +1348,9 @@ void ONNXImporter2::parseLSTM(LayerParams& layerParams, const opencv_onnx::NodeP
layerParams.set("produce_sequence_y", need_y);
if (lstm_proto.input_size() == 8)
// The 8th input (P, peephole weights) is optional; an absent ONNX input is
// encoded as an empty name. Only enable peephole when it is actually present.
if (lstm_proto.input_size() == 8 && !lstm_proto.input(7).empty())
layerParams.set("use_peephole", true);
+1 -4
View File
@@ -135,10 +135,7 @@ int main(int argc, char *argv[])
Ptr<CCheckerDetector> detector;
#ifdef HAVE_OPENCV_DNN
if (model_path != "" && pbtxt_path != ""){
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net = readNetFromTensorflow(model_path, pbtxt_path, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
+1 -5
View File
@@ -165,11 +165,7 @@ int main(int argc, char **argv)
parser.about(about);
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu")
{
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net;
loadModel(model, backend, target, net, engine);
+1 -3
View File
@@ -140,9 +140,7 @@ def apply_modnet(args, model, image):
def main(func_args=None):
args = get_args_parser(func_args)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
image = cv.imread(cv.samples.findFile(args.input))
if image is None:
+1 -4
View File
@@ -146,10 +146,7 @@ int main(int argc, char** argv)
}
CV_Assert(!model.empty());
//! [Read and initialize network]
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net = readNetFromONNX(model, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
+1 -3
View File
@@ -83,9 +83,7 @@ def main(func_args=None):
labels = f.read().rstrip('\n').split('\n')
# Load a network
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNetFromONNX(args.model, engine)
net.setPreferableBackend(get_backend_id(args.backend))
net.setPreferableTarget(get_target_id(args.target))
+1 -4
View File
@@ -83,10 +83,7 @@ int main(int argc, char** argv) {
resize(imgL, imgLResized, Size(256, 256), 0, 0, INTER_CUBIC);
// Prepare the model
EngineType engine = ENGINE_AUTO;
if (backendId != 0 || targetId != 0){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
dnn::Net net = dnn::readNetFromONNX(onnxModelPath, engine);
net.setPreferableBackend(backendId);
net.setPreferableTarget(targetId);
+1 -3
View File
@@ -44,9 +44,7 @@ if __name__ == '__main__':
img_gray_rs *= (100.0 / 255.0) # Scale L channel to 0-100 range
onnx_model_path = args.onnx_model_path # Update this path to your ONNX model's path
engine = cv.dnn.ENGINE_AUTO
if args.backend != 0 or args.target != 0:
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
session = cv.dnn.readNetFromONNX(onnx_model_path, engine)
session.setPreferableBackend(args.backend)
session.setPreferableTarget(args.target)
+1 -4
View File
@@ -95,10 +95,7 @@ int main(int argc, char **argv)
bool swapRB = parser.get<bool>("rgb");
Scalar mean_v = parser.get<Scalar>("mean");
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net = readNetFromONNX(modelPath, engine);
net.setPreferableBackend(getBackendID(backend));
+1 -4
View File
@@ -83,10 +83,7 @@ def main():
args.model = findModel(args.model, args.sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNetFromONNX(args.model, engine)
net.setPreferableBackend(get_backend_id(args.backend))
+1 -4
View File
@@ -159,10 +159,7 @@ int main(int argc, char** argv) {
string method = parser.get<String>("method");
String sha1 = parser.get<String>("sha1");
string model = findModel(parser.get<String>("model"), sha1);
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
parser.about(about);
VideoCapture cap;
+1 -3
View File
@@ -110,9 +110,7 @@ def apply_dexined(model, image):
def main(func_args=None):
args = get_args_parser(func_args)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0)
if not cap.isOpened():
+1 -4
View File
@@ -129,10 +129,7 @@ int main(int argc, char **argv)
cout<<"Model loading..."<<endl;
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net = readNetFromONNX(modelPath, engine);
net.setPreferableBackend(getBackendID(backend));
+1 -4
View File
@@ -114,10 +114,7 @@ def main():
args.model = findModel(args.model, args.sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNetFromONNX(args.model, engine)
net.setPreferableBackend(get_backend_id(args.backend))
+1 -3
View File
@@ -355,9 +355,7 @@ class DDIMInpainter(object):
decoder_path = findModel(args.decoder_model, args.decoder_sha1)
diffusor_path = findModel(args.diffusor_model, args.diffusor_sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
self.encoder = cv.dnn.readNet(encoder_path, "", "", engine)
self.diffusor = cv.dnn.readNet(diffusor_path, "", "", engine)
+1 -4
View File
@@ -220,10 +220,7 @@ int main(int argc, char** argv)
}
}
//![read_net]
EngineType engine = ENGINE_AUTO;
if ((parser.get<String>("backend") != "default") || (parser.get<String>("target") != "cpu")){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net = readNet(modelPath, configPath, "", engine);
int backend = getBackendID(parser.get<String>("backend"));
net.setPreferableBackend(backend);
+1 -3
View File
@@ -99,9 +99,7 @@ if args.labels:
labels = f.read().rstrip('\n').split('\n')
# Load a network
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNet(args.model, args.config, "", engine)
net.setPreferableBackend(get_backend_id(args.backend))
net.setPreferableTarget(get_target_id(args.target))
+1 -4
View File
@@ -258,10 +258,7 @@ int main(int argc, char **argv)
int fontSize = 50;
int fontWeight = 500;
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net reidNet = readNetFromONNX(modelPath, engine);
reidNet.setPreferableBackend(getBackendID(backend));
reidNet.setPreferableTarget(getTargetID(target));
+1 -4
View File
@@ -183,10 +183,7 @@ def main():
else:
args.yolo_model = findModel(args.yolo_model, args.yolo_sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
yolo_net = cv.dnn.readNetFromONNX(args.yolo_model, engine)
reid_net = cv.dnn.readNetFromONNX(args.model, engine)
reid_net.setPreferableBackend(get_backend_id(args.backend))
+1 -4
View File
@@ -214,10 +214,7 @@ int main(int argc, char **argv)
CV_Assert(!model.empty());
//! [Read and initialize network]
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_NEW;
Net net = readNetFromONNX(model, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
+1 -3
View File
@@ -100,9 +100,7 @@ def main(func_args=None):
colors = [np.array(color.split(' '), np.uint8) for color in f.read().rstrip('\n').split('\n')]
# Load a network
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNetFromONNX(args.model, engine)
net.setPreferableBackend(get_backend_id(args.backend))
net.setPreferableTarget(get_target_id(args.target))
+1 -3
View File
@@ -122,9 +122,7 @@ def main(func_args=None):
# Create color checker detector
if args.model and args.config:
# Load the DNN from TensorFlow model
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNetFromTensorflow(args.model, args.config, engine)
net.setPreferableBackend(get_backend_id(args.backend))
net.setPreferableTarget(get_target_id(args.target))
+1 -3
View File
@@ -89,9 +89,7 @@ def main(func_args=None):
if args.model and args.config:
# Load the DNN from TensorFlow model
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_NEW
net = cv.dnn.readNetFromTensorflow(args.model, args.config, engine)
net.setPreferableBackend(get_backend_id(args.backend))
net.setPreferableTarget(get_target_id(args.target))