Google Coral USB Accelerator 使用說明
參考資料
https://www.tensorflow.org/lite/guide
https://github.com/google-coral/edgetpu
https://www.pyimagesearch.com/2019/04/22/getting-started-with-google-corals-tpu-usb-accelerator/
目錄
(一) 安裝Debian 10.4
(二) 安裝Ubuntu 18.04 on VM Workstation
(三) 安裝Windows 10
(一) 安裝Debian 10.4
Step00.預先安裝下面的套件,並已安裝Anaconda3 虛擬環境,並建立好虛擬環境tf_lite
Step01. 加入下載的位置相關指令
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - sudo apt-get update
Setp02. 安裝 Eege TPU runtime
sudo apt-get install libedgetpu1-std
Setp03. 插入USB Accelerator,並確認USB Device 是否有 ID 1a6e:089a Global Unchip Corp.
lsusb
Step04. 安裝 TensorFlow Lite on x86_64,要確認python版本,並安裝對應版本的
https://www.tensorflow.org/lite/guide/python
pip install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl
Step05. 執行python ,並驗證tensorflow lite是否安裝成功
import tflite_runtime.interpreter as tflite
Step06. 驗證TensorFlow Lite 是否有使用Edge TPU來處理
mkdir coral && cd coral git clone https://github.com/google-coral/tflite.git cd tflite/python/examples/classification bash install_requirements.sh
python3 classify_image.py \ --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \ --labels models/inat_bird_labels.txt \ --input images/parrot.jpg
正常情況有接Edge TPU 會顯示測試的數據,parrot圖片不會顯示
沒有接Edge TPU 會顯示錯誤
Step07. 另外安裝python3-edgetpu
sudo apt-get install python3-edgetpu
安裝完後其設定和驗證,請參考下一篇"安裝Ubuntu 18.04 on VM Workstation"
(二) 安裝Ubuntu 18.04 on VM Workstation
Step00.預先安裝下面的套件,並已安裝Anaconda3 虛擬環境,並建立好虛擬環境tflite
sudo apt-get update sudo apt-get install git curl python3-pip openssh-server -y
Step01. 加入下載的位置相關指令
# 將Package來源清單加入至系統套件來源名單 echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list # 下載來源清單驗證金鑰並加入至套件金鑰管理 curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - # 執行所有套件資訊更新 sudo apt-get update
Setp02. 安裝 Eege TPU runtime
# 安裝EdgeTPU runtime library(此為一般標準模式,也就是標準效能運作) sudo apt-get install libedgetpu1-std -y or # 如果需要最大效能模式,請改安裝下面EdgeTPU runtime library(需要搭配USB3.0) sudo apt-get install libedgetpu1-max -y
Setp03. 插入USB Accelerator,並確認USB Device 是否有 ID 1a6e:089a Global Unchip Corp.
lsusb
如果沒有device時要確認VM的USB設定是否為USB3.0
Step04. 安裝 TensorFlow Lite on x86_64,先進入虛擬環境tflite,再確認python版本,並安裝對應版本的
https://www.tensorflow.org/lite/guide/python
conda activate tflite python --version curl -O https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl pip install tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl
Step05. 執行python ,並驗證tensorflow lite是否安裝成功
import tflite_runtime.interpreter as tflite
Step06. 驗證TensorFlow Lite 是否可以使用Edge TPU來處理
https://github.com/google-coral/tflite/tree/master/python/examples/classification
mkdir coral && cd coral git clone https://github.com/google-coral/tflite.git cd tflite/python/examples/classification bash install_requirements.sh
執行範例程式
# 主程式檔案 classify_image.py # 第一個參數 --model 指定使用tflite模型來源 # 第二個參數 --labels 指定分類標籤來源 # 第三個參數 --input 指定輸入圖片來源 python classify_image.py \ --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \ --labels models/inat_bird_labels.txt \ --input images/parrot.jpg #不使用edgetpu 所測試的數據 python classify_image.py \ --model models/mobilenet_v2_1.0_224_inat_bird_quant.tflite \ --labels models/inat_bird_labels.txt \ --input images/parrot.jpg
正常情況有接Edge TPU ,並使用edgetpu會顯示測試的數據,
不使用edgetpu所顯示測試的數據
parrot圖片不會顯示,如要顯示圖片只要修改classify_image.py,加入image.show()
另一個範例,請參考下面網站
https://github.com/google-coral/tflite/tree/master/python/examples/detection
Step07.安裝EdgeTPU官方Python API 函式庫
https://coral.ai/docs/edgetpu/api-intro/#install-the-library-and-examples
# 安裝EdgeTPU官方Python API 函式庫 sudo apt install python3-edgetpu -y
要確認edgetpu 的安裝路徑,
#確認edgetpu 的安裝路徑 sudo find / | grep edgetpu #到下面的路徑,新增一個edgetpu link cd conda/envs/tflite/lib/python3.7/site-packages/ ln -s /usr/lib/python3/dist-packages/edgetpu ls -l
如果沒有新增edgetpu link,執行程式會錯誤
Step08.安裝EdgeTPU Examples
# 安裝EdgeTPU官方Python提供範例包與程式環境設置 sudo apt install edgetpu-examples -y # 安裝完畢範例資料夾會存在 /usr/share/edgetpu/examples/
Step09. 測試Edge TPU 範例
# 執行範例程式 # 主程式檔案 classify_image.py # 第一個參數 --model 指定使用tflite模型來源 # 第二個參數 --labels 指定分類標籤來源 # 第三個參數 --image 指定輸入圖片來源 python /usr/share/edgetpu/examples/classify_image.py \ --model /usr/share/edgetpu/examples/models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \ --label /usr/share/edgetpu/examples/models/inat_bird_labels.txt \ --image /usr/share/edgetpu/examples/images/parrot.jpg
Step10.只使用Tensorflow lite,而不使用edge tpu的範例
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/examples/python/
下載資料
# Get photo curl https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/lite/examples/label_image/testdata/grace_hopper.bmp > /tmp/grace_hopper.bmp # Get model curl https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz | tar xzv -C /tmp # Get labels curl https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_1.0_224_frozen.tgz | tar xzv -C /tmp mobilenet_v1_1.0_224/labels.txt mv /tmp/mobilenet_v1_1.0_224/labels.txt /tmp/
執行測試
python label_image.py \ --model_file /tmp/mobilenet_v1_1.0_224.tflite \ --label_file /tmp/labels.txt \ --image /tmp/grace_hopper.bmp
(三) 安裝Windows 10
Step01.加入下載的位置相關指令
Step02.安裝 Eege TPU runtime
Step03.插入USB Accelerator,並確認USB Device 是否有 ID 1a6e:089a Global Unchip Corp.
Step04.安裝 TensorFlow Lite on x86_64,要確認python版本,並安裝對應版本的
Step05.執行python ,並驗證tensorflow lite是否安裝成功
Step06.驗證TensorFlow Lite 是否有使用Edge TPU來處理
Step07.