iOS开发之机器学习框架MediaPipe(1)

 

MediaPipe是谷歌开源的机器学习框架,用于处理视频、音频等时间序列数据。
MediaPipe Solutions提供了16个Solutions: 人脸检测、Face Mesh(面部网格)、虹膜、手势、姿态、人体、人物分割、头发分割、目标检测、Box Tracking、Instant Motion Tracking、3D目标检测、特征匹配等。

本周刚开始学习MediaPipe框架,所以今天先记录一下部分准备工作和遇到的一下疑难杂症~

# 在Mac上安装Homebrew
/bin/bash -c "$(curl -fsSL \
https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
//国内用户可用一键安装脚本:
/bin/zsh -c"$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

# 安装Xcode及命令行工具
xcode-select --install

# 安装Bazelisk,
brew install bazelisk

# 克隆MediaPipe库文件
git clone https://github.com/google/mediapipe.git
cd mediapipe

# 安装OpenCV
brew install opencv@3

当你在执行 brew install opencv@3 时,你肯定会遇到类似下面的问题:

这是因为缺少对应的依赖库,上面就是缺少了 harfbuzz 库,所以下载好对应的库就可以解决,执行:brew install harfbuzz

之后再遇见一样的错误,还是执行:brew install (缺少的库),直到下载依赖库不再报错,或者执行完一次:1、brew install (缺少的库),无论结果如何,接着执行:2、brew install opencv@3,看opencv@3结果缺少哪个库,然后多次执行1、2两个终端命令,直到执行:brew install opencv@3 不再error,那么执行

brew info opencv@3 # 查看opencv的版本及信息

显示结果如图:

之后下载python3的six库,一定要注意,在终端上将python3设置为默认,下载完成后,查看安装结果

# 安装 six库
pip3 install --user six

# 查验安装结果
# cd 到 mediapipe 所在的目录,执行下面操作

export GLOG_logtostderr=1
// 需要bazel设置环境变量'MEDIAPIPE_DISABLE_GPU=1',因为桌面GPU当前不受支持
bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
    mediapipe/examples/desktop/hello_world:hello_world

此时如果你很顺利的输出了以下结果,那么恭喜你,最初的配置已经成功。

但是很不幸的是,我遇到了下面的大坑,

问题很明显是缺少了numpy库

ERROR: Analysis of target '//mediapipe/examples/desktop/hello_world:hello_world' failed; build aborted: Problem getting numpy include path.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Is numpy installed?

于是我就使用各种终端命令安装numpy,命令显示已经安装上了,然后再执行hello_world语句,依然是相同的报错,然后 import numpy 导入库,发现竟然没有,最后使用下面命令安装:

python3 -m pip install numpy

报错如下:

查看了各种英文,各种尝试都不管用,最后终于在github上理解了原因是什么:Failed pip install for numpy in python 3.9 on macOS using conda,这是一个python的bug!!!在这个版本上安装会失败!!!Failed pip install for numpy in python 3.9 on macOS using conda · Issue #17569 · numpy/numpy · GitHub

于是我更新了python3.10.5的版本:https://www.python.org/ftp/python/3.10.5/python-3.10.5-macos11.pkg

然后再次执行

python3 -m pip install numpy

成功效果如下:

最后再次执行操作语句:

export GLOG_logtostderr=1
// 需要bazel设置环境变量'MEDIAPIPE_DISABLE_GPU=1',因为桌面GPU当前不受支持
bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
    mediapipe/examples/desktop/hello_world:hello_world

终于让我看到了世界语言:

INFO: Analyzed target //mediapipe/examples/desktop/hello_world:hello_world (81 packages loaded, 1836 targets configured).
INFO: Found 1 target...
Target //mediapipe/examples/desktop/hello_world:hello_world up-to-date:
  bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 575.843s, Critical Path: 487.45s
INFO: 776 processes: 156 internal, 620 darwin-sandbox.
INFO: Build completed successfully, 776 total actions
INFO: Build completed successfully, 776 total actions
I20221013 17:40:34.163226 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165056 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165071 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165081 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165088 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165097 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165105 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165114 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165122 179693056 hello_world.cc:57] Hello World!
I20221013 17:40:34.165131 179693056 hello_world.cc:57] Hello World!

真是遇到了一个大坑啊,第一步大坑已经迈过去了,距离胜利越来越近了,未完待续~~

整理不易,转载请注明,谢谢

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hbblzjy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值