Deep Learning et Raspberry PI

"Qu'avons-nous?" Demanda le bossu en se retournant.
"Aldan-3", dit l'homme barbu.
"Une voiture riche", ai-je dit. "[1]

Récemment, j'ai décidé d'étudier le deep learning. Au travail, ils m'ont donné une nouvelle carte avec le soutien de la CUDA et le patron a exprimé le souhait que ce pic d'ingénierie permette à notre laboratoire de faire un bond en avant, ou du moins de ne pas se faire dépasser par la masse des concurrents. J'avais déjà une certaine expérience avec Tensor Flow, mais cette fois j'ai décidé d'essayer Torch. Il était attrayant qu'il soit écrit en Lua et C, il est assez léger et facilement extensible via FFI. Et je n'aime pas non plus Python.


Récemment, je suis tombé sur un article sur Habrahabr, au cours de la discussion dont je me suis souvenu que quelque part dans ma table de nuit, je voyais un Raspberry Pi, modèle B +, et je voulais voir si je pouvais lever le flambeau dessus et exécuter quelque chose de simple.



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 &



:


image


:


image


image


image



, . , - , , .


nnpack, .


:


Extraits de "Monday Begins Saturday" et "The Tale of the Three" par A. et B. Strugatsky.
La description de la procédure en anglais et le référentiel avec toutes les sources sont sur le github .

Source: https://habr.com/ru/post/fr400141/


All Articles