Reputation: 1488
tf.to_float(tf.convert_to_tensor(python_object))
used many times in Tensorflow object detection api like grid_anchor_generator. normaly I'll use tf.constant(python_object, dtype=tf.float32)
. I'm wondering the difference between them. Thanks
Upvotes: 18
Views: 8657
Reputation: 1088
For tf.constant
, the input value must be a static non-tensor type. For example a numpy array.
For tf.convert_to_tensor
, the value "an object whose type has a registered Tensor conversion function." This means input types like Tensors or tf.Variables can also be provided as inputs. For example, see the tensor conversion function for Variables here: https://github.com/tensorflow/tensorflow/blob/r1.8/tensorflow/python/ops/variables.py#L762
Upvotes: 14