Press "Enter" to skip to content

openvino模型学习-从模型转化流水线制作

本站内容均来自兴趣收集,如不慎侵害的您的相关权益,请留言告知,我们将尽快删除.谢谢.

1、模型转换

 

(/home/kewei/openvino/openvion_venv) [email protected]:~/openvino/OV-200-lab-files/02/exercise-1$ cd ~/intel/openvino_2021/deployment_tools/model_optimizer/
(/home/kewei/openvino/openvion_venv) [email protected]:~/intel/openvino_2021/deployment_tools/model_optimizer$ mo_caffe.py --input_model $lab_dir/public/resnet-50/resnet-50.caffemodel --output_dir  $lab_dir
Model Optimizer arguments:
Common parameters:
        - Path to the Input Model:      /home/kewei/openvino/OV-200-lab-files/02/exercise-1//public/resnet-50/resnet-50.caffemodel
        - Path for generated IR:        /home/kewei/openvino/OV-200-lab-files/02/exercise-1/
        - IR output name:       resnet-50
        - Log level:    ERROR
        - Batch:        Not specified, inherited from the model
        - Input layers:         Not specified, inherited from the model
        - Output layers:        Not specified, inherited from the model
        - Input shapes:         Not specified, inherited from the model
        - Mean values:  Not specified
        - Scale values:         Not specified
        - Scale factor:         Not specified
        - Precision of IR:      FP32
        - Enable fusing:        True
        - Enable grouped convolutions fusing:   True
        - Move mean values to preprocess section:       None
        - Reverse input channels:       False
Caffe specific parameters:
        - Path to Python Caffe* parser generated from caffe.proto:      /home/kewei/intel/openvino_2021/deployment_tools/model_optimizer/mo/utils/../front/caffe/proto
        - Enable resnet optimization:   True
        - Path to the Input prototxt:   /home/kewei/openvino/OV-200-lab-files/02/exercise-1//public/resnet-50/resnet-50.prototxt
        - Path to CustomLayersMapping.xml:      /home/kewei/intel/openvino_2021/deployment_tools/model_optimizer/mo/utils/../../extensions/front/caffe/CustomLayersMapping.xml
        - Path to a mean file:  Not specified
        - Offsets for a mean file:      Not specified
        - Inference Engine found in:    /home/kewei/intel/openvino_2021/python/python3.7/openvino
Inference Engine version:       2021.4.2-3974-e2a469a3450-releases/2021/4
Model Optimizer version:        2021.4.2-3974-e2a469a3450-releases/2021/4
/home/kewei/intel/openvino_2021/deployment_tools/model_optimizer/mo/utils/versions_checker.py:170: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  req_ver = LooseVersion(required_v)
/home/kewei/openvino/openvion_venv/lib/python3.7/site-packages/setuptools/_distutils/version.py:351: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  other = LooseVersion(other)
[ SUCCESS ] Generated IR version 10 model.
[ SUCCESS ] XML file: /home/kewei/openvino/OV-200-lab-files/02/exercise-1/resnet-50.xml
[ SUCCESS ] BIN file: /home/kewei/openvino/OV-200-lab-files/02/exercise-1/resnet-50.bin
[ SUCCESS ] Total execution time: 17.21 seconds. 
[ SUCCESS ] Memory consumed: 638 MB. 
It's been a while, check for a new version of Intel(R) Distribution of OpenVINO(TM) toolkit here https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit/download.html?cid=other&source=prod&campid=ww_2022_bu_IOTG_OpenVINO-2022-1&content=upg_all&medium=organic or on the GitHub*

 

可以看到生成了如上文件。

 

进行推理:

 

python3 classification_sample_async.py --i images/car.png -m resnet-50.xml --labels squeezenet1.1.labels -d CPU

 

2、wsl使用netron查看神经网络:

 

pip install netron
netron ~/openvino/OV-200-lab-files/02/exercise-1/public/squeezenet1.1/squeezenet1.1.prototxt

 

打开http://localhost:8080

 

可以看到网络的详细构成了。

 

3、目标检测是计算机视觉核心任务之一,也是最常见与应用最广泛的视觉场景。OpenVINO已经提供了以下通用场景下的目标检测包括人脸检测、行人检测、物体检测、车辆检测、车牌检测等,一个图像目标检测显示示意图如下:

 

相比图像分类,目标检测多了每个对象位置信息,所以简单的认为目标检测=图像分类+Box位置信息。第一个深度学习相关的目标检测网络正是基于这样思想的RCNN模型,但是它的缺点是无法实时,所以2015年底有人提出了一个实时目标检测网络Single Shot MultiBox Detector缩写为SSD。

 

4、剪枝实验,得到的小模型仍然保持较好的精度

 

5、打印可用设备实验

 

第 12代智能英特尔® 酷睿™ 台式机处理器能够通过增强型 Gaussian & Neural Accelerator 3.0 (GNA)

 

6、ffmpeg用法

 

ffmpeg -i output_1.avi output_1.mp4

 

转换为mp4后,大小由100多兆变为了40多兆

 

7、推理语句,实际就一句

 

this_time1 = time.time()
        exec_net.start_async(request_id=next_request_id, inputs=feed_dict)
        this_time2 = time.time()
        print(this_time2-this_time1)

 

8、性能测试

 

Task 1:

 

测试ssd-mobilenet模型在2推理请求,2 streams下的性能

 

python3 benchmark_app.py -m models/ssd-mobilenet.xml -i images/ -t 20  -nstreams 2 -nireq 2

 

[ INFO ] First inference took 27.14 ms

 

[Step 11/11] Dumping statistics report

 

Count: 1272 iterations

 

Duration: 20055.84 ms

 

Latency: 29.64 ms

 

Throughput: 63.42 FPS

 

Task 2:

 

测试resnet-50模型在batch为4,异步推理的性能。并且将perf_counts和progress 选项设置为可见。

 

python3 benchmark_app.py -m models/resnet-50.xml -i images/ -t 20 -api async -progress True -pc True -b 4

 

Total time: 280361 microseconds

 

Total CPU time: 280361 microseconds

 

Count: 284 iterations

 

Duration: 20229.78 ms

 

Latency: 282.11 ms

 

Throughput: 56.15 FPS

 

9、AttributeError: ‘openvino.inference_engine.ie_api.IENetwork’ object has no attribute ‘layers’

 

对于layer新版本openvino已不支持,可行的做法是先注释掉

 

然后就跑起来了

 

10、报错: invalid optionnd_classification-file.sh: line 7: set: –

 

在运行bash face_detection_and_classification-file.sh出错

 

Linux下运行sh文件出现 invalid option set: -问题的原因主要是因为你可能在Windows环境下打开过.sh文件,那幺无形中就会改变文件的一些属性,比如换行符的问题。这种情况极大的概率出现在在Windows环境下,打开,修改并保存了.sh文件。

 

解决方案是:在Linux环境下,在你的目标文件夹下,键入命令行

 

在你的目标文件夹下,键入命令行

 

vi ./*.sh

 

这里的*是你的sh文件名,记得修改。

 

进入之后,在sh文件首行加入一句话 set ff=UNIX

 

保存并退出

 

再在你的目标文件加下,键入命令行

 

dos2unix -q *.sh

 

或者

 

sed -i 's/\r//' *.sh

 

同样这里的*是具体文件名,需要修改。

 

这样就可以正常运行了。

 

bash *.sh

Be First to Comment

发表评论

您的电子邮箱地址不会被公开。