weight_2初期化されていない値を使用しようとするが、私のコードです:TensorFlow:変数を計算するセッションを入力しますか? FailedPreconditionError:私は以下の変数Wの値を見つけるためにTensorFlowセッションを実行しようとしています
:W = tf.Variable(rng.randn(), name="weight")
init = tf.initialize_all_variables()
print(W.dtype)
print(W.initial_value)
print(W.value)
sess = tf.Session()
sess.run(W)
それから私は、次の出力に&エラーを得ました
<dtype: 'float32_ref'>
Tensor("weight_2/initial_value:0", shape=(), dtype=float32)
<bound method Variable.value of <tensorflow.python.ops.variables.Variable object at 0x7f031f36a470>>
---------------------------------------------------------------------------
FailedPreconditionError Traceback (most recent call last)
/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
971 try:
--> 972 return fn(*args)
973 except errors.OpError as e:
/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
953 feed_dict, fetch_list, target_list,
--> 954 status, run_metadata)
955
/usr/lib/python3.4/contextlib.py in __exit__(self, type, value, traceback)
65 try:
---> 66 next(self.gen)
67 except StopIteration:
/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/errors.py in raise_exception_on_not_ok_status()
462 compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 463 pywrap_tensorflow.TF_GetCode(status))
464 finally:
FailedPreconditionError: Attempting to use uninitialized value weight_2
[[Node: _send_weight_2_0 = _Send[T=DT_FLOAT, client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=-1169476299400319384, tensor_name="weight_2:0", _device="/job:localhost/replica:0/task:0/cpu:0"](weight_2)]]
During handling of the above exception, another exception occurred:
FailedPreconditionError Traceback (most recent call last)
<ipython-input-35-892407d423e3> in <module>()
7
8 sess = tf.Session()
----> 9 sess.run(W)
/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
715 try:
716 result = self._run(None, fetches, feed_dict, options_ptr,
--> 717 run_metadata_ptr)
718 if run_metadata:
719 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
913 if final_fetches or final_targets:
914 results = self._do_run(handle, final_targets, final_fetches,
--> 915 feed_dict_string, options, run_metadata)
916 else:
917 results = []
/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
963 if handle is None:
964 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
--> 965 target_list, options, run_metadata)
966 else:
967 return self._do_call(_prun_fn, self._session, handle, feed_dict,
/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
983 except KeyError:
984 pass
--> 985 raise type(e)(node_def, op, message)
986
987 def _extend_graph(self):
FailedPreconditionError: Attempting to use uninitialized value weight_2
[[Node: _send_weight_2_0 = _Send[T=DT_FLOAT, client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=-1169476299400319384, tensor_name="weight_2:0", _device="/job:localhost/replica:0/task:0/cpu:0"](weight_2)]]
私は、セッションを実行するにはWの式が必要だと推測していますが、何が必要なのか正確には分かっていません...セッションが値を計算できるように正確に何が提供される必要がありますか変数の?ありがとう!
感謝。しかし、なぜinitialize_all_variablesを呼び出さなくても、W.initial_valueがTensor( "weight_2/initial_value:0"、shape =()、dtype = float32)と表示されるのはなぜですか?ありがとう! – Edamame
'initial_value'が何であるかを説明するために私の答えを更新しました。 –