tensorflow各版本间踩过的坑

这篇博客列举了在不同TensorFlow版本间遇到的问题及其解决办法,包括TypeError、ValueError以及AttributeError等,涉及函数参数类型不匹配、API名称改变等问题,并提供了相应的修复建议。
部署运行你感兴趣的模型镜像

问题一:TypeError: Expected int32, got list containing Tensors of type ‘_Message’ instead.

tensorflow 函数tf.cocat([fw,bw],2)出错:

Expected int32, got list containing Tensors of type ‘_Message’ inst
查看原因是11版本的函数形式为:tf.concat(2,[fw,bw]),即应把串联的维度与串联值位置调换即可.

问题二:Input ‘split_dim’ of ‘Split’ Op has type float32 that does not match expected type of int32

This is because in Tensorflow versions < 0.12.0 the split function takes the arguments as:

x = tf.split(0, n_steps, x) # tf.split(axis, num_or_size_splits, value)
The tutorial you are working from was written for versions > 0.12.0, which has been changed to be consistent with Numpy’s split syntax:

x = tf.split(x, n_steps, 0) # tf.split(value, num_or_size_splits, axis)

问题三:TypeError: concat() got an unexpected keyword argument ‘axis’

tf.concat(concat_dim=axis, values=inputs, name=name)
修改为: tf.concat(inputs,1,name=name)

问题四:ValueError: ‘size’ must be a 1-D Tensor of 2 elements

img = tf.image.resize_images(img, new_shape[0], new_shape[1])
改为
img = tf.image.resize_images(img, new_shape)

问题五: ‘module’ object has no attribute ‘pack’

因为TF后面的版本修改了这个函数的名称,把 tf.pack 改为 tf.stack。

问题六:The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays

数据集是feed输入的,feed的数据格式是有要求的
解决:img,label = sess.run[img,label],用返回值

问题七:AttributeError: ‘module’ object has no attribute ‘per_image_whitening’

For anyone else who has this problem, per_image_whitening was replaced by per_image_standardization in v0.12.

问题八:AttributeError: ‘module’ object has no attribute ‘image_summary’

tf.image_summary should be renamed to tf.summary.image;

问题九:AttributeError: ‘module’ object has no attribute ‘mul’

tf.mul(a,b) 这里的矩阵a和矩阵b的shape必须相等 tf.mul()是矩阵的element-wise相乘(即Hadamard乘积)
tf.matmul(a,b) 这里的矩阵a和矩阵b的shape应是a的行数对等与b的列数,tf.matmul()是矩阵的一般相乘。
解决:[tf.mul,tf.sub ] 和 [tf.neg] 不再使用,改为 [tf.multiply],[tf.subtract] 和 [tf.negative]。

问题十:AttributeError: ‘module’ object has no attribute ‘scalar_summary’

修改为:tf.summary.scalar(‘batch_loss’, loss)原因:新版本做了调整 …

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9

TensorFlow-v2.9

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

<think>嗯,用户想在Windows 10上安装Anaconda,需要推荐合适的版本。这个问题很实际,因为选错版本可能导致兼容性问题。 首先考虑Windows 10的系统特性。它支持64位和32位系统,但现代电脑基本都是64位的了。Anaconda官方文档确实提到过2020年后停止支持32位安装包,所以64位是必然选择。 Python版本方面要更谨慎。虽然Python 3.11更新,但很多科学计算库对最新版支持可能有滞后。想到去年NumPy就出现过新版本不兼容的情况,所以推荐更稳定的Python 3.9比较稳妥。这个版本在生态兼容性和新特性之取得了很好的平衡。 安装包类型也有讲究。用户可能不知道Graphical Installer和Command Line Installer的区别,图形化安装显然对普通用户更友好。需要特别提醒用户验证SHA-256校验码,网络安全意识很重要。 突然想到用户没说电脑配置。如果用户是老机器,可能需要提醒8GB内存的要求,不过现在主流电脑应该都满足。另外要强调安装路径不要用中文,这个见过太多人了。 最后考虑衍生问题。用户问的是版本选择,但安装后可能遇到环境配置、镜像源设置等问题。特别是国内用户,不换源的话conda install可能会慢得离谱。这些都应该在相关问题里提一下,让用户有心理准备。 对了,还得确认Anaconda和Miniconda的区别。有些用户其实不需要全套科学计算工具,但这个问题里用户明确要Anaconda,就不展开说了。</think>以下是针对 Windows 10 的 Anaconda 版本选择建议: ### **安装推荐** 1. **最新稳定版**(优先选择) - 官网下载地址:[Anaconda Installers](https://www.anaconda.com/download) - **当前推荐版本**:`Anaconda3-2024.02-1`(Python 3.11.5) - 原因: - 完全兼容 Windows 10(64位系统) - 包含最新的科学计算库(NumPy, Pandas 等)和安全更新 - 官方持续维护支持 2. **经典兼容版**(如需特定 Python 版本) - 版本:`Anaconda3-2022.10`(Python 3.9) - 适用场景: - 需兼容旧项目(如 TensorFlow 1.x) - 企业环境要求固定版本 > 💡 **验证系统兼容性**: > ```bash > 系统要求 → Windows 10 (版本 1607 或更高) + 64位处理器 > 存储空 ≥ 5GB,内存 ≥ 8GB 为佳 > ``` ### **安装步骤** 1. **下载安装包**: - 选 `64-Bit Graphical Installer`(图形界面版) - 文件示例:`Anaconda3-2024.02-1-Windows-x86_64.exe` 2. **安装注意事项**: - ✅ 勾选 *"Add Anaconda to my PATH environment variable"*(方便命令行调用) - ✅ 选择 *"Register Anaconda3 as my default Python"* - ❌ 避免中文路径(如 `C:\ProgramData\Anaconda3`) 3. **验证安装**: ```bash conda --version # 应返回 conda 24.x.x python -c "import numpy; print(numpy.__version__)" # 输出版本号 ``` ### **常见问题规避** | 问题类型 | 解决方案 | |----------|----------| | 安装卡顿 | 关闭杀毒软件临时防护 | | 环境变量失效 | 手动添加:`C:\Users\<用户名>\anaconda3\Scripts` 到 PATH | | 创建环境失败 | 使用国内镜像源:`conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/` | ### **版本选择建议** $$\begin{array}{c|c} \text{需求场景} & \text{推荐版本} \\ \hline \text{机器学习/深度学习} & \text{最新版 (Python 3.11)} \\ \text{企业遗留系统兼容} & \text{Anaconda3-2020.11 (Python 3.8)} \\ \text{轻量化安装} & \text{Miniconda3 + 自选包} \\ \end{array}$$ > ⚠️ **重要提醒**: > 避免安装 Python 2.7 版本(已停止维护),2020年后官方不再提供32位安装包[^1]。 --- ### **相关问题** 1. Anaconda 和 Miniconda 的核心区别是什么?如何选择? 2. Windows 10 安装 Anaconda 后出现 *"conda is not recognized"* 错误如何解决? 3. 如何为 Anaconda 配置国内镜像加速包下载? 4. 在 Anaconda 中创建独立 Python 环境的最佳实践是什么? 5. 如何彻底卸载 Windows 10 上的 Anaconda 及其所有依赖项? [^1]: 根据 Anaconda 官方文档 *"Legacy Installers"* 说明,32位支持已于2020年终止。
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值