C.W.K.
Stream
Lesson 04 of 05 · published

TFLite Interpreter와 하드웨어 delegate

~11 min · interpreter, delegates, edge-tpu, core-ml

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

Model이 실제로 도는 곳

TFLite Interpreter는 device에서 .tflite model 실행하는 runtime. Python (mobile 배포 전 데스크톱 테스트에 유용)에선 tf.lite.Interpreter 사용.

Delegate는 TFLite가 특화 하드웨어로 계산 offload하게 해줘. 각 delegate는 plugin — TFLite가 지원되는 op 먼저 delegate에 시도, 미지원 op는 CPU로 fallback.

Delegate하드웨어플랫폼지원 quant
GPU DelegateOpenCL/Metal GPUAndroid, iOS, Linuxfp32, fp16, dynamic range
Core ML DelegateNeural Engine (A12+)iOS 12+fp32, fp16
Edge TPUCoral Edge TPULinux/Win/macOSfull int8만
NNAPINeural Proc UnitAndroid 8.1–14device마다 다름

Delegate 선택과 quantization 선택이 묶여있어. Coral Edge TPU 타깃? full int8 quantization 필수. iOS Neural Engine 타깃? fp16. 배포 타깃 고려 없이 quantization tier 고르면 작업 낭비.

Code

Python interpreter — desktop testing·python
import tensorflow as tf
import numpy as np

interpreter = tf.lite.Interpreter(model_path='model.tflite')
interpreter.allocate_tensors()

input_details  = interpreter.get_input_details()
output_details = interpreter.get_output_details()

print("Input shape:", input_details[0]['shape'])
print("Input dtype:", input_details[0]['dtype'])

# Run inference
input_data = np.random.rand(1, 224, 224, 3).astype(np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()

output = interpreter.get_tensor(output_details[0]['index'])
print("Predictions:", output)
Edge TPU delegate·python
import tflite_runtime.interpreter as tflite

# Coral Edge TPU — requires libedgetpu installed
interpreter = tflite.Interpreter(
    model_path='model_edgetpu.tflite',
    experimental_delegates=[
        tflite.load_delegate('libedgetpu.so.1')      # Linux
        # tflite.load_delegate('libedgetpu.1.dylib')  # macOS
        # tflite.load_delegate('edgetpu.dll')          # Windows
    ]
)
interpreter.allocate_tensors()

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.