aboutsummaryrefslogtreecommitdiff
path: root/python/pyarmnn/examples/common/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/pyarmnn/examples/common/tests')
-rw-r--r--python/pyarmnn/examples/common/tests/conftest.py40
-rw-r--r--python/pyarmnn/examples/common/tests/context.py7
-rw-r--r--python/pyarmnn/examples/common/tests/test_network_executor.py24
-rw-r--r--python/pyarmnn/examples/common/tests/test_utils.py19
4 files changed, 90 insertions, 0 deletions
diff --git a/python/pyarmnn/examples/common/tests/conftest.py b/python/pyarmnn/examples/common/tests/conftest.py
new file mode 100644
index 0000000000..5e027a0125
--- /dev/null
+++ b/python/pyarmnn/examples/common/tests/conftest.py
@@ -0,0 +1,40 @@
+# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+# SPDX-License-Identifier: MIT
+
+import os
+import ntpath
+
+import urllib.request
+import zipfile
+
+import pytest
+
+script_dir = os.path.dirname(__file__)
+@pytest.fixture(scope="session")
+def test_data_folder(request):
+ """
+ This fixture returns path to folder with shared test resources among all tests
+ """
+
+ data_dir = os.path.join(script_dir, "testdata")
+ if not os.path.exists(data_dir):
+ os.mkdir(data_dir)
+
+ files_to_download = ["https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/messi5.jpg",
+ "https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/basketball1.png",
+ "https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/Megamind.avi",
+ "https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip"
+ ]
+
+ for file in files_to_download:
+ path, filename = ntpath.split(file)
+ file_path = os.path.join(data_dir, filename)
+ if not os.path.exists(file_path):
+ print("\nDownloading test file: " + file_path + "\n")
+ urllib.request.urlretrieve(file, file_path)
+
+ # Any unzipping needed, and moving around of files
+ with zipfile.ZipFile(os.path.join(data_dir, "coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip"), 'r') as zip_ref:
+ zip_ref.extractall(data_dir)
+
+ return data_dir
diff --git a/python/pyarmnn/examples/common/tests/context.py b/python/pyarmnn/examples/common/tests/context.py
new file mode 100644
index 0000000000..72246c03bf
--- /dev/null
+++ b/python/pyarmnn/examples/common/tests/context.py
@@ -0,0 +1,7 @@
+import os
+import sys
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
+
+import cv_utils
+import network_executor
+import utils
diff --git a/python/pyarmnn/examples/common/tests/test_network_executor.py b/python/pyarmnn/examples/common/tests/test_network_executor.py
new file mode 100644
index 0000000000..e27b382078
--- /dev/null
+++ b/python/pyarmnn/examples/common/tests/test_network_executor.py
@@ -0,0 +1,24 @@
+# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+# SPDX-License-Identifier: MIT
+
+import os
+
+import cv2
+
+from context import network_executor
+from context import cv_utils
+
+
+def test_execute_network(test_data_folder):
+ model_path = os.path.join(test_data_folder, "detect.tflite")
+ backends = ["CpuAcc", "CpuRef"]
+
+ executor = network_executor.ArmnnNetworkExecutor(model_path, backends)
+ img = cv2.imread(os.path.join(test_data_folder, "messi5.jpg"))
+ input_tensors = cv_utils.preprocess(img, executor.input_binding_info)
+
+ output_result = executor.run(input_tensors)
+
+ # Ensure it detects a person
+ classes = output_result[1]
+ assert classes[0][0] == 0
diff --git a/python/pyarmnn/examples/common/tests/test_utils.py b/python/pyarmnn/examples/common/tests/test_utils.py
new file mode 100644
index 0000000000..28d68ea235
--- /dev/null
+++ b/python/pyarmnn/examples/common/tests/test_utils.py
@@ -0,0 +1,19 @@
+# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+# SPDX-License-Identifier: MIT
+
+import os
+
+from context import cv_utils
+from context import utils
+
+
+def test_get_source_encoding(test_data_folder):
+ video_file = os.path.join(test_data_folder, "Megamind.avi")
+ video, video_writer, frame_count = cv_utils.init_video_file_capture(video_file, "/tmp")
+ assert cv_utils.get_source_encoding_int(video) == 1145656920
+
+
+def test_read_existing_labels_file(test_data_folder):
+ label_file = os.path.join(test_data_folder, "labelmap.txt")
+ labels_map = utils.dict_labels(label_file)
+ assert labels_map is not None