Python2.7でPythonプログラムを実行しています。私は、以下の手法を使って発電機の価値を印刷しようとしています。ジェネレータからの読み取り時の競合条件
y = m.predict(input_fn=lambda:input_fn(df_predict), as_iterable=True)
#output of this is a generator
print(type(y))
print(list(y))
次のエラーが表示されます。print ('Predictions: {}'.format(str(y)))
出力を実行する上で
Traceback (most recent call last):
File "tensorflow/examples/wide_n_deep_model_predictions_v3.0.py", line 176, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "tensorflow/examples/wide_n_deep_model_predictions_v3.0.py", line 171, in main
train_and_eval()
File "tensorflow/examples/wide_n_deep_model_predictions_v3.0.py", line 167, in train_and_eval
print (list(y))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py", line 328, in _as_iterable
for pred in preds:
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 909, in _infer_model_as_iterable
restore_checkpoint_path=checkpoint_path):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/graph_actions.py", line 867, in run_feeds_iter
yield session.run(output_dict, f)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 766, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 964, in _run
feed_dict_string, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1014, in _do_run
target_list, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1034, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: WhereOp: Race condition between counting the number of true elements and writing them. When counting, saw 2645 elements; but when writing their indices, saw 19 elements.
[[Node: linear/linear/ip/ip_weights/Where = Where[_device="/job:localhost/replica:0/task:0/cpu:0"](linear/linear/ip/ip_weights/GreaterEqual/_409)]]
Caused by op u'linear/linear/ip/ip_weights/Where', defined at:
File "tensorflow/examples/wide_n_deep_model_predictions_v3.0.py", line 176, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "tensorflow/examples/wide_n_deep_model_predictions_v3.0.py", line 171, in main
train_and_eval()
File "tensorflow/examples/wide_n_deep_model_predictions_v3.0.py", line 163, in train_and_eval
y = m.predict(input_fn=lambda:input_fn(df_predict), as_iterable=True)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 245, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py", line 747, in predict
as_iterable=as_iterable)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 191, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 477, in predict
as_iterable=as_iterable)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 847, in _infer_model
infer_ops = self._get_predict_ops(features)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 1113, in _get_predict_ops
return self._call_model_fn(features, labels, ModeKeys.INFER)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 1026, in _call_model_fn
params=self.params)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py", line 504, in _dnn_linear_combined_model_fn
scope=scope)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py", line 535, in weighted_sum_from_feature_columns
weight_collections)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py", line 332, in _create_embedding_lookup
name=column.name + '_weights')
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/embedding_ops.py", line 123, in safe_embedding_lookup_sparse
sparse_ids, sparse_weights = _prune_invalid_ids(sparse_ids, sparse_weights)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/embedding_ops.py", line 169, in _prune_invalid_ids
sparse_ids = sparse_ops.sparse_retain(sparse_ids, is_id_valid)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/sparse_ops.py", line 880, in sparse_retain
where_true = array_ops.reshape(array_ops.where(to_retain), [-1])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 2501, in where
return gen_array_ops.where(input=condition, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3821, in where
result = _op_def_lib.apply_op("Where", input=input, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2259, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1130, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): WhereOp: Race condition between counting the number of true elements and writing them. When counting, saw 2645 elements; but when writing their indices, saw 19 elements.
[[Node: linear/linear/ip/ip_weights/Where = Where[_device="/job:localhost/replica:0/task:0/cpu:0"](linear/linear/ip/ip_weights/GreaterEqual/_409)]]
はPredictions: <generator object _as_iterable at 0x7f1883235550>
ある誰かが、私は発電機を印刷することができますどのように私を導くことはできますか?
あなたは 'プリント(x)'は試してみましたか?あなたがpythonにいるかもしれないような音3 –
私はPython2.7でそれを実行しています。 print(x)の結果、プログラムが壊れてInvalidArgumentError(トレースバックについては上記を参照)が発生します。WhereOp:真の要素の数を数える間の競合条件。カウントするとき、2037個の要素を見た。しかし、彼らの指数を書くとき、19の要素を見た。 [[ノード:linear/linear/device/device_weights/Where =ここで[_device = "/ジョブ:ローカルホスト/レプリカ:0 /タスク:0/cpu:0"](線形/線形/デバイス/デバイス_重量/ GreaterEqual/_297 )]] ' – Vasanti
ジェネレータオブジェクトの価値はどういう意味ですか? –