Raspberry Piã¨TensorFlowã使ã£ããã£ã¼ãã©ã¼ãã³ã°éçºç°å¢
ã以ä¸ã®è¨äºã§Raspberry Piã¨TensorFlowã使ã£ããã£ã¼ãã©ã¼ãã³ã°ã®éçºç°å¢ã®æ§ç¯æ¹æ³ãç´¹ä»ãã¾ããã
ãè¨äºã®æå¾ã®æ¹ã«ãèªåãã¼ã¿ã®å¦ç¿ãããå¦ç¿ãããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã§å¤å¥ã¾ã§å®æ½ã§ããèªåã®ããã±ã¼ã¸ãtensorflow-piããç´¹ä»ããã¦ããã ãã¾ããã
ããã ãREADMEã ãè¦ã¦ããæå³ä¸æãªè±èªã§è¯ãããããªãã¨æãã¾ãã®ã§ãä»åã¯å®ä¾ã交ããªãããã®ã½ããã®ä½¿ãæ¹ãç´¹ä»ãããã¨æãã¾ãã
ãä¾é¡ã§ããã以åãããã§è©±é¡ã«ãªã£ãããããã³ãã®å¹»ã®é¡èªèæ©è½ãããã¾ãã詳ããã¯ä»¥ä¸åç §ä¸ããã
ãéçºæ±ºå®ï¼ã¨ãããã¥ã¼ã¹ã¯è©±é¡ã«ãªã£ããã®ã®ããã®å¾ç¶å ±ãã¨ãã¨èããã¾ãããããããæè¡çã«ä¸å¯è½ãªãããã¨ããåãèããã¦ããããã¾ããã
ãå¥ããããããã³ã¨Raspberry Piã¯ãARMãã¼ã¹ã®1.2GHzã®ã¯ã¢ããã³ã¢CPUãã«ã¡ã© 800ä¸ç»ç´ ã¨æ§è½çã«ã¯ä¼¼éã£ã¦ãã¾ãããããã³ã®OS(Android)ä¸ã§ãTensorFlowã®å¦ç¿ãã¼ã¿ãæ±ãããããã®ã§ãRaspberry Piã§å®ç¾ã§ããã°ããããã³ã§åããã¨ãã§ããå¯è½æ§ã¯é«ããã§ããã¨ãããã¨ã§ãRaspberry Piã§é¡èªèæ©è½éçºãã¦ããããã³ã§é¡èªèãå®ç¾ã§ãããã©ãããRaspberry Piã§ãããã¿ã¤ãã³ã°ãã¦äºåæ¤è¨¼ãã¦ã¿ããã¨ã«ãã¾ããããããªããã§ãããã³ã¯ä½¿ãã¾ãããã¿ã¤ãã«ã§æå¾ ããæ¹ã¯ãã¿ã¾ããï¼ï¼ãããããã³æã«å ¥ã£ããããã¯ãã¦ã¿ããï¼ï¼ã
ãããã¦ãä¸å¿æåã«æ¸ãã¦ããã¾ãããç§ã¯æ©æ¢°å¦ç¿ããã£ã¼ãã©ã¼ãã³ã°ã®å°é家ã§ãä½ã§ãç¡ãã趣å³ã§ãã£ã¦ããã ãã§ãã®ã§ãå 容ã«ä¸æ£ç¢ºãªç®æãå«ã¾ããå¯è½æ§ãããã¨ã¯ã容赦ä¸ããï¼èªåãªãã«ã¯é å¼µã£ã¦ããã¤ããã§ããï¼ãåå¼·ä¸ã®èº«ã§ãã®ã§ãããæ°ã¥ãããæ¹ã¯ãåªããæãã¦ããã ãããå¬ããæãã¾ãã
ããã¨ãããããçµæå¾ãããªãã£ãå²ã«ãé·ãã¦ããã¢ãã¯ãªã®ã§èå³ããæ¹ã®ã¿ã覧ä¸ãããããã»ãã¨ã
é¡èªèæ©è½ã®éçº
ä»æ§å®ç¾©
ããããã¸ãã¯ã詳ããä»æ§ã決ã¾ã£ã¦ããããã§ã¯ãªãã®ã¨ãããã§ã¯ããã¾ã§ãã£ã¼ãã©ã¼ãã³ã°ã®å®é¨ãç®çãªã®ã§ã以ä¸ã®ãã£ããä»æ§ã¨ãã¾ã
- ãã¼ãã¦ã§ã¢ã¯Raspberry Piã¨å°ç¨ã«ã¡ã©ã¢ã¸ã¥ã¼ã«ã使ç¨
- å¦ç¿ãã対象ã¯ãã¨ãããã家æ3人ï¼å¢ãããã¨ã¯å¯è½ã«ãã¦ããï¼
- ã«ã¡ã©ã§å®æçã«æ®å½±ãã人ã®é¡ãæ®å½±ãããã誰ããå¤å¥ãã¦æãã¦ããã
- å¦ç¿ãå¤å¥ã¯åºæ¬Raspberry Piä¸ã§è¡ã
- é¡åçã®åéåã³åå¦çã¯æåã§ããï¼ããã®èªååã¯å¾ã§èããï¼
ã製åã®ãã¨ãèããã¨ãæ¬å½ã¯ãããä¸çªå¤§åãªãã§ããã©ãã
é¡èªèæ©è½ã®æ¦è¦
ãé¡èªèæ©è½ã®æ¦è¦ã«é¢ãã¦ã¯ãä¸å³ã®ããã«ãªãã¾ãã
ã大ãããå¦ç¿ã¨èªèã®2ã¤ã®ããã¼ã«åããã¾ããå¦ç¿ããã¼ã§ã¯ãèªèããã人ã®é¡ãå«ã¾ãã大éã®åçããé¡æ¤åºãã¦åãæãã½ããã§é¡åçãåãåºãã¾ããããã¦ãéããé¡åçã誰ã®åçãåé¡ï¼ã©ãã«ä»ãï¼ãã¦ãã£ãä¸ã§ãå¦ç¿ãè¡ãå¦ç¿ã¢ãã«ï¼ãã¥ã¼ã©ã«ãããã¯ã¼ã¯ï¼ãå¾ã¾ããå¦ç¿ãã§ã¤ãºã®ä½æ¥ã¯ã1é¨ãé¤ãã¨ã»ã¼æåã®ä½æ¥ã«ãªãã¾ãã
ãèªèã®ããã¼ã§ã¯ãRaspberry Piã§æ®å½±ããåçããå¦ç¿ã®ã¨ãã¨åãè¦é ã§é¡æ¤åºï¼åãæããè¡ããåãåºããé¡åçãå¦ç¿ãããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã使ãå¤å¥ãã¾ããèªèã«é¢ãã¦ã¯ãããã°ã©ã ãéå§ããããåºæ¬çã«èªåã§ç¹°ãè¿ãè¡ããã¾ãã
Raspberry Piã¨TensorFlowã®ç°å¢æ§ç¯
ãã¾ãã¯ã以ä¸è¨äºãåèã«Raspberry Piã«TensorFlowã®ç°å¢ãæ§ç¯ãã¾ãã
ã次ã«ãèªåãã¼ã¿ã®å¦ç¿ããå¤å¥ã¾ã§ã§ããèªä½ã½ããtensorflow-pi
ãã以ä¸ã®GitHubã®ãªãã¸ããªãããã¦ã³ãã¼ãï¼cloneï¼ãã¾ãã
ãå ·ä½çã«ã¯ãRaspberry Piä¸ã®ã¿ã¼ããã«ã§ä»¥ä¸ã³ãã³ããå®è¡ãã¦ãã¦ã³ãã¼ãä¸ãã
$ cd $ git clone https://github.com/karaage0703/tensorflow-pi $ cd tensorflow_pi
ãGitHubã£ã¦ä½ï¼ã£ã¦äººã¯ã以ä¸ãåç §ãã¦ä¸ããã
ãµã³ãã«ãã¼ã¿ï¼å ¥ååçï¼åå¾
ãèªåã¨æãã妻ã¨å¨ã¨èªåã®é¡åçãå ¥ã£ããµã³ãã«ãã¼ã¿ãéãã¾ããããã¯ãRaspberry Piã§æ®å½±ãã¦éãã¦ãããã£ãã®ã§ãããè²ããªæ¡ä»¶ã®ãã®ããã£ãæ¹ãããã ããã¨ãããã¨ã§ãéå»åçãªã©ãæ´»ç¨ãããã¨ã«ãã¾ããã
ãããã¯ã¢ããã«ä½¿ç¨ãã¦ããflickrãGoogleãã©ãããæ¢ãã¦ã¿ã¾ããããããã®ãµã¼ãã¹ã¨ãé¡åçãèªåã§æ¤åºããæ©è½ãæã£ã¦ãã¾ãã詳細ã¯ä»¥ä¸åç §ãã ããã
ãflickrã¯ã«ã¡ã©ãã¼ã«ã®magic viewãããè¤æ°é¸æãã¦ä¸æ¬ãã¦ã³ãã¼ãã§ãã¾ãã
ãGoogleãã©ãã¯Google ãã©ãã®ã¢ã«ãã ->人ç©ã§ãä¸ã¤ãã¤Shift+D
ã§ãã¦ã³ãã¼ãã§ãã¾ãã
ã使ã£ã¦ã¿ãæ触ã¨ãã¦ã¯ãGoogleãã©ããåå¥ã®äººç©ã¾ã§èå¥ãã¦ãããã®ã§ä¸çªè¯ãæãã§ãããflickrã¯ä¸æ¬ãã¦ã³ãã¼ããããã®ã¯è¯ãã®ã§ããããã¦ã³ãã¼ããæ»ã¬ã»ã©éãã§ãï¼ã¿ã¤ãã³ã°ã«ãã£ã¦ãå¤ããããï¼ã
ãGoogleãã©ãã¯ããµã¤ãºãå¶éããã°å®¹éã¯ç¡å¶éãªã®ã§ãGoogleã¸ã®ã¢ãããã¼ãã«æµæããªããã°ãææã¡ã®ç»åãå ¨é¨ã¢ãããã¼ããã¦Googleãã©ãã«åé¡ãã¦ãããã®ããä¸çªæ軽ãªé¡åçãã²ããããæ¹æ³ããªã¨æãã¾ããã
ããããã¦å¤§éã®ããªã¼ç´ æãéã¾ãã¾ããã
ããµã³ãã«ã¯ã¤ã¡ã¼ã¸ã§ã
ãä»åã®è¨äºããããéå ¬éã®ç§ã®å®¶æåçã®ä»£ããã«ãã¤ã¡ã¼ã¸ç»åã¨ãã¦ãããªã¼ç´ æã®ãã³ã¹ã¿(id:lonestartx) ããã®åçã使ãããã¦ããã ãã¦ããã¾ãããã¤ããããã¨ããããã¾ãã
ããªããåçã¯ããã°ã©ã ã®é½åä¸å ¨ã¦ã«ã©ã¼ç»åã使ç¨ãã¦ä¸ããï¼ã¢ãã¯ãç»åãå ¥ã£ã¦ããã¨ã¨ã©ã¼ã§æ¢ã¾ãã¾ãï¼ã
é¡ã®åãåºã
ãé¡åçãåéãããã次ã¯é¡ã®é¨åã«éå®ãã¦åãåºãã¦ããå¿ è¦ãããã¾ãã以åä½ã£ãé¡æ¤åºã®ããã°ã©ã ããã¼ã¹ã«é¡ãåãåºãã½ãããä½æãã¾ãããé¡æ¤åºã«é¢ãã¦ã¯ã以ä¸åç §ä¸ããã
ãä»åã¯ãä¸è¨ã®ããã°ã©ã ã®ã¾ã¾ã§ã¯ããã¾ãã«æ¤åºç²¾åº¦ãæªãã£ãã®ã§ãè²ã
ãªãµã¤ããåèã«ãã¦ç®ã®ä½ç½®ãªã©ãå¤å®ã«å ããçãã¦ç²¾åº¦åä¸ãã以ä¸ã®pythonã®ç»åå¦çããã°ã©ã éã®ãªãã¸ããªã«face_crop.py
ã¨ããååã§è¿½å ãã¾ãããåèã«ããã¦ããã ãããµã¤ãã¯ãæ¬è¨äºã®æ«å°¾ãããªã³ã¯ãè²¼ã£ã¦ãã¾ãã
ã使ãæ¹ã¯ãREADMEã«ãæ¸ãã¦ããã¾ããç°¡åã«è§£èª¬ãã¾ãã以ä¸ã¯ãMacãLinux(Raspberry Piå«ãï¼ã®ã¿ã¼ããã«ã§ã®æä½ãåæã¨ãã¦è¨è¼ãã¦ãã¾ãã®ã§ã注æä¸ããã
ãç°å¢æºåã¯ä»¥ä¸åç §ã«ã»ããã¢ãããã¦ä¸ããã
ã次ã«ãé¡ãåãåºãããç»åã®ãããã©ã«ãã«ç§»åãããã¨ãã¿ã¼ããã«ã§ä»¥ä¸ã³ãã³ããå®è¡ãã¦ããã°ã©ã ãã³ãã¼ãã¾ãã
$ wget https://raw.githubusercontent.com/karaage0703/python-image-processing/master/face_crop_simple.py https://raw.githubusercontent.com/karaage0703/python-image-processing/master/face_crop_simple-all.sh $ chmod 755 face_crop_simple-all.sh
ããã¨ã¯ã以ä¸ãå®è¡ããã°ãé¡åçãface_images
ãã£ã¬ã¯ããªã«èªåçã«åãåºããã¦è¡ãã¾ãã
$ ./face_crop_simple-all.sh
ã以ä¸ã®ãããªæãã§ãã
ãâ»ææ°ã®é¡åãåºãã½ããã§ã¯ãå¤å°è¡¨ç¤ºãç°ãªãã¾ã
ãåãåºããé¡ã¯ãã«ãã´ãªï¼ä»åã ã¨äººæ¯ï¼ã«ãã©ã«ãåããã¦ãRaspberry Piã®tensorflow-pi/data/
以ä¸ã«ã¾ã¨ãã¦ããã¾ããä¾ãã° karaage
lemon
necogista
ã ã¨ä»¥ä¸ã®ããã«é
ç½®ãã¾ãã
tensorflow-pi |- data/ image_data/ |--- etc/face_etc_01.jpg, face_etc_02.jpg, ... |--- karaage/face_karaage_01.jpg, face_karaage_02.jpg, ... |--- lemon/face_lemon_01.jpg, face_lemon_02.jpg, ... |--- necogista/face_necogista_01.jpg, face_necogista_02.jpg, ...
ããã©ã«ãåããã¡ã¤ã«åã¯ä½ã§ãOKã§ãï¼ãã ããæ¥æ¬èªã¨ãç¹æ®ãªè¨å·ã¯ãã¡ããï¼ã
ãPCä¸ã§ã¿ãã¨ä»¥ä¸ã®ãããªã¤ã¡ã¼ã¸ã§ãã
ãã¡ãªã¿ã«ãetc
ã¨ããã®ã¯ãé¡ä»¥å¤ã®ãã®ãæ¤åºãããç»åï¼ãã¤ãºï¼ãå
¥ãã¦ãã¾ãããããå
¥ãããã¨ã§ãå®éã«ä½¿ãéãé¡æ¤åºã«å¤±æããã¨ãç¡çãã誰ãã«å½ã¦ã¯ãããã¨ãªããetc
ï¼é¡ä»¥å¤ã®ãã®ï¼ã¨ãã¦å¤å®ãããã¨ã§ã誤èªèãæ¸ããå¹æãæå¾
ãã¦ãã¾ãã
ã以ä¸ã¯etc
ã«ãã´ãªã®åçã®1ä¾ã§ãã
ãå ¨ç¶é¡ãããªãã§ããã
ãä»åã¯ãããããã®ã¯ã©ã¹ã«30æç¨åº¦ã®åçãåè¨120æç¨åº¦ã®åçãéãã¾ããã
ãã¼ã¿ã®Nå¢ã
ããã£ã¼ãã©ã¼ãã³ã°ã§å¦ç¿ãããéã¯ããã¼ã¿ãNå¢ãï¼æ°´å¢ãï¼ããæ¹ãããã¨ãã話ãããèãã®ã§ãNå¢ãããã½ãããtensorflow-pi
ã«ç¨æãã¾ãããã½ããã¯ãèªä½ããããã¨æã£ãã®ã§ããããã§ã«ä¾¿å©ãªã½ãããä½ã£ã¦ãã人ãå¤æ°ããã®ã§ã以ä¸ã®ãµã¤ããªã©ãåèã«ããã¦ããã ãã¾ãããããããããããããã
ããã ãå®ã¯ä»åã®å ´åã¯Nå¢ãåã®120æç¨åº¦ã®ç»åã§å¦ç¿ããã¨ãã¾ããã£ãã®ã§ãæçµçã«ã¯Nå¢ããã¾ããã§ãããNå¢ãã®å¹æã¯ããã£ã¨ã¯ã©ã¹ãå¤ãã¨å¿ è¦ã«ãªã£ã¦ããããªã®ã§ãå¥ã®èª²é¡ã§æ¹ãã¦æ¤è¨¼ããããªã¨æã£ã¦ãã¾ãã
ãNå¢ããããæ¹æ³ã¯ãNå¢ãããããã©ã«ãã«ç§»åãã¦ãã³ãã³ããå®è¡ããã ãã§ããä¾ãã°ã~/tensorflow-pi/data/image_data/karaage
ã®ãã¼ã¿ãNå¢ããããå ´åã¯ä»¥ä¸ã§ãã
$ cd ~/tensorflow-pi/data/image_data/panda
$ ../../increase_picture-all.sh
ãå®è¡ããã¨trans_...
ã¨ããNå¢ããã¼ã¿ã大éã«çæããã¦ããã¾ãã
ããããNå¢ããããå ¨ã¦ã®ãã©ã«ãã§è¡ãã¾ããã¤ã¡ã¼ã¸çã«ã¯ããã®1ã¤ã®åçã
ã以ä¸ã®ããã«Nå¢ãããã¾ãã
ãã¾ãã«å°çï¼ï¼
ãã¡ãªã¿ã«ãTensorFlowã§ã¯ãããã°ã©ã ä¸ã§ç»åãç°¡åã«Nå¢ããã¦ããããããªæ©è½ãç¨æããã¦ããã®ã§ãããã使ãã®ãç°¡åã§ãããTensorFlow以å¤ã®ãã¬ã¼ã ã¯ã¼ã¯ã使ãããã¨ãã®ãã¨ãèæ ®ããã®ã¨ã極ååå¦çã§ä½ããã£ã¦ããããèªåã§ææ¡ãã¦ããããã£ãã®ã§ãããã¦ç¬ç«ããã¹ã¯ãªãããç¨æãã¾ããã
ãTensorFlowã®Nå¢ãã«é¢ãã¦ç¥ãããæ¹ã¯ã以ä¸ã®TensorFlowã®cifar10ã¨ããç»åèªèã®ãµã³ãã«ããã°ã©ã ã®distorted_inputs
ãããã®é¢æ°ãåèã«ãªãã¨æãã¾ãã
ã©ãã«ä½æ
ã次ã«é¢åãªã©ãã«ä»ãã§ããããããä¸æ¬ã§ã§ããã¹ã¯ãªãããç¨æãã¦ãã¾ãã以ä¸å®è¡ããã ãã§ãã
$ cd ~/tensorflow-pi/data
$ python make_train_data.py image_data
ããã㧠/tmp/tensorflow_pi/
以ä¸ã« labels.txt
, train.txt
ã¨ãã£ããã¡ã¤ã«ãçæããã¾ããã¾ããæå¾ã«class number= 4
ã¨ãã£ã表示ãããã¾ããããã¯ãåé¡ããã¯ã©ã¹ã®æ°ã§ããä»åã¯ã3人ã®é¡ + ãã®ä»ã®åè¨4ã¯ã©ã¹ã«åé¡ãããã®ã§4ã表示ããã¾ãã
ã~/tensorflow-pi
ç´ä¸ã®cnn.py
ã¨ããããã°ã©ã ã¯ãåé¡ããã¯ã©ã¹ã®æ°ãç´æ¥å
¥åãã¦ããå¿
è¦ãããã¾ãã5è¡ç®ãã¿ãã¨NUM_CLASSES = 4
ã¨ãªã£ã¦ããã®ã§ãä»åã¯å¤æ´ä¸è¦ã§ãããããã¯ã©ã¹ã®æ°ã4以å¤ã ã£ãããã®æ°ã«æ¸ãæãã¦ãã£ã¦ä¸ããï¼ã§ããã°ããã¯èªåã§ããããã®ã§ã誰ããã£ããè¯ãæ¹æ³æãã¦ããã ãããGitHubã«PRããã ããã¨å©ããã¾ãï¼ã
ãmake_train_data.py
ã¯ãid:shi3z ããã®deelã¨ããChainerã®ã©ããã¼ããã°ã©ã ã®ãã¼ã«ã®ä¸é¨ãæ´»ç¨ããã¦ããã ãã¾ãããChainerç¨ã®ãã¼ã«ã§ã¯ããã¾ãããTensorFlowã«ãæ´»ç¨ã§ããç´ æ´ããããã¼ã«ã§ãããã¡ããã¡ãæè¬ã§ãã
GitHub - uei/deel: Deel; A High level deep learning description language
å¦ç¿
ãããããå¦ç¿ã§ããã¨ãã£ã¦ãããã£ã¬ã¯ããªç§»åãã¦ã³ãã³ã1çºã§ããç°¡åãå ·ä½çã«ã¯ä»¥ä¸ã§ãã
$ cd ~/tensorflow-pi
$ python train.py
ããã°ããå¾ ã¤ã¨ãå¦ç¿ãé²ãã§ããã¾ãã
step 0, training accuracy 0.144286, loss 39156.7 step 1, training accuracy 0.158571, loss 24045.2 step 2, training accuracy 0.200714, loss 16943.1 step 3, training accuracy 0.330357, loss 11338.4
ãloss
ãä¸ãã£ã¦accuracy
ãä¸ãã£ã¦ããã°OKã§ããloss
ãnan
ã«ãªã£ãå ´åã¯ãå¦ç¿å¤±æãã¦ãã¾ãã®ã§ãããç´ãã¦ãã ããã
ãä»åã¯ã3人+ãã®ä»(etc)ã®4ã«ãã´ãªã§ç´120æã®ç»åã§å¦ç¿ãã¾ããããã®ãããã ã¨ãRaspberry Piã§ã30åç¨åº¦ã§å¦ç¿ã§ãã¾ãããstep 200ã¾ã§è¡ãã¨å¦ç¿ãçµããã¾ããæå¾ã«ããã£ãæéã¨èªèçãåºã¦ãã¾ãã
çµæã¯ä»¥ä¸ã§ãã
step 198, training accuracy 0.988095, loss 3.84672 step 199, training accuracy 0.988095, loss 3.51081 elapsed_time:1472.91347504[sec] test accuracy 0.961538
ãæçµçã«èªèçã¯96%ã¨è¨ã£ã¦ãã¾ãããè¯ãããããªãï¼æ¬å½ï¼ï¼
ã30åãå¾ ã¡ãããªãã¨ãããã£ãã¡ãªäººã¯ãMacãLinuxãã·ã³ã使ã£ã¦åããã¨ããã¾ããããMacãLinuxã§ã®ç°å¢ã®æ§ç¯æ¹æ³ã¯ä»¥ä¸åç §ä¸ããã
ãåèã¾ã§ã«ã以ä¸ãããã®ã¹ããã¯ã®Corei5ãç©ãã Mac Book Proã§å®è¡ãã㨠3åç¨åº¦ã§ããã
$ system_profiler SPHardwareDataType Hardware: Hardware Overview: Model Name: MacBook Pro Model Identifier: MacBookPro12,1 Processor Name: Intel Core i5 Processor Speed: 2.7 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 3 MB Memory: 16 GB
ãä»ãXeonã®CPUã¨NVIDIA Quadroç©ãã 以ä¸ç¨åº¦ã®ã¹ããã¯ã®ã¯ã¼ã¯ã¹ãã¼ã·ã§ã³ãåãã¦è©¦ãã¦ã¿ãã®ã§ãããCPUã§1.5åãCUDAå ¥ãã¦GPU使ãã¨ãªãã¨20ç§ã§ãããã¨ããããGPUã¨ãä½ãæèãã¦ããã°ã©ã çµãã§ãªãã®ã«ã¡ããã¨æ©ããªããã§ãããTensorFlowåãã並ååã¨ããããããã£ã¨æ©ããªããã§ãããããã
$ lscpu Architecture: x86_64 CPU æä½ã¢ã¼ã: 32-bit, 64-bit Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 ã³ã¢ãããã®ã¹ã¬ããæ°:2 ã½ã±ãããããã®ã³ã¢æ°:4 Socket(s): 1 NUMA ãã¼ãæ°: 1 ãã³ãã¼ ID: GenuineIntel CPU ãã¡ããªã¼: 6 ã¢ãã«: 94 Model name: Intel(R) Xeon(R) CPU E3-1245 v5 @ 3.50GHz
ãå¦ç¿ã«ãããé度差ã¯ãRaspberry Piã¨ä¸è¬çãªãã·ã³ã®CPUã ã¨10åãã¡ãã£ã¨ããGPUç©ãã ãã·ã³ã ã£ãã100åãããéãã¨ããå°è±¡ã§ããï¼ãã¡ããæ¡ä»¶ã«ãã£ã¦å¤ãã£ã¦ãã¾ãã®ã§ããã¾ã§ç®å®ã§ãï¼ã
Tensor Boardã«ããå¯è¦å
ãTensorFlowã«ã¯Tensor Boardã¨ããå¯è¦åã½ãããä»å±ãã¦ãã¦ãå¦ç¿ã®æ§åããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã®æ§é ãªã©ãå¯è¦åãããã¨ãå¯è½ã§ããRaspberry Piä¸ã§å¦ç¿ãã¦ããå ´åã¯ãRaspberry Piã§ä»¥ä¸ã³ãã³ããå®è¡ãã¦ä¸ããã
$ tensorboard --logdir=/tmp/tensorflow_pi/
ããã¨ã¯ãifconfig
çã§èªåã®IPã¢ãã¬ã¹ã調ã¹ã¦ããã©ã¦ã¶ã§<ip address>:6006
ã«ã¢ã¯ã»ã¹ããã°å¯è¦åæ
å ±ãè¦ãã¾ããä¾ãã°IPã¢ãã¬ã¹ã192.168.0.10
ã ã£ãã192.168.0.10:6006
ã®ã¢ãã¬ã¹ã«ã¢ã¯ã»ã¹ãã¾ãããã
ããã©ã¦ã¶ã¯Raspberry Piä¸ã®Chromeãã©ã¦ã¶ã§ã¢ã¯ã»ã¹ãã¦ãOKã§ããããããã¯ã¼ã¯ã«ç¹ãã£ã¦ããä»ã®ãã·ã³ã®ãã©ã¦ã¶ã§ã¢ã¯ã»ã¹ãã¦ãOKã§ãããã ãMacã®Safariã¯ç§ã®ç°å¢ã§ã¯ãã¾ã表示ãããªãã£ãã®ã§ããã©ã¦ã¶ã¯FireFoxãChromeãããããããã¾ããã
ãRaspberry Piä¸ã§Tensor Boardãåããã¦ããæ§å
ããã ãTensor Boardã¯Raspberry Piä¸ã§åããã¨ããªãéãã®ã§ããã¾ãå®ç¨çã§ã¯ãªãããããã¾ããããã®å ´åã¯ãmatplotlibã§å¯è¦åããã®ã軽ãã¦ä¾¿å©ã§ãã
matplotlib/pandas ã«ããå¯è¦å
ãtrain.py
ã使ã£ã¦å¦ç¿ããã¨ãå¦ç¿ã®æ§åã/tmp/tensorflow_pi/train_graph.csv
ã¨ãããã¡ã¤ã«ã«æ¸ãåºããã¦ãã¾ãããããå¯è¦åããã«ã¯ã以ä¸ã³ãã³ããå®è¡ãã¦ä¸ããã
$ cd ~/tensorflow-pi
$ python plot_graph.py
ã以ä¸ã®ããã«ãå¦ç¿ã®æ§åã表示ããã¾ãããã®ããã«loss
ãä¸ããaccurarcy
ãä¸ãã£ã¦ããã¨ãæ£å¸¸ã«å¦ç¿ã§ãã¦ãããã¨ã«ãªãã¾ãã
ãmatplotlib/pandasã®å¯è¦åã«é¢ãã¦ã¯ã以ä¸ã®è¨äºãåç §ä¸ããã
ãmatplotlibãã©ããã¦ãããåãããªããè¦æã¨ãã人ã¯ã/tmp/tensorflow_pi/train_graph.csv
ãã¨ã¯ã»ã«ãªã©ã®è¡¨è¨ç®ã½ããã§å¥½ãã«ã°ã©ãã«ãã¦ãOKã§ãã
å¤å¥ãã¹ã
ãããã§90%ãããã®ç²¾åº¦ã§èªèã§ãããã¨ãåãã£ãããã§ããããªããåãããã§ããããä¿¡ãããã¾ããï¼ï¼ç§ã¯ä¿¡ãããã¾ããï¼ãã»ãã¨ã«ã¡ããã¨å¦ç¿ã§ãã¦ããããæ°ããæ®å½±ããé¡åçã§ãã¹ããã¦ã¿ããã§ãããããã¡ãããããªãã¹ãç¨ã®ããã°ã©ã ãç¨æãã¦ãã¾ãã
ãã¾ãã¯ããã¹ããããé¡åçããé¡ã®åãåºãã®ã¨ããã§è¡ã£ãã®ã¨åãè¦é ã§é¡ãåãåºãã¾ããåçã¯ãä»åã¯~/tensorflow-pi
以ä¸ã«test.jpg
ã¨ãããã¡ã¤ã«åã§ããã¾ããå¾ã¯ã以ä¸ã³ãã³ãã§å¤å¥ã§ãã¾ããä»åã¯ç§ã®åçã使ãã¾ããã
$ cd ~/tensorflow-pi $ python predict.py test.jpg
ãå®è¡ããã¨ã以ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
2017-08-09 22:01:12.554877: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-09 22:01:12.554923: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-08-09 22:01:12.554936: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-09 22:01:12.554946: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. karaage
ãã¡ããã¨æå¾ã«karaage
ã£ã¦åºã¦ããï¼åãï¼è³¢ãï¼
ãå¤å¥ãããã¾ã§ã®æéããã·ã³ã«ãã£ã¦ã¯ããããæéãããããããã¾ããããã»ã¨ãã©ã¯TensorFlowã®èªã¿åºãã«ãããæéã®ã¯ãã§ããä»å使ç¨ãããããã®å¦ç¿ã¢ãã«ã§ããã°ãRaspberry Piã§ãå®æéï¼1,2ç§ç¨åº¦ï¼ã§èªèã§ããã¯ãã§ãã
é¡èªèå®é¨
ããã¹ãã§ããããããããRaspberry Piä¸ã®ã«ã¡ã©ã§é¡èªèãããã¦ã¿ã¾ããããRaspberry Pi以å¤ã®ãã·ã³ã§å¦ç¿ããå ´åã¯ãå¦ç¿ããã¢ãã«ã®ãã¼ã¿ã¨ã©ãã«ãã¼ã¿ãRaspberry Piã«ã³ãã¼ãã¦ããã¦ä¸ããã
ãå
·ä½çã«ã¯ã~/tensorflow-pi/data/model
以ä¸ã®ãã¹ã¦ã®ãã¡ã¤ã«ï¼checkpoint , model.ckpt.data-00000-of-00001, model.ckpt.index, model.ckpt.meta, labels.txt
ï¼ã¨ãªãã¾ããã³ãã¼ããããRaspberry Piã«ã«ã¡ã©ã¢ã¸ã¥ã¼ã«ãæ¥ç¶ãã¦ãã«ã¡ã©ãæ®å½±ã§ããç¶æ
ã«ãã¦ããã¦ä»¥ä¸ãå®è¡ãã¾ãããï¼Raspberry Piã§ã«ã¡ã©æ®å½±ããæ¹æ³ã¯ãããã§ã¯è©³ç´°ã¯çç¥ãã¾ãã®ã§ãèªèº«ã§èª¿ã¹ã¦ä¸ããï¼
ãæºåãã§ãããã以ä¸ã³ãã³ããå®è¡ããã ãã§ãã
$ cd ~/tensorflow-pi
$ python face_recog_pi.py
ããã®ããã°ã©ã ã§ã¯ãRaspberry Piã®ã«ã¡ã©ã§æ®å½±ãã¦ãé¡æ¤åºãå®æ½ãé¡æ¤åºã«æåãããé¡ãåãåºããé¡èªèãè¡ãã¨ãããã¨ããã»ã¼ãªã¢ã«ã¿ã¤ã ã§å®æ½ãã¦ããã¾ãã以ä¸ãå®è¡ã®æ§åã§ãã
ãRaspberry Piã®ã«ã¡ã©ã§ãç§(karaage)ã®é¡ã¨ãå¨(lemon)ã®é¡ã交äºã«è¦ããã¨ãã¡ããã¨ããã£ã½ããªã¢ã«ã¿ã¤ã ã«èªèãã¦ããã¾ãã
ããã ãçµæ§èª¤èªèã¯å¤ãæãã§ãããã«ã¡ã©ã«ã¢ããã§é¡ããã¤ãã¨å²ã¨ãã¾ãããã®ã§ãããã«ã¡ã©ããã®è·é¢ãé¢ããã»ã©ééãã¦ãã¾ãããã§ããæè¦çã«ã¯ç²¾åº¦ã¯6ã8å²ã¨ãã£ãã¨ããã§ããããããããã£ãå®éã®ã«ã¡ã©ã«çµã¿è¾¼ãã ã¨ãã®ç²¾åº¦ã®è©ä¾¡ã¯é£ããã§ããã誤èªèã®è¦å ã¯è²ã èãããã¾ãã
- å¦ç¿ãããã¼ã¿ã¨å®éã«ãã¹ããããã¼ã¿ã®éãï¼Raspberry Piã«ã¡ã©ã¨ãã以å¤ã®ã«ã¡ã©ãæ®å½±å ´æï¼
- åçã®è§£å度ä¸è¶³ï¼ãªã¢ã«ã¿ã¤ã ã§é¡æ¤åºããããã解å度è½ã¨ãã¦ä¿åãã¦ããï¼
- ãã¼ã¿ä¸è¶³ or éå¦ç¿
- ããã°ã©ã ã«ãã°ããã
ãå®ç¨æ®µéã«ãã£ã¦ããããã«ã¯ãä¸è¨ã®è¦å ã1å1åã¤ã¶ãã¦ããå¿ è¦ãããã¾ããããã¡ããä»ã«ãåé¡ã¯å±±ç©ã¿ã¨æãã¾ãã
ãããã³ã®å¹»ã®é¡èªèæ©è½ã¯å®ç¾ã§ããã®ãï¼
ãã¯ã£ããè¨ã£ã¦ãã¾ãã°ããã®å®é¨ã ãã§ã¯è¯ãåããã¾ããã§ããï¼ãããããªãçµè«ã§ãã¿ã¾ããâ¦ï¼ããã ãå°ãªãã¨ãå®éã«ä¸è¬ã¦ã¼ã¶ã¼ã使ãããããªãã®ãä½ãã«ã¯ã大ããªèª²é¡ã沢山ããããã ãªã¨ãããã¨ã¯åããã¾ãããå ·ä½çã«ã¯ä»¥ä¸ã§ãã
- æ師ãã¼ã¿ã®éãæ¹
- æ§è½ã®åé¡
- å¦ç¿ã®åé¡
ãæ師ãã¼ã¿ã¯ãä¸è¬ã¦ã¼ã¶ã«é¡ãåãåºãã¦ç¨æãã¦ãããããã«ã¯ãããªãã®ã§ãè²ã ãªãã¿ã¼ã³ã®é¡åçããããã³ã«æ®ããããããªå·¥å¤«ãå¿ è¦ãªã®ã§ãããå¦ç¿ã«èããã沢山ã®åçãã¦ã¼ã¶ã«æ®å½±ãã¦ãããã¨ããã®ã¯ãä¸ã é£ããããªã¨æãã¾ãã
ãã¾ããæ§è½ã®åé¡ã¨ãã¦ãèªèç以å¤ã®åé¡ã¨ãã¦ãé¡ãæ£é¢ãåãã¦ããªãã¨ãã¾ãæ¤åºã§ããªãã£ããããã¾ãã解決çã¨ãã¦ãæ¤åºã¾ã§ãã£ã¼ãã©ãã³ã°ã«ããããæ¹æ³ãããããã§ããï¼ããããæè¡ã¯ããï¼ããã ãããã¯ããã§è²ã 大å¤ããã§ãã
ãéã«ãå®é¨ããåã«æ¸å¿µãã¦ããå¦ç¿æéã¯ãã¨ãããã家æåããããªãæã£ãã»ã©ãããã¾ããã§ããããã ã10人ã20人ã¨å¢ãã¦ããã¨è¨ç®éãæ¯ä¾ãã¦å¢ãã¦ããã®ã¨ããããã¯ã¼ã¯ãå¤ããªãã¨ãã¾ãå¦ç¿ã§ããªãã¨ãã£ãåé¡ãåºã¦ãããã§ããå®éã101ã¯ã©ã¹ã«åé¡ããCaltech101ã¨ããæåãªãã¼ã¿ã»ããã§ã®å¦ç¿ã試ãã¦ã¿ãã®ã§ããããã¥ã¼ã©ã«ãããã®æ§é ãå¤æ´ããªãã¨ãã¾ãå¦ç¿ã§ãã¾ããã§ãããCaltech101ã¯tensorflow-pi
ã使ã£ã¦ä»¥ä¸ã³ãã³ãã§ãã¦ã³ãã¼ãã§ããã®ã§èå³ãããæ¹ã¯ãããã¯ã¼ã¯ãå¤ãã¦è²ã
試ãã¦ã¿ã¦ãã ããã
$ cd ~/tensorflow-pi/data
$ ./getCaltech101.sh
ã¾ã¨ã
ããããã³ã®å¹»ã®é¡èªèæ©è½ã«ãã£ã¼ãã©ã¼ãã³ã°ã§ææ¦ãã¦ã¿ã¾ãããããããç§ãããã¾ã§ããªããã·ã£ã¼ãã®åªç§ãªã¨ã³ã¸ãã¢ãããªãæ¢ã«ãã®ãããã®å®é¨ã¯ã¨ã£ãã«æ¸ã¾ãã¦ããã¨æãã¾ããããã¦ããã¾ãã®é£æ度ã«çµ¶æãã¦ããã®ãããªãããªãã¨åæã«åæ ãã¦ãã¾ãï¼ç¬ï¼ãããã®æ©è½ãé«ãæ§è½ã§å®ç¾ããããéçºããã·ã£ã¼ãããã®ã¨ã³ã¸ãã¢ã«ã¯æãã¿ãªãè³è³ãéããããªã¨æãã¾ãã
ããã£ã¼ãã©ã¼ãã³ã°ã¨ããã¨ããªãã§ãã§ãããããªæ°ããã¦ãã¾ãã¾ãããéããããªã½ã¼ã¹ã§æç¨ãªã¢ããªã±ã¼ã·ã§ã³ãä½ããã¨ããã¨ã¾ã ã¾ã 課é¡ããããã¨ããããã¾ããä»å¾ã¯ããããã£ãå®ç¨çãªé¨åã®æè¡ã®çºå±ãéè¦ã«ãªã£ã¦ããã®ããããã¾ãããã
ãæå¾ã«ãä»åå®éã«å®é¨ãã¦ã¿ã¦ããã£ããã¨ã®ã¾ã¨ãã§ãã
- æ師ãã¼ã¿éããã®ã大å¤ãã¨ã«ãã大å¤
- ãã¤ãã¼ãã©ã¡ã¼ã¿ã¯éè¦ï¼ç¹ã«å¦ç¿çï¼
- ãã£ã¼ãã©ã¼ãã³ã°ã®ãã¬ã¼ã ã¯ã¼ã¯ã¯è²ã ããããèªåãã¼ã¿ã®æ´»ç¨ããã«ã¯ãçµæ§èªåã§ä½ããªãã¨ãããªããã®ãå¤ã
- Raspberry Piã§ãã£ã¼ãã©ã¼ãã³ã°çµæ§è²ã ã§ãããã ãã©ãã¢ã³ã¹ã¿ã¼ãã·ã³ã¯æ¬²ãã
ãæ師ãã¼ã¿éãã¯ãå®éã«ãã£ã¦ãã人ã«èãã¨èª°ãããè¨ãã®ã§ããããããæ¬å½ã«å¤§å¤ã§ããåå¦çã¾ã§å«ãã¦è¨ããªããããã»ã¼å ¨ã¦ããããã¾ãããä»åã ã¨ãã¾ãé¡æ¤åºãã¦åãåºãã½ããããä½ãå§ãã¾ãããããã
ããã¡ãããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã®æ§é ã ã£ãããå¦ç¿çã¨ãã£ããã¤ãã¼ãã©ã¡ã¼ã¿ãéè¦ã§ããæåãå
¨ç¶å¦ç¿ããã¾ããããªãã£ãã®ã§ãããå¦ç¿çãå¤ããã ãã§å¦ç¿ãåæããããã«ãªã£ãããã¦ããªããªãé¢ç½ãã£ãã§ããå¦ç¿çã®å¤ã¯ãtrain.py
ã®18è¡ç®ã®learning_rate
ãå¤ãããã¨ã§å¤æ´ã§ãã¾ãã®ã§ãèå³ããã°è²ã
試ãã¦ã¿ã¦ä¸ããã
flags.DEFINE_float('learning_rate', 1e-5, 'Initial learning rate.')
ãã¯ã©ã¹ã®æ°ã ã£ããã解ãåé¡ã«ãã£ã¦æé©ãªãããã¯ã¼ã¯ãå¤ãã£ã¦ããã®ã¯ãå ã»ã©è¿°ã¹ãéãã§ããã
ãæå¾ã«ãRaspberry Piã§ãã£ã¼ãã©ã¼ãã³ã°ã§ãããå人çã«ã¯çµæ§å¯è½æ§ãæãã¾ãããä¸ã®ä¸ã«ãããã£ã¼ãã©ã¼ãã³ã°ã®state-of-artãªã¢ãã«ã¯ãã¨ã«ããå¤ãã®ã¯ã©ã¹ã«æ£ç¢ºã«åé¡ãããã¨ãç®æãã¦ã馬鹿ã§ãããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã«ãªã£ã¦ãããã¨ãå¤ãã®ã§ãããRaspberry Piã§åããããªå°ããªãã¥ã¼ã©ã«ãããã¯ã¼ã¯ã§ããç¨éã«ãã£ã¦ã¯ååãªç²¾åº¦ãåºããããªã®ã§ã工夫ããã°ãã®åãå®ã身è¿ãªåé¡ã解決ããè¶ å°åãªäººå·¥ç¥è½ãä½ãã¦ãã¾ãããããã¾ããï¼ãã¥ã¦ãªã®ä»åãæ©ããã®ä¸ä¾ã§ããï¼ã
ãä¸æ¹ã§ãæ¬æ ¼çã«ãã£ã¼ãã©ã¼ãã³ã°ã®ãã©ã¡ã¼ã¿ãã¥ã¼ãã³ã°ãããã¥ã¼ã©ã«ãããã¯ã¼ã¯ã®è¨è¨ããããã¨ãªãã¨ãã©ãã ã試è¡é¯èª¤ã§ããããåè² ã«ãªã£ã¦ããã®ã§ãRaspberry Piã§ç©è¶³ããªããªã£ãããå ¥éã¯åæ¥ãã¦GPUç©ãã ãã·ã³ã®è³¼å ¥ãã¯ã©ã¦ããªã©ãå¿ è¦ã«ãªã£ã¦ããã®ããªã¨æãã¾ãããã¡ãªã¿ã«å¤§éã®ãã¼ã¿å¦ç¿ããããã¨ããã¨GPUã®ã¡ã¢ãªãéè¦ã§ããï¼Caltech101ã®ãã¼ã¿ã2GBã®GPUã§å¦ç¿ããããã¨ãããã¡ã¢ãªã溢ãã¦ã¨ã©ã¼ã«ãªãã¾ããï¼ã
Raspberry Pi + Chainerã§åããããªãã¨ã試ããã人ã¸
ãä»åç§ã¯Raspberry Piã¨TensorFlowã®çµã¿åããã§é¡èªèã試ãã¾ããããRaspberry Piã¨Chainerã®çµã¿åããã§åããããªãã¨ããç§ãããã£ã¨åã«è©¦ãã¦ãã人ããã¾ãããå®éã®ã¢ããªã±ã¼ã·ã§ã³ã¯ä»¥ä¸ã®ãããªæãã§ããChainerã§ãTensorFlowã¨åæ§ã«ãå°ããã®ãã¥ã¼ã©ã«ãããã¯ã¼ã¯ãªããªã¢ã«ã¿ã¤ã ãªèªèã¯ã§ããããã§ããã
ãé¡èªèã®ã½ããã®ãªãã¸ããªã¯ä»¥ä¸ã«ãªãã¾ãã
ãã³ã¼ãã®æ¸ãæ¹ãåå¦ç¿ã®ä»æ¹ãã¬ãã¼ãã®ã¾ã¨ããããã¥ã¡ã³ãã®æ¸ãæ¹ãªã©å ¨ã¦ãåèã«ãªãã¾ããããªã¹ã¹ã¡ã§ãã
ç»åèªèã®ãã¥ã¼ããªã¢ã«å ¬éãã¦ãã¾ã
ãæ¬è¨äºã®å 容ã説æä¸è¶³ã§åããã«ããï¼æ師ãã¼ã¿ãéããã®ã大å¤ï¼ç°å¢æ§ç¯ãã§ããªãï¼ãã¼ã¸ã§ã³éããåå ã§åããªãï¼ï¼ã¨ãã£ãæ¹ã«åãã¦ãæænoteã§ç»åèªèã®ãã¥ã¼ããªã¢ã«ãå ¬éãã¦ãã¾ãããGoogle Colaboratoryãã¨ãããµã¼ãã¹ã使ããã¨ã§ããã©ã¦ã¶ã ãã§ç°å¢æ§ç¯ä¸è¦ã§ç°¡åã«ãã£ã¼ãã©ã¼ãã³ã°ã§ã®ç»åèªèãå®è·µããªããå¦ã¶ãã¨ãã§ãã¾ããèå³ããæ¹ã¯æ¯éããããã ããã
é¢é£è¨äº
åèãªã³ã¯
TensorFlowでアニメゆるゆりの制作会社を識別する - kivantium活動日記
tensorflow/mnist_deep.py at r1.2 · tensorflow/tensorflow · GitHub
TensorFlow の "AttributeError: 'module' object has no attribute 'xxxx'" エラーでつまづいてしまう人のための移行ガイド - Qiita