树莓派:安装Tensorflow Lite

        因为要在树莓派上部署模型,所以要用到Tesnorflow,对于树莓派来说,官方推荐下载解释器tflite-runtime。 需要使用虚拟环境下载安装,因为树莓派系统里不许使用pip(害怕和apt起冲突),用了就会报错:

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
 
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
 
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
 
See /usr/share/doc/python3.11/README.venv for more information.
 
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

 一、在python3.7虚拟环境下载 .whl并安装

        这个方法失败了,查看自己匹配的版本,我使用python3.7,再使用pip debug --verbose命令即可查看自己的树莓派的平台。

        

        下载并安装(虚拟环境下),然后报错:缺失ssl模块。

python3.7 -m vnev tflite
source tflite/bin/activate
wget https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_aarch64.whl
sudo pip install tflite_runtime-2.1.0.post1-cp37-cp37m-linux_aarch64.whl

二、在python3.11虚拟环境下载tflite-runtime

        这个方法也失败了在python3.11创建虚拟环境里下载解释器,下载速度慢( 树莓派 pip 使用 piwheels.org 作为附加索引,服务器在英国,有方法可以设置取消此索引),下载完成后报错:软件包不适合此架构。

        树莓派4B是arm64位的架构,我安装的32位树莓派系统,装的32位python,理论上应该兼容的,触及到我知识盲区了hhhh。

python -m venv tflite
source tflite/bin/activate
pip install tflite-runtime

三、用virtualenv虚拟环境下载tflite-runtime

        重新给树莓派烧录了64位的操作系统,在网上看到的下载方法,用virtualenv。

        下载virtualenv,创建虚拟环境并激活,加入--system-site-packages选项,这会允许虚拟环境访问系统Python环境中已安装的包和库(这句话是偷的),然后就可以使用pip3安装了。

sudo apt-get install virtualenv
virtualenv 51env --system-site-packages
source 51env/bin/activate
pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime

方法三参考(搬运于):在最新raspberry pi 64-bit os上安装tflite-runtime_see pep 668 for the detailed specification.-CSDN博客

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要在树莓安装TensorFlow Lite,您需要按照以下步骤进行操作: 1. 首先,您需要在树莓安装Python和pip。如果您还没有安装它们,可以使用以下命令进行安装: sudo apt-get update sudo apt-get install python3-dev python3-pip 2. 接下来,您需要安装TensorFlow Lite的Python包。可以使用以下命令进行安装: pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1..post1-cp37-cp37m-linux_armv7l.whl 3. 安装完成后,您可以使用以下命令测试TensorFlow Lite是否正常工作: python3 -c "import tflite_runtime.interpreter as tflite" 如果没有出现任何错误,则说明TensorFlow Lite已经成功安装并可以正常工作。 希望这些步骤能够帮助您在树莓安装TensorFlow Lite。 ### 回答2: 树莓是一种小型计算机,广泛用于物联网、教育和娱乐等领域。TensorFlow Lite是Google开发的一种轻量级的机器学习框架,专门用于在移动设备和嵌入式设备上部署机器学习模型。在树莓安装TensorFlow Lite可以使其更加智能化,可以用于各种应用场景,如图像识别、自然语言处理等。 以下是在树莓安装TensorFlow Lite的步骤: 第一步:更新系统 在安装TensorFlow Lite之前,需要保证树莓系统为最新版本。可以通过以下命令更新系统: sudo apt-get update sudo apt-get upgrade 第二步:安装Python TensorFlow Lite是基于Python语言开发的,因此需要在树莓安装Python。可以通过以下命令安装Python: sudo apt-get install python3-dev python3-pip 第三步:安装TensorFlow Lite安装TensorFlow Lite之前,需要先安装TensorFlow框架。可以通过以下命令安装: pip3 install tensorflow==2.3.0 注意,TensorFlow 2.3.0是适用于树莓运行的最新版本。如果使用其他版本,可能会遇到不兼容的问题。 安装完成TensorFlow之后,可以通过以下命令安装TensorFlow Lite: pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_armv7l.whl 第四步:测试TensorFlow Lite 安装完成后,可以用以下代码测试 TensorFlow Lite 是否正常工作: import tflite_runtime.interpreter as tflite interpreter = tflite.Interpreter(model_path="model.tflite") interpreter.allocate_tensors() input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() input_shape = input_details[0]['shape'] input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32) interpreter.set_tensor(input_details[0]['index'], input_data) interpreter.invoke() output_data = interpreter.get_tensor(output_details[0]['index']) print(output_data) model.tflite是你要测试的模型的文件名。如果TensorFlow Lite正常工作,将输出模型的预测结果。 总结: 通过以上步骤,在树莓安装 Tensorflow Lite 非常简单。需要注意的是,TensorFlow Lite 不像TensorFlow那样跟大多数操作系统集成,需要从Google的官方网站上下载并安装。但还是很方便快捷的,只要按照上述步骤操作,你就可以在树莓上使用TensorFlow Lite,部署机器学习模型并让树莓变得更加智能。 ### 回答3: 树莓是一个非常强大的小型计算机,既能够实现控制硬件,也可以搭载各种软件来实现复杂的功能。在树莓安装TensorFlow Lite可以帮助我们实现各种深度学习任务,如目标检测、语音识别、机器翻译和图像分类等。 首先,我们需要设置树莓。我们需要一张32GB以上的SD卡和一个读卡器,并下载树莓的操作系统。可以通过官方网站下载最新版本的树莓操作系统,并将其烧录到SD卡中。 一旦树莓系统已经设置好,我们需要对其进行基础设置和连接外部硬件(键盘、鼠标和显示器)。接着,我们需要打开终端并更新操作系统: sudo apt-get update sudo apt-get upgrade 接着,我们需要安装Python3以及pip3: sudo apt-get install python3-dev python3-pip 接下来,我们需要安装TensorFlow Lite安装TensorFlow Lite最简单的方法是使用pip: sudo pip3 install tflite-runtime 然后,我们可以测试是否成功安装TensorFlow Lite: # Python3 程序 import tflite_runtime.interpreter as tflite interpreter = tflite.Interpreter(model_path="model.tflite") interpreter.allocate_tensors() input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() input_shape = input_details[0]['shape'] print(input_shape) 以上代码将会测试是否已经成功安装TensorFlow Lite,并打印tflite模型中的输入形状。 总之,在树莓安装TensorFlow Lite可以帮助我们实现多种深度学习任务。通过上述步骤,您可以在树莓安装TensorFlow Lite。更多详细的教程及示例,请访问TensorFlow官网。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值