1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin
2021-08-07 17:25:06 +00:00
18 changed files with 111 additions and 7 deletions
@@ -116,6 +116,12 @@ String dumpRange(const Range& argument)
}
}
CV_WRAP static inline
String testReservedKeywordConversion(int positional_argument, int lambda = 2, int from = 3)
{
return format("arg=%d, lambda=%d, from=%d", positional_argument, lambda, from);
}
CV_WRAP static inline
void testRaiseGeneralException()
{
+36
View File
@@ -62,6 +62,12 @@ def printParams(backend, target):
}
print('%s/%s' % (backendNames[backend], targetNames[target]))
def getDefaultThreshold(target):
if target == cv.dnn.DNN_TARGET_OPENCL_FP16 or target == cv.dnn.DNN_TARGET_MYRIAD:
return 4e-3
else:
return 1e-5
testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False))
g_dnnBackendsAndTargets = None
@@ -373,5 +379,35 @@ class dnn_test(NewOpenCVTests):
cv.dnn_unregisterLayer('CropCaffe')
# check that dnn module can work with 3D tensor as input for network
def test_input_3d(self):
model = self.find_dnn_file('dnn/onnx/models/hidden_lstm.onnx')
input_file = self.find_dnn_file('dnn/onnx/data/input_hidden_lstm.npy')
output_file = self.find_dnn_file('dnn/onnx/data/output_hidden_lstm.npy')
if model is None:
raise unittest.SkipTest("Missing DNN test files (dnn/onnx/models/hidden_lstm.onnx). "
"Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")
if input_file is None or output_file is None:
raise unittest.SkipTest("Missing DNN test files (dnn/onnx/data/{input/output}_hidden_lstm.npy). "
"Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")
net = cv.dnn.readNet(model)
input = np.load(input_file)
# we have to expand the shape of input tensor because Python bindings cut 3D tensors to 2D
# it should be fixed in future. see : https://github.com/opencv/opencv/issues/19091
# please remove `expand_dims` after that
input = np.expand_dims(input, axis=3)
gold_output = np.load(output_file)
net.setInput(input)
for backend, target in self.dnnBackendsAndTargets:
printParams(backend, target)
net.setPreferableBackend(backend)
net.setPreferableTarget(target)
real_output = net.forward()
normAssert(self, real_output, gold_output, "", getDefaultThreshold(target))
if __name__ == '__main__':
NewOpenCVTests.bootstrap()
+12
View File
@@ -214,6 +214,16 @@ simple_argtype_mapping = {
"Stream": ArgTypeInfo("Stream", FormatStrings.object, 'Stream::Null()', True),
}
# Set of reserved keywords for Python. Can be acquired via the following call
# $ python -c "help('keywords')"
# Keywords that are reserved in C/C++ are excluded because they can not be
# used as variables identifiers
python_reserved_keywords = {
"True", "None", "False", "as", "assert", "def", "del", "elif", "except", "exec",
"finally", "from", "global", "import", "in", "is", "lambda", "nonlocal",
"pass", "print", "raise", "with", "yield"
}
def normalize_class_name(name):
return re.sub(r"^cv\.", "", name).replace(".", "_")
@@ -371,6 +381,8 @@ class ArgInfo(object):
def __init__(self, arg_tuple):
self.tp = handle_ptr(arg_tuple[0])
self.name = arg_tuple[1]
if self.name in python_reserved_keywords:
self.name += "_"
self.defval = arg_tuple[2]
self.isarray = False
self.arraylen = 0
+4 -2
View File
@@ -979,7 +979,8 @@ class CppHeaderParser(object):
has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0
if has_mat:
_, _, _, gpumat_decl = self.parse_stmt(stmt, token, mat="cuda::GpuMat", docstring=docstring)
decls.append(gpumat_decl)
if gpumat_decl != decl:
decls.append(gpumat_decl)
if self._generate_umat_decls:
# If function takes as one of arguments Mat or vector<Mat> - we want to create the
@@ -988,7 +989,8 @@ class CppHeaderParser(object):
has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0
if has_mat:
_, _, _, umat_decl = self.parse_stmt(stmt, token, mat="UMat", docstring=docstring)
decls.append(umat_decl)
if umat_decl != decl:
decls.append(umat_decl)
docstring = ""
if stmt_type == "namespace":
+17
View File
@@ -464,6 +464,23 @@ class Arguments(NewOpenCVTests):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpRange(not_convertible)
def test_reserved_keywords_are_transformed(self):
default_lambda_value = 2
default_from_value = 3
format_str = "arg={}, lambda={}, from={}"
self.assertEqual(
cv.utils.testReservedKeywordConversion(20), format_str.format(20, default_lambda_value, default_from_value)
)
self.assertEqual(
cv.utils.testReservedKeywordConversion(10, lambda_=10), format_str.format(10, 10, default_from_value)
)
self.assertEqual(
cv.utils.testReservedKeywordConversion(10, from_=10), format_str.format(10, default_lambda_value, 10)
)
self.assertEqual(
cv.utils.testReservedKeywordConversion(20, lambda_=-4, from_=12), format_str.format(20, -4, 12)
)
class SamplesFindFile(NewOpenCVTests):