2016å¹´åRaspberry Piè¨äº
ãã©ããã§ããRaspberry Piのわけわからん記事書いてるããããã§ãã2016å¹´åã®Raspberry Piè¨äºã«ãªãäºå®ã§ããäºå®ã§ãã¨ããã®ã¯2015å¹´ã®å¹´æ«ã«ãã®è¨äºãæ¸ãã¦ããããã§ããä»å¹´ãæ°ãåãããRaspberry Piã®ããããããè¨äºãéç£ãã¦ãããã¨æãã¾ãããããããªï¼
ãæ°å¹´ä¸çºãã¨ãããã¨ã§ãå夢ã«ãããã¦å¤¢ã«é¢ãã話é¡ã§ããå»å¹´æ«é ã«è©±é¡ã«ãªã£ã人工ç¥è½ãè¦ã夢ãDeepDreamãã®è©±é¡ã§ãã
- åºç社/ã¡ã¼ã«ã¼: RaspberryPi.org
- ã¡ãã£ã¢: ã¨ã¬ã¯ãããã¯ã¹
- ãã®ååãå«ãããã° (10件) ãè¦ã
DeepDreamã¨ã¯
ãä¸ææã°ããç»åãçæããã¨ãããã¨ã§è©±é¡ã«ãªãã¾ããããDeep DreamããDeep Dreamã®è©³ç´°ã¯ä»¥ä¸åç
§ãã ããã
ãä»æ´ãªããã§ãããã¡ãã£ã¨ãã£ã¦ã¿ãããªã¨æãç«ã¡ã¾ãããこの前Raspberry Pi2でDeep Learningやったãã©ãããªãRaspberry Pi2ã§ã§ããªãããªï¼æ¤ç´¢ãããæ¢ã«Raspberry Pi2ã«ã¤ã³ã¹ãã¼ã«ãã¦ããå大ãªãå
人ããããããï¼æ¥½å楽åï¼
ãããæã£ã¦ããææãç§ã«ãããã¾ãããçµè«ããè¨ãã¨å°çã§ãããå¿
è¦ãªããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ã¨ãã«ãã«ãã¡ããã¡ãæéãããä¸ãä¸è¨ãµã¤ãã¨åãããã«ãã£ã¦ããã¨ã©ã¼å¤çºãã¦ãã®ãã³ã«å¯¾å¦æ¹æ³æ¤ç´¢ãã¦ãã©ã¤ã¢ã³ãã¨ã©ãç¹°ãè¿ãç¾½ç®ã«ãªãã¾ãããããã¦ããªãã¨ãã§ããããã«ãªã£ããã®ã®ã240x120ãµã¤ãºã®ç»åãµã¤ãºã§1æç»åçæããã®ã«5åãããã¨ããç¶æ³ãããã5,6æç»åçæãããsegmentation falutã§è½ã¡ãããç»åèªèãä¸ç¬ã ã£ãã®ã§å®å
¨ã«è¦èª¤ã£ã¦ãã¾ããã
ãæ¬å½ã¯Deep Learningãã¸ã«ã¡ä½ãããã£ãã®ã§ãããã¡ãã£ã¨Raspberry Pi2ã§ã®å®ç¾ã¯éé ããã§ãã
Raspberry Pi2ã§Deep Dreamç»å
ãèå³ãªãæ¹ã大åã®ä½ãæ¹çã¯å¾ã«åãã¦ãã¨ããããçµæã ãå ã«è¼ã£ãã¦ããã¾ãã
å ç»å
ããã£ããã馴æã¿ã®ãªãã¡ã¬ã³ã¹ç»åããããã (id:lonestartx) ããç´ ææä¾ãããã¨ããããã¾ãï¼
Deep Dreamã§ç»åçæ
ãããã¼ã°ãç»åã ï¼ã ãã ãã°ãç»åã«ãªã£ã¦ããã®ããåããããã ããã§ããããï¼ä¸æçæããã«5å以ä¸ãããã6æã»ã©çæããå¾segmentation falutã§ããã°ã©ã ãè½ã¡ã¾ãããRaspberry PiãDeep Learningã®å¤¢ãè¦ã¦ããã®ããåããããã ããã ãããï¼
ããã®å¾ã¯ããã®ãããããªãçµæãå¾ãããã®å°çã®å®å®èªãç¶ãã®ã§èå³ã¨è¦æãããæ¹ã ãã覧ãã ããï¼ã¨ãã£ã¦ããã®è¨äºã®éãããã°2æéãããã°ã§ããã¯ãã§ããå¤åããã¡ã¤ãï¼ï¼ã
Deep Dreamã»ããã¢ãã
ã大ãã2ã¤å¿ è¦ã§ãDeep Learningã®Caffeã¨ããã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ã¨Deep Dreamèªä½ã®ã¤ã³ã¹ãã¼ã«ã§ããã»ã¨ãã©ã¯Caffeã¨Caffeãåããããã®ããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ã«è²»ãããã¾ãã
Caffeã¤ã³ã¹ãã¼ã«æºå
ãã¾ãã¯é©å½ãªä½æ¥ç¨ã®ãã£ã¬ã¯ããªãä½ã£ã¦ä¸ã«å ¥ãã¾ãããã
$ cd $ mkdir DeepDream $ cd DeepDream
ã以ä¸ã®ã³ãã³ãã§Caffeã®ææ°ã®ã½ã¼ã¹ã³ã¼ããåå¾ã
$ git clone --depth 1 https://github.com/BVLC/caffe.git
å¿ è¦ãªããã±ã¼ã¸ãapt-getã§ã¤ã³ã¹ãã¼ã«
ãã²ãããã¤ã³ã¹ãã¼ã«ãã¾ããå¤å30åããããããã¾ãã
$ sudo apt-get update $ sudo apt-get install libopenblas-dev $ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev $ sudo apt-get install libhdf5-serial-dev protobuf-compiler
pythonã®ããã±ã¼ã¸ã¤ã³ã¹ãã¼ã«
ãCaffeã«å¿ è¦ãªpythonã®ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãã¾ããå¿ è¦ãªããã±ã¼ã¸ã¯ä»¥ä¸ã®ã³ãã³ãã§ã³ãã³ãã§ç¢ºèªã§ãã¾ãã1è¡ç®ã®ã³ãã³ãã¯ãã£ã¬ã¯ããªã®ç§»åã
$ cd ~/DeepDream/caffe $ less python/requirements.txt
ãä¸æ°ã«pipã§å ¥ãããã¨ããã¨ä½æ ãã¨ã©ã¼ãã§ãã®ã§ãapt-getã§å ¥ãããããã®ã¯apt-getã§å ¥ãã¾ããå ·ä½çã«ã¯ä»¥ä¸ã®ã³ãã³ããå°éã«æã£ã¦ããã¾ãã
$ sudo apt-get install cython $ sudo apt-get install python-numpy $ sudo apt-get install python-scipy $ sudo apt-get install python-skimage $ sudo apt-get install python-h5py $ sudo apt-get install python-networkx $ sudo apt-get install python-pandas $ sudo apt-get install python-protobuf
ãä»ã®ããã±ã¼ã¸ã¯ãapt-getã§å ¥ããã¨ãã¼ã¸ã§ã³ãåããªããããã®ã§ä»¥ä¸ã®ã³ãã³ãã§å¿ è¦ãªããã±ã¼ã¸ãpipã¨ããpythonã®ã©ã¤ãã©ãªå°ç¨ã®ã¤ã³ã¹ãã¼ã©ã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
$ cd ~/DeepDream/caffe $ sudo pip install -r python/requirements.txt
ãã«ãã®ããã®æºå
ããã«ãã®ããã«è²ã æºåãå¿ è¦ã§ãã
ãããã¼ãªã©ã®ä½ç½®åãã
ãä¿®æ£ãå¿ è¦ã¨ã®ãã¨ãèªåã§ä¿®æ£ããã¹ã¯ãªããgistã«ã¢ãããã¾ããã以ä¸ã®ã³ãã³ããã³ããããã°ä¿®æ£ãã¦ããã¾ãã
$ cd ~/DeepDream/caffe $ git clone https://gist.github.com/karaage0703/955324396cf60e1dc839 optimize $ mv optimize/OptimizeBuildCaffe.sh ./ $ bash OptimizeBuildCaffe.sh
DBå¨ãã®èª¿æ´
ãã½ã¼ã¹ãã¡ã¤ã«ã®å®æ°ãå¤æ´ããå¿ è¦ããã¾ãã以ä¸ã³ãã³ãã§ãã¡ã¤ã«ãç·¨éãã¾ãããã
$ vi src/caffe/util/db_lmdb.cpp
ãå¤æ´å 容ã¯ä»¥ä¸
å¤æ´å const size_t LMDB_MAP_SIZE = 1099511627776; // 1 TB å¤æ´å¾ const size_t LMDB_MAP_SIZE = 536870912;
Makefileä¿®æ£
ããã«ãããåã«ãMakefileãä¿®æ£ããå¿ è¦ããã¾ããã¾ãã¯ä»¥ä¸ã³ãã³ãã§Makefileæºåãã¦ç·¨é
$ cd ~/DeepDream/caffe
$ cp Makefile.config.example Makefile.config
$ vi Makefile.config
ãå¤æ´å
容ã¯ä»¥ä¸ã§ããçç±ã¯åèãµã¤ããåç
§ãã¦ãã ããããã¨åèãµã¤ãã®ã¾ã¾ã§ã¯hdf5
ãç¡ãã¨ããã¨ã©ãåºã¦ãããã«ãéããªãã£ãã®ã§ãã²ã£ãã«ã°ã°ã£ã¦LIBRARYã«ãã¹ã追å ããã°ãã«ããéããã¨ããããã¾ããã
å¤æ´å
7è¡ç®ä»è¿ # CPU-only switch (uncomment to build without GPU support). # CPU_ONLY := 1 42è¡ç®ä»è¿ # BLAS choice: # atlas for ATLAS (default) # mkl for MKL # open for OpenBlas BLAS := atlas 86è¡ç®ä»è¿ LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
å¤æ´å¾
7è¡ç®ä»è¿ # CPU-only switch (uncomment to build without GPU support). CPU_ONLY := 1 42è¡ç®ä»è¿ # BLAS choice: # atlas for ATLAS (default) # mkl for MKL # open for OpenBlas BLAS := open 86è¡ç®ä»è¿ LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/arm-linux-gnueabihf/hdf5/serial/
足ããªãããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«
ããã®å¾ã¯makeãã¦ã¯ã¨ã©ã¼çºçãã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ã°ã°ããå度makeã®ç¹°ãè¿ããæçµçã«å¿ è¦ã ã£ãã®ã¯ä»¥ä¸ã§ããã®ã§ãã«ãããåã«å ¥ãã¡ããã¾ããããä¸é¨ä¸è¦ãªãã¤ãå ¥ãã¡ãã£ã¦ãããããã¨ã©ã¼ã¡ãã»ã¼ã¸ã§åºã¦ããã¨å¤§æµè§£æ±ºæ¹æ³ãåºã¦ãã¾ãããå大ãªãå 人ã«æè¬æè¬ããã§ã«ã¤ã³ã¹ãã¼ã«ããã¦ãããã®ãããããããã¾ããããæ°ã«ããã©ãã©ãé²ãã§ãã£ã¦ãã ããã
apt-getã§ã¤ã³ã¹ãã¼ã«
$ sudo apt-get install libboost1.55-all $ sudo apt-get install cmake
gflagã¤ã³ã¹ãã¼ã«
$ cd $ wget https://github.com/schuhschuh/gflags/archive/master.zip $ unzip master.zip $ cd gflags-master $ mkdir build && cd build $ export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1 $ make $ sudo make install
glogã¤ã³ã¹ãã¼ã«
$ cd $ wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz $ tar zxvf glog-0.3.3.tar.gz $ cd glog-0.3.3 $ ./configure $ make $ sudo make install
mdbã¤ã³ã¹ãã¼ã«
$ cd $ git clone https://github.com/wizawu/lmdb.git $ cd lmdb/libraries/liblmdb $ make $ sudo make install
ãæ¬å®¶ã®git://gitorious.org/mdb/mdb.git
ãæ»ãã§ããã®ã§ãã©ã¼ãµã¤ããæ¢ãåºãã¾ããã
Caffeãã«ã
ããããããã«ãã§ããããã¾ã§ã®æºåããã¾ããã£ã¦ããããã«ããä¸çºã§éãã¯ãã§ãããã¾ããããªãã£ããâ¦æ®å¿µã§ããããã¨ã©ã¼ãã°ã°ã£ã¦ã¯å¯¾å¦æ¹ã調ã¹ãã¨ããå°çã¸ããããï¼(Welcome to underground!)
$ cd ~/DeepDream/caffe $ make all -j4 $ make test -j4 $ make runtest $ make pycaffe $ make distribute $ mkdir ~/pycaffe $ mv distribute/python/caffe ~/pycaffe
ããã¨ã¯ä»¥ä¸ã³ãã³ãã§caffeã¸ã®ãã¹ãéãã¾ãããããã¸ããããããããªãã¦ã°ã°ã£ã¦è§£æ±ºãã¾ãããexportã¯èµ·åã®ãã³ã«å®è¡å¿
è¦ã«ãªãã¾ããæ¯åé¢åãããã¨ãã人ã¯.bashrc
ã«ã§ãã³ãããã¦ãã
$ export PYTHONPATH=/home/pi/pycaffe:$PYTHONPATH $ export LD_LIBRARY_PATH=/home/pi/DeepDream/caffe/distribute/lib:$LD_LIBRARY_PATH
ã¢ãã«ãã¦ã³ãã¼ã
ããã¦ã³ãã¼ããã¾ãããã
$ cd ~/DeepDream/caffe/models/bvlc_googlenet/
$ wget http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel
DeepDreamã¤ã³ã¹ãã¼ã«
ãããããã¤ã³ã¹ãã¼ã«ï¼ãªã®ã§ãããipythonã§åããæ¬å®¶ã®DeepDreamã¯ä½æ
ããã¾ãåãã¾ããã§ããï¼å¤åipythonã®ãã¼ã¸ã§ã³é¢ä¿ï¼ãåç´ã«pythonã§åãããããã©ããã¾ããããåè¦å
«è¦ãã¦ãããããã¡ãã«ãå大ãªå
人ãã
ãããã°ã©ã ã³ãããã¦ãã¢ãã«ã®ãã¹ã ãæ¸ãæãããä¸çºã§åãã¾ãããåãï¼è¶ æè¬ï¼ãã¹æ¸ãæããã³ã¼ããgistã«ã¢ããããã¦ããã ãããã®ã§ã以ä¸ã®ã³ãã³ãã§ã³ãã¼(clone)ã§ãã¾ãã
$ cd ~/DeepDream
$ git clone https://gist.github.com/d9ad7556fa624ccce303.git dd
DeepDreamå®è¡
ã好ããªç»åãv.jpg
ã¨ããååã§ä¿åãã¦ãã¹ã¯ãªããã¨åããã£ã¬ã¯ããª~/DeepDream/dd
ã«é
ç½®ãã¦ããã以ä¸ã³ãã³ããå®è¡ãã¦ãã ãããç»åã®ãµã¤ãºã¯160x120ããããããªãã¨1æãçæã§ããsegmentation falutã§è½ã¡ã¾ãã
$ cd ~/DeepDream/dd
$ python deepdream_sample.py
ãåããã£ã¬ã¯ããªã«frames
ã¨ãããã£ã¬ã¯ããªãçæããã¦ãç´5åæ¯ã«ç»åã1æçæããã¾ãããã§ã«frames
ãçæããã¦ããã¨ã¨ã©ã«ãªãã®ã§$ rm -rf frames
ã§ãã£ã¬ã¯ããªåé¤ãã¦ãã
ã¾ã¨ã
ãã¨ããããã§Deep Dreamãã£ã¦ã¿ã¾ãããããªã大å¤ã§ãããããã¦Raspberry Pi2ã§ãéããã¦å®ç¨çãããªãã§ããããã£ã¨è»½ããã°è²ã 使ãéãããããªã®ã§ããâ¦æ®å¿µã§ãã