错误一

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长度为1
X[1,1:] = 0
X_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，运行成功。

1）两者类型需要保持一致
2）只支持float类型，float32、float64都可以

错误二

ValueError: setting an array element with a sequence.

from sklearn.decomposition import PCA
import numpy as np

x = 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)

错误三

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)

  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

错误五

# coding:UTF-8

# -*- coding:UTF-8 -*-

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120