深度学习和Raspberry PI

“我们有什么?” 驼背问,转过身来。
有胡子的男人说:“ Aldan-3。”
我说:“一辆有钱的汽车。[1]

最近,我决定学习深度学习。在工作中,他们给了我一张带有CUDA支持的新卡,老板表示希望工程的这一高峰将使我们的实验室取得飞跃,或者至少不会被众多竞争对手超越。我已经有一些使用Tensor Flow的经验,但是这次我决定尝试使用Torch。它是用Lua和C编写的,很有吸引力,它非常轻巧,可以通过FFI轻松扩展。而且我也不喜欢Python。


最近,我碰到一篇有关Habrahabr的文章,在讨论中,我记得在床头柜的某个地方,我看到了B +型的Raspberry Pi,我想看看是否可以在上面举起火炬并进行简单的操作。



GPU alexnet . Torch. , , .


(Raspberry PI B+).



torch :


apt-get install git-core  
git clone https://github.com/torch/distro.git ~/torch --recursive

, Torch OpenBLAS QT , :


apt-get install -y build-essential gcc g++ curl cmake libreadline-dev libjpeg-dev libpng-dev ncurses-dev imagemagick libzmq3-dev gfortran libopenblas-base libopenblas-dev

torch:


cd ~/torch;
./install.sh

.


— ? — . [1]

: torch: arm, NEON:


[  6%] Building C object lib/TH/CMakeFiles/TH.dir/THVector.c.o
In file included from /home/pi/torch/pkg/torch/lib/TH/THVector.c:2:0:
/home/pi/torch/pkg/torch/lib/TH/generic/THVectorDispatch.c: In function ‘THByteVector_vectorDispatchInit’:
/home/pi/torch/pkg/torch/lib/TH/generic/simd/simd.h:64:3: error: impossible constraint in ‘asm’
   asm volatile ( "cpuid\n\t"

. , ! , - torch Raspberry PI -B ( NEON): https://github.com/vfonov/deep-pi/releases/download/v1/torch_intstall_raspbian_arm6l_20161218.tar.gz, /home/pi



MNIST, Torch:


th train-on-mnist.lua 
<torch> set nb of threads to 4  
<mnist> using model:    
nn.Sequential {
  [input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> output]
  (1): nn.SpatialConvolutionMM(1 -> 32, 5x5)
  (2): nn.Tanh
  (3): nn.SpatialMaxPooling(3x3, 3,3, 1,1)
  (4): nn.SpatialConvolutionMM(32 -> 64, 5x5)
  (5): nn.Tanh
  (6): nn.SpatialMaxPooling(2x2, 2,2)
  (7): nn.Reshape(576)
  (8): nn.Linear(576 -> 200)
  (9): nn.Tanh
  (10): nn.Linear(200 -> 10)
}
<warning> only using 2000 samples to train quickly (use flag -full to use 60000 samples)    
<mnist> loading only 2000 examples  
<mnist> done    
<mnist> loading only 1000 examples  
<mnist> done    
<trainer> on training set:  
<trainer> online epoch # 1 [batchSize = 10] 
 [===================>.................... 471/2000 ....................................]  ETA: 2m20s | Step: 92ms      

, — i5-4590 CPU @ 3.30GHz, GPU:


[=======================>................ 571/2000 ....................................]  ETA: 27s613ms | Step: 19ms   

. 5 .



«» : «. » [1]

googlenet. : Alexnet , . squeezenet Network-in-Network, torch.


ARM ( Raspberry PI — ).


torch, ‘ascii’, — :


Desktop:


model=torch.load(‘blah.t7’)
torch.save(‘blah_ascii.t7’,model,’ascii’)

Raspberry PI:


model=torch.load(‘blah_ascii.t7’,’ascii’)
torch.save(‘blah_arm.t7’,model)

arm .


:
.


...
local m=torch.load(prefix..'nin_bn_final_arm.t7')
...
local input=image.load(prefix.."n07579787_ILSVRC2012_val_00049211.JPEG")
...
local output=model:forward(cropped)
...

, ImageNET:


>th test_single.lua n07579787_ILSVRC2012_val_00049211.JPEG
loading model:0.57sec   
Running neural net:13.46sec 
 25.3%: n07579787: plate    
 13.8%: n07873807: pizza, pizza pie     
 8.8%: n04263257: soup bowl     
 8.0%: n07590611: hot pot, hotpot   
 7.2%: n07831146: carbonara     

T.e 14 !


: camera display, , 14 . (luarocks install camera) - (luarocks install display).


.


--  
local cam = image.Camera {idx=0,width=iW,height=iH}
...
  local frame = cam:forward()
  local cropped = image.crop(frame, w1, h1, w1+oW, h1+oH) -- center patch
 --   
  display_sample_in.win=display.image(cropped,display_sample_in)
 --    
  local output=model:forward(cropped)
--   -  
  display_output.win=display.text(out_text,display_output)

display: nohup th -ldisplay.start 8000 0.0.0.0 &



:


图片


:


图片


图片


图片



, . , - , , .


nnpack, .


:


行情来自A.和B. Strugatsky的“星期一开始于星期六”和“三个故事”。
英文版的程序说明以及带有所有源代码的存储库都在github上

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


All Articles