本帖最后由 独活草 于 2018-8-29 10:27 编辑
今天测试了一下角蜂鸟内嵌的数字识别模型,写了个简单的代码,用于识别官网提供的数字图片
大概操作步骤 :
1 在 misc 目录下新建目录mnist_test ,添加图片
;
2 在 apps 目录下 新建目录mytest 新建mnist_test1.py , 编辑如下代码:
#加载OpenCV、Numpy以及角蜂鸟HSAPI
import cv2, sys, numpy as np
sys.path.append('../../../')
import hsapi as hs
# 初始化角蜂鸟、设定内置加载模型、识别对象图片的根目录
net = hs.HS('mnist')
imgroot = '../../misc/mnist_test/4.jpg'
print('mnist test 1')
img = cv2.imread(imgroot)
result = net.run(img)
print(result[1])
net.q
3 终端输入命令:
sudo chmod 777 mnist_test1.py
python3 mnist_test1.py
可以惊奇的看到效果:
·············································································································
注意:
代码倒数第二行,如果使用 print(result)
则会返回结果:
| ======= Horned Sungem ======== |
| Device index [0] |
| Graph:mnist |
| ../../graphs/graph_mnist |
| Model loaded to Python |
| Model allocated to device |
| ============================== |
my mnist test 1
[array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 2, 0, 0,
7, 3, 0, 2, 12, 0, 11, 1, 2, 3, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 1, 6, 0,
2, 10, 0, 2, 0, 4, 0, 0, 0, 11, 5, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 8,
0, 0, 14, 0, 3, 13, 7, 14, 4, 0, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 3, 9, 0,
0, 0, 0, 6, 5, 0, 0, 0, 2, 5, 9, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0,
1, 1, 12, 0, 16, 17, 11, 0, 0, 25, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 19, 4, 0, 38, 135,
226, 254, 240, 255, 247, 244, 252, 239, 14, 0, 13, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 209, 255, 235,
237, 255, 250, 249, 253, 255, 245, 255, 151, 16, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 49, 228, 255, 237, 232,
139, 110, 248, 142, 23, 106, 255, 243, 255, 96, 3, 0, 0,
0, 0],
[ 0, 4, 3, 0, 0, 3, 0, 14, 157, 255, 255, 162, 20,
6, 7, 190, 74, 0, 10, 34, 203, 255, 114, 1, 0, 0,
0, 0],
[ 0, 0, 0, 0, 7, 2, 11, 76, 255, 237, 202, 183, 0,
2, 0, 129, 34, 26, 0, 76, 237, 250, 102, 1, 0, 0,
0, 0],
[ 2, 0, 0, 0, 7, 0, 13, 117, 255, 255, 240, 34, 10,
0, 21, 0, 9, 0, 11, 195, 255, 240, 5, 12, 0, 0,
0, 0],
[ 3, 2, 0, 0, 7, 0, 5, 110, 255, 233, 74, 13, 3,
1, 0, 11, 6, 91, 218, 255, 225, 69, 27, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 11, 0, 3, 70, 235, 255, 163, 55, 35,
26, 173, 210, 196, 241, 243, 213, 100, 1, 0, 0, 0, 0,
0, 0],
[ 0, 0, 1, 0, 3, 4, 0, 15, 136, 255, 250, 229, 236,
216, 255, 250, 255, 238, 177, 16, 0, 0, 0, 11, 0, 0,
0, 0],
[ 2, 0, 4, 0, 0, 0, 0, 0, 22, 166, 251, 244, 254,
253, 250, 250, 255, 210, 51, 22, 3, 4, 0, 5, 0, 0,
0, 0],
[ 1, 0, 5, 2, 0, 6, 8, 2, 0, 28, 232, 255, 255,
247, 255, 246, 251, 255, 252, 104, 0, 0, 6, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 24, 200, 243, 239, 207,
97, 113, 249, 212, 239, 255, 204, 75, 0, 0, 12, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 102, 247, 253, 92, 0,
0, 19, 121, 57, 91, 250, 241, 190, 1, 0, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 197, 255, 192, 4, 0,
11, 0, 0, 7, 3, 208, 241, 236, 0, 8, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 226, 247, 235, 21, 9,
0, 7, 16, 0, 24, 210, 255, 201, 4, 0, 3, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 231, 237, 255, 40, 0,
11, 0, 0, 19, 131, 255, 246, 96, 0, 0, 2, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 94, 255, 243, 127, 34,
0, 5, 59, 168, 248, 250, 124, 0, 0, 15, 2, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 49, 242, 245, 247, 208,
135, 177, 251, 255, 234, 140, 27, 0, 5, 9, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 2, 34, 238, 255, 249,
255, 255, 249, 246, 134, 6, 0, 2, 6, 0, 10, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 98, 116, 246,
247, 246, 159, 24, 12, 0, 0, 0, 4, 1, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 7,
0, 16, 1, 9, 3, 0, 0, 2, 5, 4, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 4, 9, 0,
0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 0, 0, 0,
0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 4, 8,
13, 2, 6, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0,
0, 0]], dtype=uint8), 8]
这说明 执行 net.run(img),返回的 result 包含两个参数(图像矩阵,检测结果),分别放置在 result[0] 与 result[1] 。
|