Site icon GRIP.News

Google Coral, Edge TPU 컴파일러

Edge TPU Compiler(edgetpu_compiler)는 TensorFlow Lite 모델(.tflite file)을 Edge TPU에서 사용할 수 있도록 크로스 컴파일해 주는 도구다. 모든 TensorFlow Lite 모델이 Edge TPU와 100% 호환된다고 보장할 수 없기 때문에 사전에 코드를 면밀히 검토해야 한다.

 

설치


Edge TPU Compiler는 대부분의 Debian 6.0을 호환하는 Linux에서 사용할 수 있다. 참고로 필자도 Coral 응용 프로그램 개발을 WSL Ubuntu(=Debian에서 파생된) 18.04에서 진행하고 있다.

명령어에 필요한 모든 권한은 root로 진행하자.

root@WORKS-HP-G400:/home/gloriashield# echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main"| tee /etc/apt/sources.list.d/coral-edgetpu.list
root@WORKS-HP-G400:/home/gloriashield# curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
root@WORKS-HP-G400:/home/gloriashield# apt-get update
root@WORKS-HP-G400:/home/gloriashield# apt-get install edgetpu-compiler
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libedgetpu1-std
The following NEW packages will be installed:
  edgetpu-compiler libedgetpu1-std
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 4998 kB of archives.
After this operation, 18.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
....
root@WORKS-HP-G400:/home/gloriashield# edgetpu_compiler
Edge TPU Compiler version 2.1.302470888

Usage:
edgetpu_compiler [options] model...

Options:
-o, --out_dir <dir>

edgetpu_compiler 명령어가 실행된다면 정상적으로 설치된 것.

 

사용방법


컴파일러는 하나 이상의 TensorFlow Lite 모델을 포함, 파일과 여러 옵션을 명시해 사용할 수 있다. 컴파일된 모델의 파일 이름은 input_filename_edgetpu.tflite이며, -out_dir를 사용해 저장될 위치를 바꿀 수 있다.

Edge TPU는 하나의 모델만 실행하고 있을 때 최고의 추론 속도를 제공한다. 이것은 Edge TPU에서 사용 가능한 메모리/캐시 공간이 한 번에 여러 모델을 대응할 수 없기 때문이다. Edge TPU에서 강제로 여러 모델을 실행하게 한다면 모델을 교체할 때마다 캐시를 지워야 하기 때문에 파이프라인 전체 속도가 느려진다. 이런 병목 현상을 해결하려면 각 모델을 각각의 다른 Edge TPU로 실행해야만 한다.

Coral 하드웨어에 사용된 Edge TPU칩은 양자화된 모델을 사용하도록 설계되어 있다. 양자화는 정확도에 미치는 영향을 최소한으로 하면서 기반이 되는 데이터를 압축해 간결하고 빠른 모델링하는 것을 말한다. Tensor Flow Lite Converter를 사용하면 모든 학습된 Tensor Flow 모델을 양자화할 수 있다. 이 부분은 다음에 다시 다뤄 보고자 한다.

 

 

 

 

 

Exit mobile version