0

I am stuck in a simple looking problem in Tensorflow.

Traceback (most recent call last):
  File op_def_library.py, line 510, in _apply_op_helper
    preferred_dtype=default_dtype)
  File ops.py, line 1040, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File ops.py, line 883, in _TensorTensorConversionFunction
    (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int64 for Tensor with dtype float32: 'Tensor("sequence_sparse_softmax_cross_entropy/zeros_like:0", shape=(?, ?, 10004), dtype=float32)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "red.py", line 281, in <module>
    main()
  File "red.py", line 99, in main
    sequence_length=lengths)
  File loss.py, line 225, in sequence_sparse_softmax_cross_entropy
    losses = xloss(labels=labels, logits=logits)
  File loss.py", line 48, in loss
    post = array_ops.where(target_tensor > zeros, target_tensor - sigmoid_p, zeros)
  gen_math_ops.py, line 2924, in greater
    "Greater", x=x, y=y, name=name)
  op_def_library.py, line 546, in _apply_op_helper
    inferred_from[input_arg.type_attr]))
TypeError: Input 'y' of 'Greater' Op has type float32 that does not match type int64 of argument 'x'

Using as type also does not work.

I just defined another function to be used. I defined it and tried to use it. What should I do to make it work? I just want to define a function that takes tensors as input just like tf cross entropy function. Please suggest how to do that.

In particular, how can I resolve the error?

Rafael
  • 651
  • 13
  • 30
  • 1
    Whenever you need a tensor to be evaluated, you need to run the graph in a session, it looks like you tried to compare the value of a variable with a tensor variable before evaluating that variable (Running the graph) – anand_v.singh Jan 29 '19 at 04:31
  • @anand_v.singh I just defined another function to be used.. defined it and tried to use it..what should I do to make it work? I just want to define a function that takes tensors as input just like tf cross entropy function. please suggest how to do that. thank you! – Rafael Jan 29 '19 at 04:34
  • Run that within a `tf.Session()` construct, if you are still not able to run it, put your code on GitHub and post a link, I will go through it later – anand_v.singh Jan 29 '19 at 04:36
  • https://stackoverflow.com/questions/35596629/how-to-convert-tf-int64-to-tf-float32 – prosti Jan 30 '19 at 13:17

0 Answers0