TensorFlowを使用して回帰モデルを実装していましたが、すべての変数に対して常にNan値を取得し続けます。以下はNanへのコードです。TensorFlowのNaN
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import xlrd
data_file = "data/fire_theft.xls"
book = xlrd.open_workbook(data_file, encoding_override="utf-8")
sheet = book.sheet_by_index(0)
data = np.asarray([sheet.row_values(i) for i in range(1, sheet.nrows)])
n_samples = sheet.nrows - 1
X = tf.placeholder(tf.float32, name="X")
Y = tf.placeholder(tf.float32, name="Y")
w = tf.Variable(0.0, name="weight_1")
u = tf.Variable(0.0, name="weight_2")
b = tf.Variable(0.0, name="bias")
Y_Predicted = tf.pow(X, 2.0) * w + X * u + b
loss = tf.square(Y - Y_Predicted, name="loss")
optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.0001).minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(10):
for x,y in data:
sess.run(optimizer, feed_dict={X: x, Y: y})
print(w.eval())
私は、次のコマンドを実行すると:私はここに非常に些細な何かが欠けています
Traceback (most recent call last):
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site- packages/tensorflow/python/client/session.py", line 1327, in _do_call
return fn(*args)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1306, in _run_fn
status, run_metadata)
File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__
next(self.gen)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'X' with dtype float
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/utkarsh/PycharmProjects/DiveIntoPython3/notes/quadratic_regression.py", line 32, in <module>
print(loss.eval())
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 541, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 4085, in _eval_using_default_session
return session.run(tensors, feed_dict)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 895, in run
run_metadata_ptr)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1124, in _run
feed_dict_tensor, options, run_metadata)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
options, run_metadata)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'X' with dtype float
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'X', defined at:
File "/home/utkarsh/PycharmProjects/DiveIntoPython3/notes/quadratic_regression.py", line 13, in <module>
X = tf.placeholder(tf.float32, name="X")
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1548, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2094, in _placeholder
name=name)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/utkarsh/Documents/environments/tensorFlow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1204, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'X' with dtype float
[[Node: X = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
:
print(loss.eval())
をプログラムは、以下に示す例外をスローします。調べるためには、別の目のペアが必要です。おかげさまで
回答がありましたか? –