Tensorflow 兼容性测试-opencloudos

介绍

Tensorflow 兼容性测试: 测试 Tensorflow 各个版本在 OpenCloudOS Stream 的安装支持

操作系统

[root@lab101 ~]# cat /etc/os-release
NAME="OpenCloudOS Stream"
VERSION="23"
ID="opencloudos"
ID_LIKE="opencloudos"
VERSION_ID="23"
PLATFORM_ID="platform:ocs23"
PRETTY_NAME="OpenCloudOS Stream 23"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:opencloudos:opencloudos:23"
HOME_URL="https://www.opencloudos.org/"
BUG_REPORT_URL="https://bugs.opencloudos.tech/"
[root@lab101 ~]# uname -a
Linux lab101 6.6.6-2401.0.1.1.ocs23.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 18 09:42:48 CST 2024 x86_64 GNU/Linux

版本要求

当前的主要版本是TensorFlow 2

旧版 TensorFlow 1.x,CPU 和 GPU 软件包是分开的:

tensorflow==1.15:仅支持 CPU 的版本
tensorflow-gpu==1.15:支持 GPU 的版本(适用于 Ubuntu 和 Windows)

1.15是TensorFlow 1.x 的最终版本

安装测试

安装旧版本1.x

源里面已经没提供1.15版本

[root@lab101 ~]# pip3 install --user tensorflow==1.15
ERROR: Could not find a version that satisfies the requirement tensorflow==1.15 (from versions: 2.12.0rc0, 2.12.0rc1, 2.12.0, 2.12.1, 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.15.0.post1, 2.15.1, 2.16.0rc0, 2.16.1, 2.16.2, 2.17.0rc0, 2.17.0rc1, 2.17.0)
ERROR: No matching distribution found for tensorflow==1.15

Tensorflow 1.15 需要运行

python <=3.7 to install Tensorflow 1.15

opencloudos上面的python版本为3.11,所以不支持这个版本

安装当前主线版本

安装最新版本的方法

pip3 install --user tensorflow -i https://mirrors.aliyun.com/pypi/simple/

当前的2.x版本有下面的版本,最新的版本为2.17.0

2.12.0 2.12.1 2.13.0 2.13.1 2.14.0 2.14.1 2.15.0 2.15.1 2.16.1 2.16.2 2.17.0

为了测试全部版本的兼容性,我们使用脚本进行遍历

#! /bin/bash

for version in `echo 2.12.0 2.12.1 2.13.0 2.13.1 2.14.0 2.14.1 2.15.0 2.15.1 2.16.1 2.16.2 2.17.0`
do
echo "正在测试$version版本"
echo "安装tensorflow==$version"
pip3 install --user tensorflow==$version   -i https://mirrors.aliyun.com/pypi/simple/
echo "测试tensorflow==$version"
python3 -c "import tensorflow as tf;print(tf.__version__);print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
echo "卸载tensorflow==$version"
done

检查输出的结果

[root@lab101 ~]# cat test.log |grep 测试ten -A 2
测试tensorflow==2.12.0
2.12.0
tf.Tensor(724.3179, shape=(), dtype=float32)
--
测试tensorflow==2.12.1
2.12.1
tf.Tensor(344.487, shape=(), dtype=float32)
--
测试tensorflow==2.13.0
2.13.0
tf.Tensor(-43.525192, shape=(), dtype=float32)
--
测试tensorflow==2.13.1
2.13.1
tf.Tensor(840.32227, shape=(), dtype=float32)
--
测试tensorflow==2.14.0
2.14.0
tf.Tensor(-1793.5032, shape=(), dtype=float32)
--
测试tensorflow==2.14.1
2.14.1
tf.Tensor(-1610.8185, shape=(), dtype=float32)
--
测试tensorflow==2.15.0
2.15.0
tf.Tensor(-455.57336, shape=(), dtype=float32)
--
测试tensorflow==2.15.1
2.15.1
tf.Tensor(847.0481, shape=(), dtype=float32)
--
测试tensorflow==2.16.1
2.16.1
tf.Tensor(-1371.9381, shape=(), dtype=float32)
--
测试tensorflow==2.16.2
2.16.2
tf.Tensor(1536.6016, shape=(), dtype=float32)
--
测试tensorflow==2.17.0
2.17.0
tf.Tensor(-1663.6276, shape=(), dtype=float32)

可以看到,全部都可以运行输出,测试验证安装的方法为官网给出的方法

补充

如果自己编译安装python3.7,看是否能支持tensorflow的1.15版本

[root@lab101 python-3.7.7]# python3.7  /usr/local/bin/pip3.7  install --user tensorflow==1.15  -i https://mirrors.aliyun.com/pypi/simple/

运行报错

    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

处理

python3.7  /usr/local/bin/pip3.7  install --user  protobuf==3.20.*  -i https://mirrors.aliyun.com/pypi/simple/

运行

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
[root@lab101 python-3.7.7]# python3.7 -c "import tensorflow as tf;print(tf.__version__);print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
1.15.0
Tensor("Sum:0", shape=(), dtype=float32)

没报错了,但是结果感觉不对,应该还是版本兼容性问题,建议使用2.x版本

兼容性列表

tensorflow版本是否兼容备注
1.15不支持要求python3<=python3.7(os python 3.11)
2.12.0支持
2.12.1支持
2.13.0支持
2.13.1支持
2.14.0支持
2.14.1支持
2.15.0支持
2.15.1支持
2.16.1支持
2.16.2支持
2.17.0支持
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

武汉磨磨

打赏是写出更好教程的鼓励

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

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

打赏作者

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

抵扣说明:

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

余额充值