在Raspberry Pi 3上使用Fish Eye:启动用于计算机视觉的预训练DL模型

下午好

在一系列文章的续篇中:关于将鱼眼镜头与Raspberry Pi 3和ROS一起使用的第一第二篇文章,我想谈谈在Raspberry Pi 3上使用经过预训练的深度学习模型进行鱼眼镜头的计算机视觉的研究。

图片分类


与之前的文章一样,我们将使用Ubuntu 16.04。 为了工作,我们将需要Keras库。 可以按照此处的说明将其安装在Ubuntu上。

我们将转到该页面 ,然后按“下载代码”按钮! 页面底部。 您将收到一封带有来源的电子邮件。

下载档案,将其解压缩并转到文件夹。 首先,根据预先训练的GoogleNet模型运行对象分类脚本:

cd pi-deep-learning/ python pi_deep_learning.py --prototxt models/bvlc_googlenet.prototxt \ --model models/bvlc_googlenet.caffemodel --labels synset_words.txt \ --image images/barbershop.png 

我们在终端中得到这个结论

 [INFO] loading model... [ INFO:0] Initialize OpenCL runtime... [INFO] classification took 1.7103 seconds [INFO] 1. label: barbershop, probability: 0.78055 [INFO] 2. label: barber chair, probability: 0.2194 [INFO] 3. label: rocking chair, probability: 3.4663e-05 [INFO] 4. label: restaurant, probability: 3.7257e-06 [INFO] 5. label: hair spray, probability: 1.4715e-06 

图片

它使用OpenCV 3.3中的深度神经网络(DNN)模块。 你可以在这里阅读。

现在,让我们尝试使用预训练的Squeezenet模型对对象进行分类:

 python pi_deep_learning.py --prototxt models/squeezenet_v1.0.prototxt \ --model models/squeezenet_v1.0.caffemodel --labels synset_words.txt \ --image images/barbershop.png 

 [INFO] loading model... [ INFO:0] Initialize OpenCL runtime... [INFO] classification took 0.86275 seconds [INFO] 1. label: barbershop, probability: 0.80578 [INFO] 2. label: barber chair, probability: 0.15124 [INFO] 3. label: half track, probability: 0.0052873 [INFO] 4. label: restaurant, probability: 0.0040124 [INFO] 5. label: desktop computer, probability: 0.0033352 

图片

我的分类效果为0.86秒。

让我们现在尝试一下cobra.png图像:

 python pi_deep_learning.py --prototxt models/squeezenet_v1.0.prototxt \ --model models/squeezenet_v1.0.caffemodel --labels synset_words.txt \ --image images/cobra.png 

结论:

 [INFO] classification took 0.87402 seconds [INFO] 1. label: Indian cobra, probability: 0.47972 [INFO] 2. label: leatherback turtle, probability: 0.16858 [INFO] 3. label: water snake, probability: 0.10558 [INFO] 4. label: common iguana, probability: 0.059227 [INFO] 5. label: sea snake, probability: 0.046393 

图片

物体检测


现在尝试使用Raspberry Pi的鱼眼镜头检测物体。 我们将转到该页面 ,然后按“下载代码”按钮! 页面底部。 您将收到一封带有来源的电子邮件。

与分类类似,下载,解压缩,然后转到文件夹。 运行脚本以检测对象:

 python pi_object_detection.py --prototxt MobileNetSSD_deploy.prototxt.txt --model MobileNetSSD_deploy.caffemodel 

结论:

 [INFO] loading model... [INFO] starting process... [INFO] starting video stream... [ INFO:0] Initialize OpenCL runtime... libEGL warning: DRI3: failed to query the version libEGL warning: DRI2: failed to authenticate 

运行脚本时,我们会收到以下错误:

 Error: AttributeError: 'NoneType' object has no attribute 'shape' (comment to post) 

要解决该问题,请打开文件pi_object_detection.py并注释掉第74行:

 vs = VideoStream(src=0).start() 

和注释行75

 vs = VideoStream(usePiCamera=True).start() 

图片

图片

我们看到该脚本检测到一些对象,尽管并非所有对象都能正确识别。 根据我的观察,脚本非常快速地检测到对象(不幸的是,fps无法修复)。

我们还可以运行real_time_object_detection.py脚本。 如果发生错误,请对pi_object_detection.py脚本重复该过程:注释掉第38行,并取消注释第39行。结果

图片

现在就这些了。 祝大家好运,很快再见!

Source: https://habr.com/ru/post/zh-CN481066/


All Articles