python str to tensorflow tf.string tensor

问题描述 投票:0回答:1

我正在尝试将具有str格式的python变量转换为具有tf.string数据类型的Tensorflow的Tensor。任何人都知道如何?

这是我尝试过的,但它预计data已经采用Tensor格式。

print(type(data)) # <type 'str'>
myTensor = tf.convert_to_tensor(data, dtype=tf.string) # ERROR!
tensorflow machine-learning computer-vision
1个回答
0
投票

我试图重现错误如下:

myTensor = tf.convert_to_tensor("foo", dtype=tf.string) 

print(myTensor)

但是打印输出是Tensor(“Const:0”,shape =(),dtype = string)所以它似乎在我的情况下正常工作。

我不确定你为什么会收到错误。

© www.soinside.com 2019 - 2024. All rights reserved.