bidirectional_dynamic_rnnを使用しようとしていますが、ValueErrorがあります。tensorflow bidirectional_dynamic_rnnなし値エラー
私は試しましたbidirectional_rnnとすべてが問題ないようです。
valueErrorがなぜ発生するのか分かりません。私の機能bidirectional_dynamic_rnn入力パラメータinput_dataは空ではない= = ||
ありがとうございます。
ここに私のコードです。ここで
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
learning_rate = 0.001
training_epochs = 100
batch_size = 100
s = 28
n = 28
h = 128
C = 10
x = tf.placeholder(tf.float32, [None, s, n])
y = tf.placeholder(tf.float32, [None, C])
def fulconn_layer(input_data, output_dim, activation_func=None):
input_dim = int(input_data.get_shape()[1])
W = tf.Variable(tf.random_normal([input_dim, output_dim]))
b = tf.Variable(tf.random_normal([output_dim]))
if activation_func:
return activation_func(tf.matmul(input_data, W) + b)
else:
return tf.matmul(input_data, W) + b
lstm_fw_cell = tf.nn.rnn_cell.BasicLSTMCell(h, forget_bias=1.0, state_is_tuple=True)
lstm_bw_cell = tf.nn.rnn_cell.BasicLSTMCell(h, forget_bias=1.0, state_is_tuple=True)
outputs, states = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell, inputs=x, time_major=False, dtype=tf.float32)
rnn_layer1 = tf.unpack(tf.transpose(outputs, [1, 0, 2]))[-1]
yhat = fulconn_layer(rnn_layer1, C)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(yhat, y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
accuracy = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(y, 1), tf.argmax(yhat, 1)), tf.float32))
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
for epoch in range(training_epochs):
for i in range(int(mnist.train.num_examples/batch_size)):
x_batch, y_batch = mnist.train.next_batch(batch_size)
x_batch = x_batch.reshape([batch_size, s, n])
sess.run(optimizer, feed_dict={x: x_batch, y: y_batch})
train_accuracy = sess.run(accuracy, feed_dict={x: x_batch, y: y_batch})
x_test = mnist.test.images.reshape([-1, s, n])
y_test = mnist.test.labels
test_accuracy = sess.run(accuracy, feed_dict={x: x_test, y: y_test})
print("epoch: %d, train_accuracy: %3f, test_accuracy: %3f" % (epoch, train_accuracy, test_accuracy))
は誤りです:TensorFlowのバグは
PyDev console: using IPython 4.2.0
Running /root/PycharmProjects/mytf/myModel/whaoo.py
Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/op_def_library.py", line 454, in apply_op
as_ref=input_arg.is_ref)
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 628, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/constant_op.py", line 180, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/constant_op.py", line 163, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/tensor_util.py", line 346, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/pycharm/helpers/pydev/pydev_run_in_console.py", line 71, in <module>
globals = run_file(file, None, None)
File "/usr/local/pycharm/helpers/pydev/pydev_run_in_console.py", line 31, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/usr/local/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/root/PycharmProjects/mytf/myModel/whaoo.py", line 37, in <module>
outputs, states = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell, inputs=x, time_major=False, dtype=tf.float32)
File "/usr/lib/python3.4/site-packages/tensorflow/python/ops/rnn.py", line 674, in bidirectional_dynamic_rnn
seq_dim=time_dim, batch_dim=batch_dim)
File "/usr/lib/python3.4/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1904, in reverse_sequence
batch_dim=batch_dim, name=name)
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/op_def_library.py", line 458, in apply_op
as_ref=input_arg.is_ref).dtype.name
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 628, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/constant_op.py", line 180, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/constant_op.py", line 163, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
File "/usr/lib/python3.4/site-packages/tensorflow/python/framework/tensor_util.py", line 346, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.
あなたが説明していただけますか? 'last_output = outputs [:、0、:]' – Dietmar
バグを指摘してくれてありがとう、それは '-1'でなければなりません。また、TF 1.xで動作するようにコードを更新しました – melgor89