alexander | f42f568 | 2021-07-16 11:30:56 +0100 | [diff] [blame] | 1 | # Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 2 | # SPDX-License-Identifier: MIT |
| 3 | |
| 4 | import os |
| 5 | import ntpath |
| 6 | |
| 7 | import urllib.request |
| 8 | import zipfile |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 9 | import pytest |
| 10 | |
| 11 | script_dir = os.path.dirname(__file__) |
alexander | f42f568 | 2021-07-16 11:30:56 +0100 | [diff] [blame] | 12 | |
| 13 | |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 14 | @pytest.fixture(scope="session") |
alexander | f42f568 | 2021-07-16 11:30:56 +0100 | [diff] [blame] | 15 | def test_data_folder(): |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 16 | """ |
| 17 | This fixture returns path to folder with shared test resources among all tests |
| 18 | """ |
| 19 | |
| 20 | data_dir = os.path.join(script_dir, "testdata") |
| 21 | if not os.path.exists(data_dir): |
| 22 | os.mkdir(data_dir) |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 23 | |
| 24 | sys_arch = os.uname().machine |
| 25 | if sys_arch == "x86_64": |
| 26 | libarmnn_url = "https://github.com/ARM-software/armnn/releases/download/v21.11/ArmNN-linux-x86_64.tar.gz" |
| 27 | else: |
| 28 | libarmnn_url = "https://github.com/ARM-software/armnn/releases/download/v21.11/ArmNN-linux-aarch64.tar.gz" |
| 29 | |
| 30 | |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 31 | files_to_download = ["https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/messi5.jpg", |
| 32 | "https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/basketball1.png", |
| 33 | "https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/Megamind.avi", |
alexander | f42f568 | 2021-07-16 11:30:56 +0100 | [diff] [blame] | 34 | "https://github.com/ARM-software/ML-zoo/raw/master/models/object_detection/ssd_mobilenet_v1/tflite_uint8/ssd_mobilenet_v1.tflite", |
| 35 | "https://git.mlplatform.org/ml/ethos-u/ml-embedded-evaluation-kit.git/plain/resources/kws/samples/yes.wav", |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 36 | "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-speech-sdk/master/sampledata/audiofiles/myVoiceIsMyPassportVerifyMe04.wav", |
| 37 | "https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/int8/prediction/1?lite-format=tflite", |
| 38 | "https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/int8/transfer/1?lite-format=tflite", |
| 39 | libarmnn_url |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 40 | ] |
| 41 | |
| 42 | for file in files_to_download: |
| 43 | path, filename = ntpath.split(file) |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 44 | if filename == '1?lite-format=tflite' and 'prediction' in file: |
| 45 | filename = 'style_predict.tflite' |
| 46 | elif filename == '1?lite-format=tflite' and 'transfer' in file: |
| 47 | filename = 'style_transfer.tflite' |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 48 | file_path = os.path.join(data_dir, filename) |
| 49 | if not os.path.exists(file_path): |
| 50 | print("\nDownloading test file: " + file_path + "\n") |
| 51 | urllib.request.urlretrieve(file, file_path) |
| 52 | |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 53 | path, filename = ntpath.split(libarmnn_url) |
| 54 | file_path = os.path.join(data_dir, filename) |
| 55 | os.system(f"tar -xvzf {file_path} -C {data_dir} ") |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 56 | |
| 57 | return data_dir |