Python Tensorflow:将占位符强制转换为字符串
在python中,我试图将类型为Python Tensorflow:将占位符强制转换为字符串,python,string,tensorflow,casting,Python,String,Tensorflow,Casting,在python中,我试图将类型为tf.float32的Tensorflow placehoder强制转换为tf.string。相反的情况可以通过,但是没有到字符串的 尝试: resample_multiplier_ = tf.placeholder(tf.float32, [], name='resample_multiplier') name_ = tf.placeholder(tf.string) resample_multiplier_str_ = tf.cast(resample_mul
tf.float32
的Tensorflow placehoder强制转换为tf.string
。相反的情况可以通过,但是没有到字符串的
尝试:
resample_multiplier_ = tf.placeholder(tf.float32, [], name='resample_multiplier')
name_ = tf.placeholder(tf.string)
resample_multiplier_str_ = tf.cast(resample_multiplier_,tf.string) + name_
给我(当我尝试运行会话时):
UnimplementedError:不支持将浮点转换为字符串
如何转换类型为tf.float32
的Tensorflow placehoder?使用:
x=tf.placeholder(tf.float32)
to_str_op=tf.py_func(lambda val:str(val),[x],tf.string)
打印(至打印操作数据类型)#
x = tf.placeholder(tf.float32)
to_str_op = tf.py_func(lambda val: str(val), [x], tf.string)
print(to_str_op.dtype) # <dtype: 'string'>