tensorflow 将 tf.int32 转换为 tf.string 适合 Google 云 ml-engine 的版本
tensorflow cast tf.int32 to tf.string in version suitable for Google cloud ml-engine
我想将 tf.int32
类型的张量转换为 tf.string
类型的张量。
感谢 我知道在 1.12 版本中我可以使用 tf.strings.format
:
import tensorflow as tf
x = tf.constant([1, 2, 3], dtype=tf.int32)
x_as_string = tf.map_fn(lambda xi: tf.strings.format('{}', xi), x, dtype=tf.string)
with tf.Session() as sess:
res = sess.run(x_as_string)
print(res)
# [b'1' b'2' b'3']
但我想在 Google 云 ml-engine 上执行此操作(今天)仅支持 1.10 版。
我可以在早期版本的 tensorflow 中使用替代操作吗?
或者,在 Google cloud ml-engine 中是否可以使用新版本的 TensorFlow?
tf.as_string
应该可以将整数转换为字符串。
我想将 tf.int32
类型的张量转换为 tf.string
类型的张量。
感谢 tf.strings.format
:
import tensorflow as tf
x = tf.constant([1, 2, 3], dtype=tf.int32)
x_as_string = tf.map_fn(lambda xi: tf.strings.format('{}', xi), x, dtype=tf.string)
with tf.Session() as sess:
res = sess.run(x_as_string)
print(res)
# [b'1' b'2' b'3']
但我想在 Google 云 ml-engine 上执行此操作(今天)仅支持 1.10 版。
我可以在早期版本的 tensorflow 中使用替代操作吗?
或者,在 Google cloud ml-engine 中是否可以使用新版本的 TensorFlow?
tf.as_string
应该可以将整数转换为字符串。