You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何构建TensorFlow Lite benchmark_model?Android编译报错求助

Building TensorFlow Lite Benchmark Model & Fixing That Bazel Warning

1. How to Build TensorFlow Lite's benchmark_model for Android arm64-v8a

First, let's make sure you're set up correctly:

  • Clone the TensorFlow source code (stick to a stable 2.x release—older versions have deprecated paths that cause unnecessary issues)
  • Install a Bazel version compatible with your TensorFlow release (check TensorFlow's release notes for exact versions; mismatches lead to all sorts of headaches)
  • Set up the Android NDK and SDK, with ANDROID_NDK_HOME and ANDROID_SDK_HOME environment variables pointing to their respective directories.

The command you used is almost right, but note that in newer TensorFlow versions, the path changed from tensorflow/contrib/lite to tensorflow/lite (the contrib module was phased out). Here's the updated build command:

bazel build -c opt --cxxopt='--std=c++11' \
//tensorflow/lite/tools:benchmark_model \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=arm64-v8a \
--verbose_failures

2. Fixing the Protobuf Workspace Warning

That warning about the protobuf_archive's WORKSPACE file is a common gotcha with older TensorFlow versions. Here are your best solutions:

  • Upgrade TensorFlow: The easiest and most permanent fix is to switch to TensorFlow 2.3 or later. The team resolved this protobuf workspace naming conflict in those releases, so the warning will disappear automatically.
  • Suppress the warning temporarily: If you can't upgrade right now, add the --nowarn=workspace flag to your Bazel command. This tells Bazel to ignore workspace name-related warnings. Your full command becomes:
    bazel build -c opt --cxxopt='--std=c++11' \
    //tensorflow/lite/tools:benchmark_model \
    --crosstool_top=//external:android/crosstool \
    --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
    --cpu=arm64-v8a \
    --verbose_failures \
    --nowarn=workspace
    
  • Double-check your workspace setup: If you manually modified TensorFlow's WORKSPACE file, ensure there are no conflicting entries for protobuf. Custom changes can sometimes trigger this warning.

Once the build completes, you'll find the compiled benchmark_model binary in bazel-bin/tensorflow/lite/tools (or the contrib path if you're using an older version). Push it to your Android device with adb push and you're ready to benchmark your TensorFlow Lite models.

内容的提问来源于stack exchange,提问作者bin.li

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:12:38