반응형

1편 : Coral Board 대신 라즈베리파이를 사용하는 이유 : https://coding-yoon.tistory.com/85?category=866905

2편 : USB Accelerator(Edge TPU) 환경설정 : https://coding-yoon.tistory.com/87?category=866905

 

안녕하세요.

 

라즈베리파이에서 인공지능 예제를 간단하게 돌려보겠습니다. 

 

혹시 준비가 되지 않으셨다면 2편을 읽고 오시는 것을 추천드립니다. 

 

 

mkdir coral && cd coral  # coral 디렉토리 생성

git clone https://github.com/google-coral/tflite.git  

 

 

cd tflite/python/examples/classification

bash install_requirements.sh
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   189  100   189    0     0    314      0 --:--:-- --:--:-- --:--:--   313
100 3972k  100 3972k    0     0  1622k      0  0:00:02  0:00:02 --:--:-- 4012k
100   181    0   181    0     0    332      0 --:--:-- --:--:-- --:--:--   332
100 3448k  100 3448k    0     0  1739k      0  0:00:01  0:00:01 --:--:-- 6748k
100   158  100   158    0     0    541      0 --:--:-- --:--:-- --:--:--   541
100 40895  100 40895    0     0  63699      0 --:--:-- --:--:-- --:--:-- 3968k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   148  100   148    0     0    361      0 --:--:-- --:--:-- --:--:--   361
100  582k  100  582k    0     0   483k      0  0:00:01  0:00:01 --:--:-- 2277k

github에서 classification과 detection이 같이 설치가 됩니다. 

 

document처럼 classification을 따라할겁니다. detection read.md를 보시고 따라하시면 됩니다. 

 

 

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

 

classify_image.py를 실행하고 뒤에 3개의 Argumnets가 따라옵니다. 

 

python의 argparse 라이브러리를 사용해 인자 값을 달리 줘서 다르게  동작시킬 수 있습니다. 

 

머신러닝에서 많이 사용하는 함수인데, 이것은 설명할 수 있는 기회가 있으면 자세히 설명하도록 하겠습니다.

 

인자 값으로 세 개의 파라미터가 전달됩니다. 

 

꼭 argparse를 사용할 필요는 없습니다. 나중에 tensorflow lite interpreter를 사용하는 방법에 대해 설명할 것입니다. 

 

지금은 아 그런가보다 하고 넘어가시면 됩니다.

 

실행해보겠습니다.

 

parrot.jpg

----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
17.1ms
4.4ms
4.4ms
4.3ms
4.5ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.77734

# 77% Ara macao 라는 새라고 예측함

Ara macao

예측을 잘한 것 같습니다. 속도도 ms 단위로 나름 빠르게 inference해줍히다. 

 

libedgetpu1-max를 시켜주면 더 빨라지겠죠?

 

다음 글은 자신이 만든 모델을 TPU에 넣기 좋은 모양으로 만드는 방법을 올리겠습니다.

 

https://coral.ai/docs/accelerator/get-started/#3-run-a-model-using-the-tensorflow-lite-api

 

Get started with the USB Accelerator | Coral

Learn how to set up the Coral USB Accelerator and run some demo code.

coral.ai

 

728x90
반응형

+ Recent posts