TensorFlow报错的解决方案(持续更新)
来源:互联网 发布:淘宝儿童折叠床 编辑:程序博客网 时间:2024/06/05 06:28
错误一
ValueError: Initializer for variable rnn/basic_rnn_cell/kernel/ is from inside a control-flow construct, such as a loop or conditional. When creating a variable inside a loop or conditional, use a lambda as the initializer.
X = np.random.randn(2, 2, 1)# 第二个example长度为1X[1,1:] = 0X_lengths = [2, 1]cell = tf.nn.rnn_cell.BasicRNNCell(num_units=64)Y = tf.placeholder(tf.int32, [2,2,1])outputs, last_states = tf.nn.dynamic_rnn(cell=cell, dtype=tf.float64, sequence_length=X_lengths, inputs=Y)output = tf.reshape(outputs, [-1, 2])result = tf.contrib.learn.run_n({"outputs": outputs, "last_states": last_states}, n=1, feed_dict={Y:X})print(result[0])
Y = tf.placeholder(tf.int32, [2,2,1])行的类型需要跟tf.nn.dynamic_rnn中的类型统一,将int32改成float64,运行成功。
此外,tf.nn.dynamic_rnn函数似乎只允许float类型,将两个类型统一成int32,仍然报这个错(I don’t know why now)。
总结:
1)两者类型需要保持一致
2)只支持float类型,float32、float64都可以
错误二
ValueError: setting an array element with a sequence.
from sklearn.decomposition import PCAimport numpy as npx = np.array([[1.], [0.9, 0.95], [1.01, 1.03], [2., 2.], [2.03, 2.06], [1.98, 1.89], [3., 3.], [3.03, 3.05], [2.89, 3.1], [4., 4.], [4.06, 4.02], [3.97, 4.01]])pca=PCA(n_components=1, copy=False)print(pca.fit_transform(x))print(x)
一般这种错误是array中数组长度不统一,如第一个数组[1.]维度出错,与其它数组维度不一致。
错误三
error destroying CUDA event in context 000001EAA2598510: CUDA_ERROR_LAUNCH_FAILED
labels = tf.one_hot(tf.reshape(output_data, [-1]), depth=vocab_size + 1) loss = tf.nn.softmax_cross_entropy_with_logits(labels=labels, logits=logits)
代码在这个位置报错,设置它们在cpu下执行即可解决。
with tf.device('/cpu:0'): labels = tf.one_hot(tf.reshape(output_data, [-1]), depth=vocab_size + 1) loss = tf.nn.softmax_cross_entropy_with_logits(labels=labels, logits=logits)
错误四
ValueError: Shape (?, 1) must have rank at least 3
报错行的tensor要求输入3维的参数,但是shape(?,1)是两维的。改成正确的数据格式即可。
- TensorFlow报错的解决方案(持续更新)
- Python报错的解决方案(持续更新)
- android各种报错疑难杂症解决方案(持续更新)
- 项目报错解决方案(持续更新) by-昊哥
- Tensorflow-报错解决方案
- 【Tensorflow】报错解决方案
- 编程时遇到的报错总结(持续更新)
- xcode报错总结(持续更新)
- mysql报错总结(持续更新)
- hibernate报错总结(持续更新)
- Angluar2报错记录(持续更新...)
- 启动报错(持续更新)
- tensorflow某些函数的小坑(持续更新)
- tensorflow image api (持续更新)
- Tensorflow 常用方法总结(持续更新)
- TensorFlow学习问题总结(持续更新)
- Tomcat启动报错的解决方法[持续更新]
- sqlserver经常遇到的异常报错 持续更新整理
- jQuery知识点(4)-.html() .text() .val() .attr()获取元素内容、值、属性
- 11 个简单的 Java 性能调优技巧
- NandFlash的时序分析
- Redis入门,安装
- notify & notify all
- TensorFlow报错的解决方案(持续更新)
- 冒泡排序及其改进算法
- java反射回顾<一>
- java网络编程之传统IO与伪异步IO(一)
- 方向感知鼠标悬停效果动画
- Azure 中虚拟机的计划内维护
- Spring入门到应用
- Java POI 写入Excel
- 面试题积累