mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -456,10 +456,6 @@ class dnn_test(NewOpenCVTests):
|
||||
"Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")
|
||||
|
||||
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)
|
||||
|
||||
for backend, target in self.dnnBackendsAndTargets:
|
||||
@@ -470,10 +466,63 @@ class dnn_test(NewOpenCVTests):
|
||||
net.setPreferableBackend(backend)
|
||||
net.setPreferableTarget(target)
|
||||
|
||||
# Check whether 3d shape is parsed correctly for setInput
|
||||
net.setInput(input)
|
||||
real_output = net.forward()
|
||||
|
||||
normAssert(self, real_output, gold_output, "", getDefaultThreshold(target))
|
||||
# Case 0: test API `forward(const String& outputName = String()`
|
||||
real_output = net.forward() # Retval is a np.array of shape [2, 5, 3]
|
||||
normAssert(self, real_output, gold_output, "Case 1", getDefaultThreshold(target))
|
||||
|
||||
'''
|
||||
Pre-allocate output memory with correct shape.
|
||||
Normally Python users do not use in this way,
|
||||
but we have to test it since we design API in this way
|
||||
'''
|
||||
# Case 1: a np.array with a string of output name.
|
||||
# It tests API `forward(OutputArrayOfArrays outputBlobs, const String& outputName = String()`
|
||||
# when outputBlobs is a np.array and we expect it to be the only output.
|
||||
real_output = np.empty([2, 5, 3], dtype=np.float32)
|
||||
real_output = net.forward(real_output, "237") # Retval is a tuple with a np.array of shape [2, 5, 3]
|
||||
normAssert(self, real_output, gold_output, "Case 1", getDefaultThreshold(target))
|
||||
|
||||
# Case 2: a tuple of np.array with a string of output name.
|
||||
# It tests API `forward(OutputArrayOfArrays outputBlobs, const String& outputName = String()`
|
||||
# when outputBlobs is a container of several np.array and we expect to save all outputs accordingly.
|
||||
real_output = tuple(np.empty([2, 5, 3], dtype=np.float32))
|
||||
real_output = net.forward(real_output, "237") # Retval is a tuple with a np.array of shape [2, 5, 3]
|
||||
normAssert(self, real_output, gold_output, "Case 2", getDefaultThreshold(target))
|
||||
|
||||
# Case 3: a tuple of np.array with a string of output name.
|
||||
# It tests API `forward(OutputArrayOfArrays outputBlobs, const std::vector<String>& outBlobNames)`
|
||||
real_output = tuple(np.empty([2, 5, 3], dtype=np.float32))
|
||||
# Note that it does not support parsing a list , e.g. ["237"]
|
||||
real_output = net.forward(real_output, ("237")) # Retval is a tuple with a np.array of shape [2, 5, 3]
|
||||
normAssert(self, real_output, gold_output, "Case 3", getDefaultThreshold(target))
|
||||
|
||||
def test_set_param_3d(self):
|
||||
model_path = self.find_dnn_file('dnn/onnx/models/matmul_3d_init.onnx')
|
||||
input_file = self.find_dnn_file('dnn/onnx/data/input_matmul_3d_init.npy')
|
||||
output_file = self.find_dnn_file('dnn/onnx/data/output_matmul_3d_init.npy')
|
||||
|
||||
input = np.load(input_file)
|
||||
output = np.load(output_file)
|
||||
|
||||
for backend, target in self.dnnBackendsAndTargets:
|
||||
printParams(backend, target)
|
||||
|
||||
net = cv.dnn.readNet(model_path)
|
||||
|
||||
node_name = net.getLayerNames()[0]
|
||||
w = net.getParam(node_name, 0) # returns the original tensor of three-dimensional shape
|
||||
net.setParam(node_name, 0, w) # set param once again to see whether tensor is converted with correct shape
|
||||
|
||||
net.setPreferableBackend(backend)
|
||||
net.setPreferableTarget(target)
|
||||
|
||||
net.setInput(input)
|
||||
res_output = net.forward()
|
||||
|
||||
normAssert(self, output, res_output, "", getDefaultThreshold(target))
|
||||
|
||||
def test_scalefactor_assign(self):
|
||||
params = cv.dnn.Image2BlobParams()
|
||||
|
||||
Reference in New Issue
Block a user