代码之家  ›  专栏  ›  技术社区  ›  Stewart_R

TensorFlow在适用于Google Cloud ML引擎的版本中将tf.int32强制转换为tf.string

  •  1
  • Stewart_R  · 技术社区  · 6 年前

    我想转换一个类型的张量 tf.int32 类型之一 tf.string .

    多亏了 this answer 我知道在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']
    

    但我想在GoogleCloudML引擎上做这个操作,它(今天)只支持1.10版。

    在早期版本的TensorFlow中是否可以使用其他操作?

    或者,也可以选择,在谷歌云ML引擎中使用新版本的TensorFlow吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   rhaertel80    6 年前

    tf.as_string 应该可以将int转换为字符串。