Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 3c81c06

Browse files
committed
tests prep automatization
1 parent a7d93e6 commit 3c81c06

14 files changed

Lines changed: 128 additions & 9416 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ opencv/*
2323
ffmpeg/*
2424
!ffmpeg/.gitkeep
2525
venv
26+
tests/venv_t
27+
tests/rateme*
2628
*tar.gz
2729
*tar.bz2
2830
*.zip
2931
*.swp
3032
*.whl
33+
*.xml
3134
TODO.txt
3235
*.bin
3336
*.weights

TODO.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
# TODO list
2-
3-
**TESTS**:
4-
5-
+ Automatize model weights downloading
6-
+ Webcam open?
7-

download_all_stuff.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ red () {
1414
}
1515

1616
green "DOWNLOAD ALL STUFF"
17-
wget -c https://github.com/opencv/opencv/archive/4.2.0.tar.gz
17+
wget -c https://github.com/opencv/opencv/archive/4.2.0.tar.gz
1818
wget -c https://github.com/FFmpeg/FFmpeg/archive/n4.2.2.tar.gz
1919
wget -c https://github.com/opencv/dldt/archive/2020.1.tar.gz
2020

tests/README.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,52 @@
1-
The [rateme](https://github.com/heyml/rateme) is YOLO3 actually.
1+
# Tests for opencv-python-inference-engine wheel
22

3-
These are Intel's models: [text-detection-0004](https://github.com/opencv/open_model_zoo/blob/master/models/intel/text-detection-0004/description/text-detection-0004.md) and [text-recognition-0012](https://github.com/opencv/open_model_zoo/blob/master/models/intel/text-recognition-0012/description/text-recognition-0012.md).
3+
## Usage
44

5-
Video from here (free): <https://www.pexels.com/video/a-cattails-fluff-floats-in-air-2156021/>
5+
### Features
66

7+
Just run bash script and read output.
78

8-
**MODEL WEIGHTS SHOULD BE DOWNLOADED SEPARATELY (for now)**
9+
```bash
10+
cd tests
11+
./prepare_and_run_tests.sh
12+
```
13+
14+
### Inference speed
15+
16+
Something like below. The general idea is to test only inference speed, without preprocessing and decoding.
17+
Also, 1st inference must not count, because it will load all stuff into memory.
18+
I prefer to do such things in `ipython` or `jupyter` with `%timeit`.
19+
**NB:** be strict about BAckend and Target
20+
21+
```python
22+
import cv2
23+
from pixellink import PixelLinkDetector
24+
25+
# read img and network
26+
img = cv2.imread('helloworld.png')
27+
detector = PixelLinkDetector('text-detection-0004.xml')
28+
29+
# select target & backend, please read the documentation for details:
30+
# <https://docs.opencv.org/4.2.0/db/d30/classcv_1_1dnn_1_1Net.html#a9dddbefbc7f3defbe3eeb5dc3d3483f4>
31+
detector._net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
32+
detector._net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
33+
34+
# 1st inference does not count
35+
detector.detect(img)
36+
37+
# use magic function
38+
%timeit detector.detect(img)
39+
```
40+
41+
42+
## Models
43+
44+
+ [rateme](https://github.com/heyml/rateme) (YOLO3).
45+
+ [text-detection-0004](https://github.com/opencv/open_model_zoo/blob/master/models/intel/text-detection-0004/description/text-detection-0004.md)
46+
+ [text-recognition-0012](https://github.com/opencv/open_model_zoo/blob/master/models/intel/text-recognition-0012/description/text-recognition-0012.md).
47+
48+
## Files
49+
50+
+ `short_video.mp4` from here (free): <https://www.pexels.com/video/a-cattails-fluff-floats-in-air-2156021/>
51+
+ `dislike.jpg` from rateme repository.
52+
+ `helloworld.png` I either made it or forgot from where it downloaded from

tests/prepare_and_run_tests.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
green="\033[0;32m"
4+
red="\033[0;31m"
5+
end="\033[0m"
6+
7+
green () {
8+
echo -e "${green}${1}${end}"
9+
}
10+
11+
red () {
12+
echo -e "${red}${1}${end}"
13+
}
14+
15+
# check if (no ARG and no some appropriate files are compiled) or
16+
# (some args provided but arg1 is not existing file)
17+
# of course, you could shoot your leg here in different ways
18+
if ([ ! $# -ge 1 ] && ! $(ls ../create_wheel/dist/opencv_python_inference_engine*.whl &> /dev/null)) ||
19+
([ $# -ge 1 ] && [ ! -f $1 ]); then
20+
red "How do you suppose to run wheel tests without wheel?"
21+
red "Compile it or provide as an ARG1 to script"
22+
exit 1
23+
fi
24+
25+
26+
green "CREATE SEPARATE TEST VENV"
27+
if [ ! -d ./venv_t ]; then
28+
virtualenv --clear --always-copy -p /usr/bin/python3 ./venv_t
29+
fi
30+
31+
32+
green "INSTALLING DEPENDENCIES"
33+
if [ $1 ]; then
34+
# install ARGV1
35+
green "Installing from provided path"
36+
./venv_t/bin/pip3 install --force-reinstall "$1"
37+
else
38+
# install compiled wheel
39+
green "Installing from default path"
40+
./venv_t/bin/pip3 install --force-reinstall ../create_wheel/dist/opencv_python_inference_engine*.whl
41+
fi
42+
43+
./venv_t/bin/pip3 install -r requirements.txt
44+
45+
46+
green "GET MODELS"
47+
48+
if [ ! -d "rateme" ]; then
49+
./venv_t/bin/pip3 install --python-version 3 rateme -U --no-deps -t ./
50+
fi
51+
52+
# urls, filenames and checksums are from:
53+
# + <https://github.com/opencv/open_model_zoo/blob/2020.1/models/intel/text-detection-0004/model.yml>
54+
# + <https://github.com/opencv/open_model_zoo/blob/2020.1/models/intel/text-recognition-0012/model.yml>
55+
declare -a models=("text-detection-0004.xml"
56+
"text-detection-0004.bin"
57+
"text-recognition-0012.xml"
58+
"text-recognition-0012.bin")
59+
60+
url_start="https://download.01.org/opencv/2020/openvinotoolkit/2020.1/open_model_zoo/models_bin/1"
61+
62+
for i in "${models[@]}"; do
63+
if [ ! -f $i ]; then
64+
wget "${url_start}/${i%.*}/FP32/${i}"
65+
else
66+
sha256sum -c "${i}.sha256sum"
67+
fi
68+
done
69+
70+
71+
green "RUN TESTS with ./venv_t/bin/python ./tests.py"
72+
./venv_t/bin/python ./tests.py

tests/rateme/__init__.py

Whitespace-only changes.

tests/rateme/rateme.cfg

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)