如何查看已经编译了那些graph 用于NCS加载
ai@ai-usb:~/ai_ws$ find -name graph
./ncappzoo/caffe/GoogLeNet/graph
./ncappzoo/caffe/TinyYolo/graph
./ncappzoo/caffe/SqueezeNet/graph
./ncappzoo/caffe/SSD_MobileNet/graph
./ncappzoo/caffe/GenderNet/graph
./ncappzoo/tensorflow/mobilenets/graph
./ncsdk/examples/caffe/GoogLeNet/graph
./ncsdk/examples/caffe/AlexNet/graph
./ncsdk/examples/caffe/SqueezeNet/graph
./ncsdk/examples/tensorflow/inception_v3/graph
./ncsdk/examples/tensorflow/inception_v1/graph
能看到graph文件就说明已经用NCSDK中提供的编译工具编译了原始的神经网络文件eg..caffemodel+.prototxt –> graph。
问:graph文件干吗用的?
答:用来加载到NCS上作推理的,加载方法参考pythonAPI:
Step 2: Load a graph file onto the NCS device
def load_graph( device ):
# Read the graph file into a buffer.
with open( GRAPH_PATH, mode='rb' ) as f:
blob = f.read()
# Load the graph buffer into the NCS.
graph = device.AllocateGraph( blob )
return graph
如何使用ncappzoo的examples
1.进入对应的demo文件夹:
pythonAPI DEMO:
/ncappzoo/apps
Caffe DEMO:
/ncappzoo/caffe
TensorFlow DEMO:
/ncappzoo/tensorflow
2.执行目录下的run.py文件即可。(如果是第一次运行,先执行make)
每个DEMO对应的都有makefile,执行make可以自动从网络上下载’对应的’神经网络模型,并用NCSDK的工具编译为可以加载到NCS设备上的graph文件。
3.以image-classifier为例子:
仅执行例子
cd ai_ws/ncappzoo/apps/image-classifier/
./run.py
or
第一次运行
cd ai_ws/ncappzoo/apps/image-classifier/
make
./run.py
已经发现的小BUG:
如果单独只是运行ncappzoo或者ncsdk的examples,那么需要去掉ROS的setup.bash打开终端才可以。否则会碰到以下错误:
Traceback (most recent call last):
File "./run.py", line 9, in <module>
import cv2
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
- 用gedit 打开 .bashrc 文件
用 # 注释掉:(有关ROS的)
#source /opt/ros/kinetic/setup.bash
#source ~/catkin_ws/devel/setup.bash
打开一个新的终端,执行之前的方法(进入对应目录,跑run.py)即可
阳光明媚 备 2018-01-25日
AgeNet 年龄推断 Demo:
插上NCS设备
cd ~/ai_ws/ncappzoo/caffe/AgeNet/
make run (仅首次)
./run.py
说明:这个Demo运行时会从网络下载一个227*227的头像图片,存放在自己的目录下(~/ai_ws/ncappzoo/caffe/AgeNet/image.jpg),可以打开run.py文件查看:46行,就是它下载图片的地址。
运行结果(我已注释了从网络下载image.jpg的部分):
ai@ai-usb:~/ai_ws/ncappzoo/caffe/AgeNet$ ./run.py
Device 0 Address: 1 - VID/PID 03e7:2150
Starting wait for connect with 2000ms timeout
Found Address: 1 - VID/PID 03e7:2150
Found EP 0x81 : max packet size is 512 bytes
Found EP 0x01 : max packet size is 512 bytes
Found and opened device
Performing bulk write of 865724 bytes…
Successfully sent 865724 bytes of data in 89.961487 ms (9.177469 MB/s)
Boot successful, device address 1
Found Address: 1 - VID/PID 03e7:f63b
done
Booted 1 -> VSC
——- predictions ——–
the age range is 25-32 with confidence of 99.9%
ai@ai-usb:~/ai_ws/ncappzoo/caffe/AgeNet$