Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

TensorFlow LiteでGPUが使えるようになった



これ記事によると、TensorFlow LiteでGPUが利用できるみたい。

 ・OpenGL ES 3.1 Compute Shaders on Android devices

 ・Metal Compute Shaders on iOS devices

GPUを利用することで、Floatの演算処理のまま処理速度をあげられるようです。
ただし、現時点ではオープンソースでは無く、バイナリの提供のみ。
ソースコードの提供は、2019年末のころです。

パブリックなモデルとして、以下の4つがダウンロード可能
 ・MobileNet v1 (224x224) image classification [download]
  (image classification model designed for mobile and embedded based vision applications)

 ・PoseNet for pose estimation [download]
  (vision model that estimates the poses of a person(s) in image or video)

 ・DeepLab segmentation (257x257) [download]
  (image segmentation model that assigns semantic labels (e.g., dog, cat, car) to every pixel in the input image)

 ・MobileNet SSD object detection [download]
  (image classification model that detects multiple objects with bounding boxes)

また、Googleオリジナルのモデルとして、次の2つもダウンロード可能
 ・Face contours as used by MLKit

 ・Realtime Video Segmentation as used by Playground Stickers and YouTube Stories

AndroidJavaのサンプルコード
引用します
// Initialize interpreter with GPU delegate.
GpuDelegate delegate = new GpuDelegate();
Interpreter.Options options = (new Interpreter.Options()).addDelegate(delegate);
Interpreter interpreter = new Interpreter(model, options);

// Run inference.
while (true) {
  writeToInputTensor(inputTensor);
  interpreter.run(inputTensor, outputTensor);
  readFromOutputTensor(outputTensor);
}

// Clean up.
delegate.close();

InterpreterのaddDelegateって、ここですよ
    /**
     * Adds a {@link Delegate} to be applied during interpreter creation.
     *
     * <p>WARNING: This is an experimental interface that is subject to change.
     */
    public Options addDelegate(Delegate delegate) {
      delegates.add(delegate);
      return this;
    

Delegateを変えるだけだからね。

質問は、Githubか、stack overflow