TensorFlowエラーの解決策(継続的な更新)
4326 ワード
エラー1
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.
Y = tf.placeholder(tf.int 32,[2,2,1])行のタイプはtf.nn.dynamic_rnnのタイプは統一され、int 32をfloat 64に変更し、実行に成功した.また、tf.nn.dynamic_rnn関数はfloatタイプのみを許容するようで,2つのタイプをint 32に統一し,依然としてこの誤りを報告している(I don’t know why now).
まとめ:
1)両者のタイプは一貫性を保つ必要がある2)floatタイプのみをサポートし、float 32、float 64ともに
エラー2
ValueError: setting an array element with a sequence.
一般的にこのエラーはarrayにおける配列長が統一されていないことであり,例えば最初の配列[1.]次元エラー.他の配列次元と一致しません.
エラー3
error destroying CUDA event in context 000001EAA2598510: CUDA_ERROR_LAUNCH_FAILED
コードはこの位置でエラーを報告し、cpuの下で実行するように設定すれば解決します.
エラー4
ValueError: Shape (?, 1) must have rank at least 3
エラー行を報告するtensorは3次元のパラメータを入力する必要があるがshape(?,1)は2次元である.正しいデータフォーマットに変更すればいいです.
エラー5
Pythonスクリプトを作成すると、中国語のコメントまたは出力でエラーが表示されます:SyntaxError:Non-ASCII character'xe 5'in file
Pythonソースファイルの開始行に次の値を追加します.
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.int 32,[2,2,1])行のタイプはtf.nn.dynamic_rnnのタイプは統一され、int 32をfloat 64に変更し、実行に成功した.また、tf.nn.dynamic_rnn関数はfloatタイプのみを許容するようで,2つのタイプをint 32に統一し,依然としてこの誤りを報告している(I don’t know why now).
まとめ:
1)両者のタイプは一貫性を保つ必要がある2)floatタイプのみをサポートし、float 32、float 64ともに
エラー2
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)
一般的にこのエラーはarrayにおける配列長が統一されていないことであり,例えば最初の配列[1.]次元エラー.他の配列次元と一致しません.
エラー3
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)
エラー4
ValueError: Shape (?, 1) must have rank at least 3
エラー行を報告するtensorは3次元のパラメータを入力する必要があるがshape(?,1)は2次元である.正しいデータフォーマットに変更すればいいです.
エラー5
Pythonスクリプトを作成すると、中国語のコメントまたは出力でエラーが表示されます:SyntaxError:Non-ASCII character'xe 5'in file
Pythonソースファイルの開始行に次の値を追加します.
# coding:UTF-8
# -*- coding:UTF-8 -*-