void expandMid(const std::string& prefix, opencv_onnx::NodeProto& node_proto,
const std::string& input, size_t n);
+ void addNegation(const LayerParams& layerParams, opencv_onnx::NodeProto& node_proto, int input_id);
public:
-
- ONNXImporter(Net& net, const char *onnxFile)
- : dstNet(net), dispatch(buildDispatchMap())
- {
- hasDynamicShapes = false;
- CV_Assert(onnxFile);
- CV_LOG_DEBUG(NULL, "DNN/ONNX: processing ONNX model from file: " << onnxFile);
-
- std::fstream input(onnxFile, std::ios::in | std::ios::binary);
- if (!input)
- {
- CV_Error(Error::StsBadArg, cv::format("Can't read ONNX file: %s", onnxFile));
- }
-
- if (!model_proto.ParseFromIstream(&input))
- {
- CV_Error(Error::StsUnsupportedFormat, cv::format("Failed to parse ONNX model: %s", onnxFile));
- }
-
- populateNet();
- }
-
- ONNXImporter(Net& net, const char* buffer, size_t sizeBuffer)
- : dstNet(net), dispatch(buildDispatchMap())
- {
- hasDynamicShapes = false;
- CV_LOG_DEBUG(NULL, "DNN/ONNX: processing in-memory ONNX model (" << sizeBuffer << " bytes)");
-
- struct _Buf : public std::streambuf
- {
- _Buf(const char* buffer, size_t sizeBuffer)
- {
- char* p = const_cast<char*>(buffer);
- setg(p, p, p + sizeBuffer);
- }
- };
-
- _Buf buf(buffer, sizeBuffer);
- std::istream input(&buf);
-
- if (!model_proto.ParseFromIstream(&input))
- CV_Error(Error::StsUnsupportedFormat, "Failed to parse onnx model from in-memory byte array.");
-
- populateNet();
- }
+ ONNXImporter(Net& net, const char *onnxFile);
+ ONNXImporter(Net& net, const char* buffer, size_t sizeBuffer);
void populateNet();
testONNXModels("conv_resize_pool_1d");
}
+ TEST_P(Test_ONNX_layers, SubFromConst)
+ {
+ testONNXModels("sub_from_const1");
+ testONNXModels("sub_from_const_eltwise");
+ testONNXModels("sub_from_const_broadcast");
+ }
+
++
+TEST_P(Test_ONNX_layers, Quantized_Convolution)
+{
+ testONNXModels("quantized_conv_uint8_weights", npy, 0.004, 0.02);
+ testONNXModels("quantized_conv_int8_weights", npy, 0.03, 0.5);
+ testONNXModels("quantized_conv_per_channel_weights", npy, 0.06, 0.4);
+}
+
+TEST_P(Test_ONNX_layers, Quantized_MatMul)
+{
+ testONNXModels("quantized_matmul_uint8_weights", npy, 0.005, 0.007);
+ testONNXModels("quantized_matmul_int8_weights", npy, 0.06, 0.2);
+ testONNXModels("quantized_matmul_per_channel_weights", npy, 0.06, 0.22);
+}
+
+TEST_P(Test_ONNX_layers, Quantized_MatMul_Variable_Weights)
+{
+ // Unsupported
+ EXPECT_THROW(
+ {
+ testONNXModels("quantized_matmul_variable_inputs");
+ }, cv::Exception);
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Eltwise)
+{
+ testONNXModels("quantized_eltwise");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Eltwise_Scalar)
+{
+ testONNXModels("quantized_eltwise_scalar");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Eltwise_Broadcast)
+{
+ testONNXModels("quantized_eltwise_broadcast");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_LeakyReLU)
+{
+ testONNXModels("quantized_leaky_relu");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Sigmoid)
+{
+ testONNXModels("quantized_sigmoid");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_MaxPool)
+{
+ testONNXModels("quantized_maxpool");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_AvgPool)
+{
+ testONNXModels("quantized_avgpool");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Split)
+{
+ testONNXModels("quantized_split");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Pad)
+{
+ testONNXModels("quantized_padding");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Reshape)
+{
+ testONNXModels("quantized_reshape");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Transpose)
+{
+ testONNXModels("quantized_transpose");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Squeeze)
+{
+ testONNXModels("quantized_squeeze");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Unsqueeze)
+{
+ testONNXModels("quantized_unsqueeze");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Resize)
+{
+ testONNXModels("quantized_resize_nearest");
+ testONNXModels("quantized_resize_bilinear", npy, 2e-4, 0.003);
+ testONNXModels("quantized_resize_bilinear_align", npy, 3e-4, 0.003);
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Concat)
+{
+ testONNXModels("quantized_concat");
+ testONNXModels("quantized_concat_const_blob");
+}
+
+TEST_P(Test_ONNX_layers, Quantized_Constant)
+{
+ testONNXModels("quantized_constant", npy, 0.002, 0.008);
+}
+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
class Test_ONNX_nets : public Test_ONNX_layers