-
Notifications
You must be signed in to change notification settings - Fork 74.8k
Description
On TF 0.9.0, The following code with tf.while_loop inside tf.cond raises ValueError when minimized.
import tensorflow as tf
from tensorflow.python.ops import tensor_array_ops
with tf.Session() as sess:
a = tf.constant([[1., 2.], [3.,4.]])
w = tf.get_variable('w', [2, 1], tf.float32)
c = tf.Variable(1)
def loss_a(a, w):
a_ta = tensor_array_ops.TensorArray(dtype=tf.float32, size=2,
tensor_array_name="a_ta")
a_ta = a_ta.unpack(a)
b_ta = tensor_array_ops.TensorArray(dtype=tf.float32, size=2,
tensor_array_name="b_ta")
time = tf.constant(0, dtype=tf.int32, name="time")
def _time_step(time, a_ta_t, b_ta_t):
a = a_ta_t.read(time)
b_ta_t = b_ta_t.write(time, a * w)
return (time+1, a_ta_t, b_ta_t)
(_, _, final_b) = tf.while_loop(
cond=lambda time, _1, _2: time < 2,
body=_time_step,
loop_vars=(time, a_ta, b_ta),
parallel_iterations=32,
swap_memory=True)
b = tf.reduce_sum(final_b.pack(), 0)
return b
def loss_b(a, w):
return 2 * a * w
loss = tf.cond(tf.equal(c, 0), lambda: loss_a(a, w), lambda: loss_b(a,w))
train_op = tf.train.AdamOptimizer(1e-4).minimize(loss)
sess.run(tf.initialize_all_variables())
sess.run(train_op)
Traceback (most recent call last):
File "test.py", line 39, in
train_op = tf.train.AdamOptimizer(1e-4).minimize(loss)
File "/.../tensorflow/python/training/optimizer.py", line 193, in minimize
grad_loss=grad_loss)
File "/.../tensorflow/python/training/optimizer.py", line 250, in compute_gradients
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/.../tensorflow/python/ops/gradients.py", line 481, in gradients
in_grads = _AsList(grad_fn(op, *out_grads))
File "/.../tensorflow/python/ops/tensor_array_grad.py", line 115, in _TensorArrayWriteGrad
grad = g.read(index)
File "/.../tensorflow/python/ops/tensor_array_ops.py", line 191, in read
dtype=self._dtype, name=name)
File "/.../tensorflow/python/ops/gen_data_flow_ops.py", line 905, in _tensor_array_read
flow_in=flow_in, dtype=dtype, name=name)
File "/.../tensorflow/python/ops/op_def_library.py", line 704, in apply_op
op_def=op_def)
File "/.../tensorflow/python/framework/ops.py", line 2260, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/.../tensorflow/python/framework/ops.py", line 1234, in init
self._control_flow_context.AddOp(self)
File "/.../tensorflow/python/ops/control_flow_ops.py", line 1479, in AddOp
self._AddOpInternal(op)
File "/.../tensorflow/python/ops/control_flow_ops.py", line 1499, in _AddOpInternal
self.AddValue(x)
File "/.../tensorflow/python/ops/control_flow_ops.py", line 1438, in AddValue
real_val = grad_ctxt.grad_state.GetRealValue(val)
File "/.../tensorflow/python/ops/control_flow_ops.py", line 781, in GetRealValue
real_value = self.AddBackPropAccumulatedValue(h_value, value)
File "/.../tensorflow/python/ops/control_flow_ops.py", line 731, in AddBackPropAccumulatedValue
history_value = _SwitchRefOrTensor(history_value, pred)[branch]
File "/.../tensorflow/python/ops/control_flow_ops.py", line 324, in _SwitchRefOrTensor
return ref_switch(data, pred, name=name)
File "/.../tensorflow/python/ops/gen_control_flow_ops.py", line 341, in ref_switch
result = _op_def_lib.apply_op("RefSwitch", data=data, pred=pred, name=name)
File "/.../tensorflow/python/ops/op_def_library.py", line 459, in apply_op
as_ref=input_arg.is_ref).dtype.name
File "/.../tensorflow/python/framework/ops.py", line 620, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/.../tensorflow/python/ops/constant_op.py", line 179, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/.../tensorflow/python/ops/constant_op.py", line 162, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
File "/.../tensorflow/python/framework/tensor_util.py", line 346, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.
It works fine if I add la, lb as follows, although this would force execution of loss_a and loss_b regardless of the pred in tf.cond().
la = loss_a(a, w)
lb = loss_b(a, w)
loss = tf.cond(tf.equal(c, 0), lambda: la, lambda: lb)
train_op = tf.train.AdamOptimizer(1e-4).minimize(loss)
sess.run(tf.initialize_all_variables())
sess.run(train_op)
Is this a known issue or did I miss something in how to use tf.while_loop within tf.cond?
Activity
[-]minimize raise "ValueError: None values not supported." error when tf.while_loop used inside fn() of tf.cond()[/-][+]minimize raises "ValueError: None values not supported." error when tf.while_loop used inside fn() of tf.cond()[/+]concretevitamin commentedon Jul 18, 2016
Could you try using the (somewhat experimental)
@Defun
functionality to see if it works? SeetestWhileFuncBasic()
incontrol_flow_ops_py_test.py
.aselle commentedon Jul 27, 2016
Automatically closing due to lack of recent activity. Please reopen if additional information becomes available.
rifatmahmud commentedon Jul 28, 2016
The error is also occurring when restoring a model trained using layers.stack with a Estimator class(providing as model directory where the model is saved, and model_fn as the conv_model written in skflow mnist example).
File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 394, in predict as_iterable=as_iterable) File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 663, in _infer_model predictions = self._get_predict_ops(features) File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 897, in _get_predict_ops predictions, _, _ = self._call_model_fn(features, targets, ModeKeys.INFER) File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 806, in _call_model_fn return self._model_fn(features, targets) File "test.py", line 34, in conv_model return learn.models.logistic_regression(h_fc1, y) File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/models.py", line 137, in logistic_regression logging_ops.histogram_summary('%s.y' % vs.get_variable_scope().name, y) File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/logging_ops.py", line 125, in histogram_summary tag=tag, values=values, name=scope) File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/gen_logging_ops.py", line 100, in _histogram_summary name=name) File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/op_def_library.py", line 458, in apply_op as_ref=input_arg.is_ref).dtype.name File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py", line 621, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/constant_op.py", line 180, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/constant_op.py", line 163, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape)) File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_util.py", line 346, in make_tensor_proto raise ValueError("None values not supported.") ValueError: None values not supported.
hendrycks commentedon Aug 5, 2016
I get a similar error when I have a map_fn modifying a variable, and the map_fn is inside of a cond, but this may not be informative if map_fn uses while (I haven't checked).
cshapeshifter commentedon Aug 17, 2016
I'm encountering the same error when calling
learn.Estimator.predict
on a restored, already trained model, unless I calllearn.Estimator.fit
beforehand. The following code is largely based on this example. My guess is that some important stuff isn't initialized by callingpredict
. For example, I don't see "Creating TensorFlow device" or anything like that when only callingpredict
.I'm using a tensorflow 0.10.0rc0 nightly from a few days ago.
To reproduce:
./text_classification_character_rnn.py -m model
to train a model stored in the "model" directory./text_classification_character_rnn.py -m model -t
to load the model and make a prediction only, without callingfit
first, which causes the error.The error:
As a workaround, I can call
classifier.evaluate(x_train, y_train, batch_size=10000)
before callingpredict
, and then it works fine. Maybe this is not a bug but simply an API misunderstanding. I don't see any indication thatevaluate
must be called beforepredict
can be called.yuanbyu commentedon Aug 24, 2016
The original issue posted by liusiqi43@ should already be fixed at HEAD.
ozt-j commentedon Sep 27, 2016
the same issue.
python train_cifar.py
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
Hippogriff commentedon Oct 2, 2016
Did anyone find solution to this problem?
finlay-liu commentedon Dec 25, 2016
I meet this bug too, it seems about the tf.Variable, you can try it with tf.Variable(0, trainable = False)
drpngx commentedon Jan 24, 2017
@yuanbyu I think I saw something recently about that. Was that fixed at some point recently?
agniszczotka commentedon Mar 3, 2017
I met the same exception: ValueError: None values not supported.
It is impossible to use train model in the way:
nn = tf.contrib.learn.Estimator(model_fn=model_fn,model_dir='/path') predictions = nn.predict(x=prediction_set.data, as_iterable=True)
the hack to solve it is to run an evaluation before a prediction.
nn = tf.contrib.learn.Estimator(model_fn=model_fn,model_dir='/path') ev = nn.evaluate(x=test_set.data, y=test_set.target, steps=1) predictions = nn.predict(x=prediction_set.data, as_iterable=True)
efeiefei commentedon Mar 8, 2017
@agniszczotka
Great ! That solved my problem !
But I still do not know why ~
asimshankar commentedon Apr 5, 2017
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!