Skip to content

Commit

Permalink
E2E Tests: ImageManip node and better checks. (#140)
Browse files Browse the repository at this point in the history
* Add some checks to E2E testing.

* Use ImageManip to handle small inputs.
  • Loading branch information
kkeroo authored Nov 27, 2024
1 parent 0ccc611 commit 3c1fc50
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
57 changes: 49 additions & 8 deletions tests/end_to_end/manual.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse

import depthai as dai
from utils import get_input_shape, parse_model_slug
from utils import get_input_shape, get_num_inputs, parse_model_slug

from depthai_nodes.parsing_neural_network import ParsingNeuralNetwork

Expand All @@ -25,7 +25,8 @@

try:
device = dai.Device(dai.DeviceInfo(args.ip))
except Exception:
except Exception as e:
print(e)
print("Can't connect to the device with IP/mxid: ", args.ip)
exit(6)

Expand All @@ -41,13 +42,20 @@
)
try:
nn_archive_path = dai.getModelFromZoo(model_desc, useCached=False)
nn_archive = dai.NNArchive(nn_archive_path)
except Exception:
except Exception as e:
print(e)
print(
f"Couldn't find model {args.model_slug} for {device.getPlatform().name} in the ZOO"
)
device.close()
exit(7)
try:
nn_archive = dai.NNArchive(nn_archive_path)
except Exception as e:
print(e)
print(f"Couldn't load the model {args.model_slug} from NN archive.")
device.close()
exit(9)

else:
nn_archive = dai.NNArchive(args.nn_archive)
Expand All @@ -59,13 +67,46 @@
device.close()
exit(5)

input_size = get_input_shape(nn_archive)
if input_size[0] < 128 and input_size[1] < 128:
print("Input size is too small for the device.")
if get_num_inputs(nn_archive) > 1:
print(
"This model has more than one input. Currently, only models with one input are supported."
)
device.close()
exit(8)

try:
input_size = get_input_shape(nn_archive)
except Exception as e:
print(e)
device.close()
exit(8)

nn_w_parser = pipeline.create(ParsingNeuralNetwork).build(camera_node, nn_archive)
image_type = (
dai.ImgFrame.Type.BGR888i
if device.getPlatform().name == "RVC4"
else dai.ImgFrame.Type.BGR888p
)
manip = None

if input_size[0] % 2 != 0 or input_size[1] % 2 != 0:
manip = pipeline.create(dai.node.ImageManipV2)
manip.initialConfig.addResize(input_size[0], input_size[1])
large_input_shape = (input_size[0] * 2, input_size[1] * 2)

if input_size[0] < 128 and input_size[1] < 128:
manip = pipeline.create(dai.node.ImageManipV2)
manip.initialConfig.addResize(input_size[0], input_size[1])
large_input_shape = (input_size[0] * 4, input_size[1] * 4)

if manip:
camera_node.requestOutput(large_input_shape, type=image_type).link(
manip.inputImage
)
nn_w_parser = pipeline.create(ParsingNeuralNetwork).build(manip.out, nn_archive)
else:
nn_w_parser = pipeline.create(ParsingNeuralNetwork).build(
camera_node, nn_archive
)

head_indices = nn_w_parser._parsers.keys()

Expand Down
6 changes: 4 additions & 2 deletions tests/end_to_end/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ def test_pipelines(IP: str, ip_platform: str, nn_archive_path, slug):
)
except subprocess.CalledProcessError as e:
if e.returncode == 5:
pytest.skip(f"Model not supported on {ip_platform}.")
pytest.skip(f"Model {slug} not supported on {ip_platform}.")
elif e.returncode == 6:
pytest.skip(f"Can't connect to the device with IP/mxid: {IP}")
elif e.returncode == 7:
pytest.skip(f"Couldn't find model {slug} in the ZOO")
elif e.returncode == 8:
pytest.skip(
"The model is not supported in this test. (small input size, grayscale image, etc.)"
f"The model {slug} is not supported in this test. (small input size, grayscale image, etc.)"
)
elif e.returncode == 9:
pytest.skip(f"Couldn't load the model {slug} from NN archive.")
else:
raise RuntimeError("Pipeline crashed.") from e
except subprocess.TimeoutExpired:
Expand Down
7 changes: 7 additions & 0 deletions tests/end_to_end/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def get_input_shape(nn_archive: dai.NNArchive) -> Tuple[int, int]:
return input_shape


def get_num_inputs(nn_archive: dai.NNArchive) -> int:
"""Get the number of inputs of the model from the NN archive."""
inputs = get_inputs_from_archive(nn_archive)

return len(inputs)


def parse_model_slug(full_slug) -> Tuple[str, str]:
"""Parse the model slug into model_slug and model_version_slug."""
if ":" not in full_slug:
Expand Down

0 comments on commit 3c1fc50

Please sign in to comment.