古人智慧

Just Do it!
上士聞道,勤而行之;中士聞道,若存若亡;下士聞道,大笑之。不笑,不足以爲道。
~ 道德經 41

「實現夢想不是追逐成功,而是在於賦予生命意義,人生中的每個決定與聲音都有其重要含義。」"The key to realizing a dream is to focus not on success but on significance — and then even the small steps and little victories along your path will take on greater meaning."
電視名人-歐普拉·溫芙蕾(OPRAH WINFREY)

搜尋此網誌

Translation

顯示具有 4.1 RaspberryPi樹莓派 標籤的文章。 顯示所有文章
顯示具有 4.1 RaspberryPi樹莓派 標籤的文章。 顯示所有文章

2019年8月15日 星期四

[Object Detection by Tensorflow] 物件辨識

Here is just do some note for how to setup and install the object detection by Tensorflow on Raspberry Pi 3B+.
The original article here
Ok, let’s go my practise.

1. Update the Raspberry Pi

sudo apt update
sudo apt upgrade
sudo apt autoremove
Refer to here
You should install this tool as well.
sudo apt install protobuf-compiler

3. Setup the Tensorflow models

mkdir tf_objectdetect
cd tf_objectdetect/

git clone https://github.com/tensorflow/models
Download/unzip the pre-trained model in this folder
wget http://download.tensorflow.org/models/object_detection/ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz
tar -xzvf ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz
Copy this file models\research\object_detection\data\mscoco_label_map.pbtxt to data folder.
mkdir data
cp models/research/object_detection/data/mscoco_label_map.pbtxt data/.
compile the protos database
cd models/research/
protoc object_detection/protos/*.proto --python_out=.

cd models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
It will be better that add this line to .bashrc
# for tensorflow object detection 
export PYTHONPATH=$PYTHONPATH:/home/pi/tf_objectdetect/models/research:/home/pi/tf_objectdetect/models/research/slim

4. Do the Object detection

Download the code, and test
cd ~/tf_objectdetect
wget https://raw.githubusercontent.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi/master/Object_detection_picamera.py

python3 Object_detection_picamera.py
You may got problems just like me, do some modify would be solved as below process.
nano Object_detection_picamera.py
Line 52
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
Line 66
PATH_TO_LABELS = os.path.join(CWD_PATH,'models/research/object_detection/data','mscoco_label_map.pbtxt')

That is and you will be ok for this practise

​

2019年1月1日 星期二

Node.js install on Raspbian/Raspberry Pi

最近正學習Google的Firebase與DialogFlow,裡面用到的language是Node.js。
每次學習新的language,安裝套件是最令人頭痛的部分。時常遇到安裝失敗、缺東缺西、版本與Module不合、不然執行會crash~~
我一開始是用
sudo apt install nodejs
後來用了npm安裝各種module都出現權限不足,時常要加上sudo,也搞到自己的code也無法write的權限,經過多方search,使用nvm是最恰當的的安裝方式。

安裝過程

1. 首先,安裝nvm

先到nvm的github - nvm link

https://github.com/creationix/nvm
下面有安裝說明,最重要就是這行,注意注意注意,有關於版號會與我不同,請用最新版本。

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
到這裡nvm安裝OK,最好是把樹莓派reboot。

2. 安裝NodeJs

因為Node一直快速升級,時常會發生不相容情況。
所以要找一個配合Firebase版本也讓我花了好多時間。
目前這樣搭配是最合適,nodejs@8.15.0 + firebase@5.7.2
安裝nodejs

nvm install v8.15.0
安裝OK後,測試一下

node -v
如果出現v8.15.0那就確定ok。

3. 安裝Firebase套件

Google Firebase有提供一組Node的套件,而沒有熱門的Python有點詭異。

npm install firebase
到這裡應該把Firebase套件裝起來。

4. Test code

在$HOME產生一個子目錄來放測試code

mkdir nodejs

cd nodejs
參考這些前人高手文章,建立Firebase database,然後樹莓派用Nodejs來連上Firebase,控制LED燈。

5. 其他用到的指令

nvm ls-remote
nvm ls
nvm alias default 8.15.0

npm list

參考文章

​

2018年9月4日 星期二

Raspberry Pi 3B+ 樹莓派 - TensorFlow+Keras+OpenCV installation guide

這樹莓派要裝上AI的工具讓我折騰了好一陣子,真是累人。
趁記憶還清楚,把過程寫下:

基礎設備

Raspberry Pi 3B+
官網下載最新image影像檔 RASPBIAN STRETCH WITH DESKTOP
燒錄到至少16GB的SD卡,插到3B+然後開機把WiFi與相關流程完成設定。
注意: 不要讓開機程序執行自動安裝更新,因為會等好久。這步驟待會會再做。。。

重啟後,進入到pi,然後開始以下流程重點安裝:

清除不需要的APPs,省下1GB以上。

sudo apt-get purge wolfram-engine
sudo apt-get purge libreoffice*
sudo apt-get clean
sudo apt-get autoremove

開始更新Raspbian,

sudo apt update
sudo apt upgrade

sudo apt autoremove

把swap增加大一些,避免在執行安裝時出錯。

sudo nano /etc/dphys-swapfile

# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation
#CONF_SWAPSIZE=100
CONF_SWAPSIZE=1024
重啟後,進入到pi,因為Raspbian已經自帶Python3.5.3,可以直接安裝TensorFlow,記得要用pip3!!!

安裝TensorFlow:

sudo apt install libatlas-base-dev
pip3 install --user tensorflow
如果沒出現error,就繼續下一步。 如果有錯誤訊息,參考TensorFlow官網

安裝OpenCV

sudo apt install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt install libxvidcore-dev libx264-dev
sudo apt install qt4-dev-tools

pip3 install --user opencv-python

安裝Keras

sudo apt install python3-h5py
pip3 install --user keras

安裝其他工具、繪圖與影像處理模組:

pip3 install --user pillow lxml jupyter matplotlib
安裝jupyter後,用nano ~/.bashrc把export PATH=$PATH:~/.local/bin加入到最後一行。 然後輸入source .bashrc,不然會出現 command not found!!

Jupyter remote用法:

In remote host, open the terminal, change directory to where you have your notebooks and type:
#on the 3B+ site
jupyter notebook --no-browser --port=8889

#on the PC/Mac site
ssh -N -f -L localhost:8001:localhost:8889 pi@192.168.1.xxx
然後在PC/Mac端的browser輸入localhost:8001就連上樹莓派的jupyter開始寫code測試。
Oh, one more thing. Tensorflow會有機會Google `Protocal Buffer’這個工具,建議一起裝上。
sudo apt install protobuf-compiler

就這樣OK了!!!

​