DL趣闻:如何使用黄记核弹来驱逐花园里施肥的猫咪
bg8npk2016/07/14软件综合 IP:四川

How One NVIDIAN Uses Deep Learning to Keep Cats from Pooping on His Lawn


Everyone loves cats. No one loves cat poop.

原作者使用Nvidia TX1开发版配合监控摄像头,识别闯入自家花园并准备施肥的猫咪,控制花园喷水器工作将其驱逐出境。

原文链接 XXXXXXXXXXXXXXXXXXXXXXXXXXX/~XXXXnd/cats/XXXXXXXm


Overview

This project was motivated by two things: a desire to learn more about neural net software and a desire to encourage the neighbors' cats to hang out somewhere other than my front yard.

这个项目主要有两个目的:一是学习神经网络,二是让邻居家的猫不要再在我家花园施肥

The project includes just three hardware components: an Nvidia Jetson TX1 board, a Foscam FI9800P IP camera, and a Particle Photon attached to a relay The camera is mounted on the side of the house aimed at the front yard. It communicates with a WIFI Access Point maintained by the Jetson sitting in the den near the front yard. The Photon and relay are mounted in the control box for my sprinkler system and are connected to a WIFI access point in the kitchen.

这个计划主要有三个硬件:一个黄记Jetson TX1 开发板,一个Foscam FI9800P IP摄像头,和一个连有继电器的Particle Photon 开发板。摄像头安装在房子的边沿,对准前院。摄像头通过一个AP连接到Jetson TX1。Photon板和继电器安装在洒水器的控制箱里,和厨房的wifi连接。

In operation, the camera is configured to watch for changes in the yard. When something changes, the camera FTPs a set of 7 images, one per second, to the Jetson. A service running on the Jetson watches for inbound images, passing them to the Caffe deep learning neural network. If a cat is detected by the network, the Jetson signals the Photon's server in the cloud, which sends a message to the Photon. The Photon responds by turning on the sprinklers for two minutes.

工作流程如下,摄像头设定为检查院子中的图像改变。当院子里有东西时,摄像头会拍摄七张图像,一秒一张,并把它们传送给Jetson TX1。Jetson组件内部运行的一个服务,用来查看接收到的图像,再把它们发送给Caffe深度学习模拟神经网络。如果神经网络检测到那是一只猫一只猫,Jetson组件就会通过网络发送指令给Photon板,开启洒水器喷水驱猫。

Here, a cat wandered into the frame triggering the camera:

猫来了

cat1.jpg

The cat made it out to the middle of the yard a few seconds later, triggering the camera again, just as the sprinklers popped up:

几秒钟后这只喵星人走到了院子中央,再次触发了摄像头,然后洒水器启动了: cat2.jpg

(猫咪:喵喵喵喵喵?)


Installing the camera

There was nothing unusual about installing the camera. The only permanent connection is a 12 volt wire that comes through a small hole under the eaves. I mounted the camera on a wooden box positioned to show the front yard. There are a bunch of wires attached to the camera that I hid in the box as well. Here's a shot of the camera:

安装摄像头和平时没什么不一样。唯一的永久连接就是一条从屋檐下的小洞接出来的12伏电源线。把摄像头安装在了一个能纵观整个院子的地方。同时我也把和摄像头相连的一堆线藏在了箱子里面。下面是一张摄像头的照片: camera.jpg

Follow the directions from Foscam to associate it with the Jetson's AP (see below). In my setup the Jetson is at 10.42.0.1. I gave the camera a fixed IP address, 10.42.0.11, to make it easy to find. Once that is done, connect your Windows laptop to the camera and configure the "Alert" setting to trigger on a change. Set the system up to FTP 7 images on an alert. Then give it a user ID and password on the Jetson. My camera sends 640x360 images, FTPing them to its home directory.

按照Foscam的说明书来把它连接到Jetson 的AP(见下文)。在我安装的过程中,Jetson的ip是10.42.0.1,也给了摄像头一个固定IP地址:10.42.0.11。这一步完成了,把你的的Windows笔记本和摄像头连接,设定一个由变化触发的“警报”。 把系统设置为一次警报发送7张图像。然后在Jetson上设置一个用户名和密码。这里摄像头拍摄分辨率为640x360的图像,并把他们发送给主机。

Here are some selected configuration parameters for the camera:

以下是摄像头的相关设置

D88BA506-9775-42B9-A61F-3570B0D5901E.png

Installing the Particle Photon

The Photon was easy to setup. See the software section below for the code. It sits in the irrigation control box like this:

Photon板的安装十分容易。按照下面的软件说明部分的代码就行了。把它像下面这样安装在洒水器控制箱里:

photon.jpg

The black box on the left with the blue LED is a 24VAC to 5VDC converter from EBay. You can see the white relay on the relay board and the blue connector on the front. The Photon board is on the right. Both are taped to a piece of perfboard to hold them together.

左边有蓝色LED灯的黑盒子是我在EBay上淘的24V交流电-5V直流电转换器。你可以看到继电器板上的白色继电器和前面的蓝色接头。Photon板在右半部分。这两者都被粘在一块洞洞板上。

The converter's 5V output is connected to the Photon's VIN pin. The relay board is basically analog: it has an open-collector NPN transistor with a nominal 3.3V input to the transistor's base and a 3V relay. The Photon's regulator could not supply enough current to drive the relay so I connected the collector of the input transistor to 5V through a 15 ohm 1/2 watt current limiting resistor. The relay contacts are connected to the water valve in parallel with the normal control circuit.

变压器的5V输出和Photon板的VIN接口相连。继电器板基本上是模拟IO:它有一个集电极开路输出门的NPN晶体管,它通过一个表面上是3.3V的电源输入口与晶体管基部和3V的继电器相连。因为Photon板的调节器不能提供足够的电流来驱动继电器运行,所以我把输入晶体管的接口并上一个15Ω 0.5W的限流电阻接到了5V电源上。继电器触点和正常控制电路并联接到水阀上。

Here's the way it is wired:

24VAC converter 24VAC <---> Control box 24VAC OUT

24VAC converter +5V <---> Photon VIN, resistor to relay board +3.3V

24VAC converter GND <---> Photon GND, Relay GND

Photon D0 <---> Relay board signal input

Relay COM <---> Control box 24VAC OUT

Relay NO <---> Front yard water valve


Installing the Jetson

设置黄记核弹 jetson.jpg

The only hardware bits added to the Jetson are a SATA SSD drive and a small Belkin USB hub. The hub has two wireless dongles that talk to the keyboard and mouse.

唯一需要安装到Jetson的是一个固态硬盘和一个小的Belkin USB集线器。集线器有两个可以连接鼠标和键盘的无线接口。

The SSD came up with no problem. I reformatted it as EXT4 and mounted it as /caffe. I strongly recommend moving all of your project code, git repos and application data off of the Jetson's internal SD card because it is often easiest to wipe the system during Jetpack upgrades.

这个SSD没有问题。我以EXT4格式将其格式化并把它挂载至caffe框架。由于Jetpack升级时系统很容易被清除,所以我强烈建议将你所有的程序代码、Git数据以及应用数据移出Jetson的内置储存卡。

The Wireless Access Point setup was pretty easy (really!) if you follow this guide. Just use the Ubuntu menus as directed and make sure you add this config setting.

如果你按着这个指南来操作,那么WAP的安装会变得非常简单(我儿豁!)。只要根据指示使用Ubuntu菜单并确保你添加了此配置文件设置。

I installed vsftpd as the FTP server. The configuration is pretty much stock. I did not enable anonymous FTP. I gave the camera a login name and password that is not used for anything else.

我安装了vsftpd作为FTP服务器。我不使用匿名FTP,所以我给了相机一个独立的用户名和密码。

I installed Caffe using the JetsonHacks recipe. I believe current releases no longer have the LMDB_MAP_SIZE issue so try building it before you make the change. You should be able to run the tests and the timing demo mentioned in the JetsonHacks installation shell script. I'm currently using Cuda 7.0 but I'm not sure that it matters much at this stage. Do use CDNN, it saves a substantial amount of memory on these small systems. Once it is built add the build directory to your PATH variable so the scripts can find Caffe. Also add the Caffe Python lib directory to your PYTHONPATH.

我用JetsonHacks网络安装了Caffe。我相信当前版本不再有LMDB_MAP_SIZE问题,所以就这样安装吧。你应该能够运行在JetsonHacks安装脚本中提到的测试和timing demo(定时演示)。我现在使用的是Cuda7.0 ,但我不觉得在此阶段使用何种软件很重要。因为CDNN在处理这些微小系统上能够节约了大量内存,所以一定要使用它。一旦安装成功,不但要将安装目录添加至PATH,而且将Caffe Python lib目录添加到PYTHONPATH,这样脚本会自动找到Caffe。

<code>~ $ echo $PATH
/home/rgb/bin:/caffe/drive_rc/src:/caffe/drive_rc/std_caffe/caffe/build/tools:/usr/local/cuda-7.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
~ $ echo $PYTHONPATH
/caffe/drive_rc/std_caffe/caffe/python:
~ $ echo $LD_LIBRARY_PATH
/usr/local/cuda-7.0/lib:/usr/local/lib 
</code>

I'm running a variant of the Fully Convolutional Network for Semantic Segmentation (FCN). See the Berkeley Model Zoo, github.

我运行了FCN(完全卷积网络)的变量来进行语义切分。详情参考上段链接。

I tried several other networks and finally ended up with FCN. More on on the selection process in a future article. Fcn32s runs well on the TX1 - it takes a bit more than 1GB of memory, starts up in about 10 seconds, and segments a 640x360 image in about a third of a second. The current github repo has a nice set of scripts, and the setup is agnostic about the image size - it resizes the net to match whatever you throw at it.

我尝试了许多其他网络,但最后选择了FCN。在未来的文章中,我会详细介绍选择的过程。Fcn32s在TX1上运行良好——它仅占用了1GB多一点的内存、能在大约10秒之内启动并且能在三分之一秒内切分一张640×360的图像。当前的github repo已经建立了一系列不错的脚本,它们使安装程序能够根据输入图像的大小进行调整。

To give it a try, you will need to pull down a pre-trained Caffe models. This will take a few minutes: XXXXXXXXXXXXXXXXXXXXXXffemodel is over 500MB.

为了试验,你需要下载一个预载好的Caffe框架。这可能会花费一些时间,因为XXXXXXXXXXXXXXXXXXXXXXffemodel大小超过500MB。

<code>$ cd voc-fcn32s
$ wget `cat caffemodel-url`
</code>

Edit XXXXXXXX, changing the path in the Image.open() command to a valid .jpg. Change the "net" line to point to the model you just downloaded:

编辑XXXXXXXX,输入一个有效的jpg格式的图像至Image.open()command中的路径。将你刚下载的Caffe框架添加至“net”行。

<code>-net = caffe.Net('fcn8s/deploy.prototxt', 'fcn8s/fcn8s-heavy-40k.caffemodel', caffe.TEST)
+net = caffe.Net('voc-fcn32s/deploy.prototxt', 'voc-fcn32s/fcn32s-heavy-pascal.caffemodel', caffe.TEST)
</code>

You will need the file voc-fcn32s/XXXXXXXXXototxt. It is easily generated from voc-fcn32s/XXXXXXXXototxt. Look at the changes between voc-fcn8s/XXXXXXXXototxt and voc-fcn8s/XXXXXXXXXototxt to see how to do it, or you can get it from my chasing-cats github repo. You should now be able to run

你需要voc-fcn32s/XXXXXXXXXototxt文件。它可由voc-fcn32s/XXXXXXXXototxt文件快速生成。仔细观察两文件的区别,你就会知道如何生成voc-fcn32s/XXXXXXXXototxt文件,或者你可以从我的捕猫github repo中得到它。

<code>$ python infer.py
</code>

My repo includes several versions of XXXXXXXX, a few Python utilities that know about segmented files, the Photon code and control scripts and the operational scripts I use to run and monitor the system. More on software in the next post.

我的repo中有许多版本的XXXXXXXX、一些可以切分文件的Python工具、Photon代码、控制脚本以及我用来运行管理系统的运行脚本。更多关于软件的信息,请关注我的下一个帖子。

Happy cat hunting!

[修改于 7年10个月前 - 2016/07/22 10:42:15]

来自:计算机科学 / 软件综合
1
已屏蔽 原因:{{ notice.reason }}已屏蔽
{{notice.noticeContent}}
~~空空如也
我说要有光
7年10个月前 IP:河北
822872
以前看过一个用双目摄像头测距驱逐松鼠的,也很有趣,但这个先进了更多
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

所属专业
所属分类
上级专业
同级专业
bg8npk
进士 老干部 学者 机友 笔友
文章
151
回复
1436
学术分
1
2011/08/19注册,18时36分前活动

设计师,音乐制作人 KC国际局,Live Soundman

主体类型:个人
所属领域:无
认证方式:手机号
IP归属地:未同步
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
支持的图片格式:jpg, jpeg, png
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
收藏
取消收藏
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
管理提醒
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}