MediaPipe框架- GPU支持

GPU Support

GPU支持

OpenGL ES Support

OpenGL ES支持

MediaPipe supports OpenGL ES up to version 3.2 on Android/Linux and up to ES 3.0 on iOS. In addition, MediaPipe also supports Metal on iOS.

MediaPipe在Android/Linux上支持OpenGL ES 3.2版本,在iOS上支持ES 3.0版本。此外,MediaPipe还在iOS上支持Metal。

OpenGL ES 3.1 or greater is required (on Android/Linux systems) for running machine learning inference calculators and graphs.

运行机器学习推理计算器和图需要OpenGL ES 3.1或更高版本(在Android/Linux系统上)。

Disable OpenGL ES Support

禁用OpenGL ES支持

By default, building MediaPipe (with no special bazel flags) attempts to compile and link against OpenGL ES (and for iOS also Metal) libraries.

默认情况下,构建MediaPipe(没有特殊的bazel标志)会尝试针对OpenGL ES(以及iOS和Metal)库进行编译和链接。

On platforms where OpenGL ES is not available (see also OpenGL ES Setup on Linux Desktop), you should disable OpenGL ES support with:

​在OpenGL ES不可用的平台上(另请参阅Linux Desktop上的OpenGL ES设置),应使用以下选项禁用OpenGL ES支持:

$ bazel build --define MEDIAPIPE_DISABLE_GPU=1 <my-target>

Note: On Android and iOS, OpenGL ES is required by MediaPipe framework and the support should never be disabled.

注意:在Android和iOS上,OpenGL ES是MediaPipe框架所必需的,并且不应禁用其支持。

OpenGL ES Setup on Linux Desktop

OpenGL ES在Linux桌面上的安装

On Linux desktop with video cards that support OpenGL ES 3.1+, MediaPipe can run GPU compute and rendering and perform TFLite inference on GPU.

在支持OpenGL ES 3.1+视频卡的Linux桌面上,MediaPipe可以运行GPU计算和渲染,并在GPU上执行TFLite推理。

To check if your Linux desktop GPU can run MediaPipe with OpenGL ES:

要检查Linux桌面GPU是否可以使用OpenGL ES运行MediaPipe,请执行以下操作:

$ sudo apt-get install mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev
$ sudo apt-get install mesa-utils
$ glxinfo | grep -i opengl

For example, it may print:

例如,它可以打印:

$ glxinfo | grep -i opengl
...
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 430.50
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

If you have connected to your computer through SSH and find when you probe for GPU information you see the output:

如果您已通过SSH连接到计算机,并在探测GPU信息时发现输出:

glxinfo | grep -i opengl
Error: unable to open display

Try re-establishing your SSH connection with the -X option and try again. For example:

请尝试使用-X选项重新建立SSH连接,然后重试。例如

ssh -X <user>@<host>

Notice the ES 3.20 text above.

请注意上面的ES 3.20文本。

You need to see ES 3.1 or greater printed in order to perform TFLite inference on GPU in MediaPipe. With this setup, build with:

为了在MediaPipe中的GPU上执行TFLite推理,您需要看到打印的ES 3.1或更高版本。使用此设置,使用以下内容构建:

$ bazel build --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 <my-target>

If only ES 3.0 or below is supported, you can still build MediaPipe targets that don't require TFLite inference on GPU with:

如果仅支持ES 3.0或更低版本,仍然可以使用以下功能在GPU上构建不需要TFLite推理的MediaPipe目标:

$ bazel build --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 --copt -DMEDIAPIPE_DISABLE_GL_COMPUTE <my-target>

Note: MEDIAPIPE_DISABLE_GL_COMPUTE is already defined automatically on all Apple systems (Apple doesn't support OpenGL ES 3.1+).

注意:MEDIAPIPE_DISABLE_GL_COMPUTE已经在所有苹果系统上自动定义(苹果不支持OpenGL ES 3.1+)。

TensorFlow CUDA Support and Setup on Linux Desktop

TensorFlow CUDA在Linux桌面上的支持和设置

MediaPipe framework doesn't require CUDA for GPU compute and rendering. However, MediaPipe can work with TensorFlow to perform GPU inference on video cards that support CUDA.

MediaPipe框架不需要CUDA进行GPU计算和渲染。但是,MediaPipe可以与TensorFlow一起在支持CUDA的视频卡上执行GPU推理。

To enable TensorFlow GPU inference with MediaPipe, the first step is to follow the TensorFlow GPU documentation to install the required NVIDIA software on your Linux desktop.

​要使用MediaPipe启用TensorFlow GPU推理,第一步是按照TensorFlow的GPU文档在Linux桌面上安装所需的NVIDIA软件。

After installation, update $PATH and $LD_LIBRARY_PATH and run ldconfig with:

安装后,更新$PATH和$LD_LIBRARY_PATH,并使用以下命令运行ldconfig:

$ export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
$ export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64,/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
$ sudo ldconfig

It's recommended to verify the installation of CUPTI, CUDA, CuDNN, and NVCC:

建议验证CUPTI、CUDA、CuDNN和NVCC的安装情况:

$ ls /usr/local/cuda/extras/CUPTI
/lib64
libcupti.so       libcupti.so.10.1.208  libnvperf_host.so        libnvperf_target.so
libcupti.so.10.1  libcupti_static.a     libnvperf_host_static.a

$ ls /usr/local/cuda-10.1
LICENSE  bin  extras   lib64      libnvvp           nvml  samples  src      tools
README   doc  include  libnsight  nsightee_plugins  nvvm  share    targets  version.txt

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

$ ls /usr/lib/x86_64-linux-gnu/ | grep libcudnn.so
libcudnn.so
libcudnn.so.7
libcudnn.so.7.6.4

Setting $TF_CUDA_PATHS is the way to declare where the CUDA library is. Note that the following code snippet also adds /usr/lib/x86_64-linux-gnu and /usr/include into $TF_CUDA_PATHS for cudablas and libcudnn.

设置$TF_CUDA_PATHS是声明CUDA库所在位置的方法。请注意,以下代码片段还将/usr/lib/x86_64-linux-gnu和/usr/include添加到用于cudabas和libcudnn的$TF_CUDA_PATHS中。

$ export TF_CUDA_PATHS=/usr/local/cuda-10.1,/usr/lib/x86_64-linux-gnu,/usr/include

To make MediaPipe get TensorFlow's CUDA settings, find TensorFlow's .bazelrc and copy the build:using_cuda and build:cuda section into MediaPipe's .bazelrc file. For example, as of April 23, 2020, TensorFlow's CUDA setting is the following:

​要使MediaPipe获得TensorFlow的CUDA设置,请找到TensorFlow中的.bazelrc,并将build:using_cudabuild:cuda部分复制到MediaPipe的.bazellc文件中。例如,截至2020年4月23日,TensorFlow的CUDA设置如下:

# This config refers to building with CUDA available. It does not necessarily
# mean that we build CUDA op kernels.
build:using_cuda --define=using_cuda=true
build:using_cuda --action_env TF_NEED_CUDA=1
build:using_cuda --crosstool_top=@local_config_cuda//crosstool:toolchain

# This config refers to building CUDA op kernels with nvcc.
build:cuda --config=using_cuda
build:cuda --define=using_cuda_nvcc=true

Finally, build MediaPipe with TensorFlow GPU with two more flags --config=cuda and --spawn_strategy=local. For example:

最后,使用TensorFlow GPU再使用两个标志构建MediaPipe --config=cuda和--spawn_strategy=local。例如

$ bazel build -c opt --config=cuda --spawn_strategy=local \
    --define no_aws_support=true --copt -DMESA_EGL_NO_X11_HEADERS \
    mediapipe/examples/desktop/object_detection:object_detection_tensorflow

While the binary is running, it prints out the GPU device info:

当二进制文件运行时,它会打印出GPU设备信息:

I external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
I external/org_tensorflow/tensorflow/core/common_runtime/gpu/gpu_device.cc:1544] Found device 0 with properties: pciBusID: 0000:00:04.0 name: Tesla T4 computeCapability: 7.5 coreClock: 1.59GHz coreCount: 40 deviceMemorySize: 14.75GiB deviceMemoryBandwidth: 298.08GiB/s
I external/org_tensorflow/tensorflow/core/common_runtime/gpu/gpu_device.cc:1686] Adding visible gpu devices: 0

You can monitor the GPU usage to verify whether the GPU is used for model inference.

可以监视GPU的使用情况,以验证GPU是否用于模型推理。

$ nvidia-smi --query-gpu=utilization.gpu --format=csv --loop=1

0 %
0 %
4 %
5 %
83 %
21 %
22 %
27 %
29 %
100 %
0 %
0%
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值