【发布时间】:2019-02-15 11:00:15
【问题描述】:
我有一个字节列表,我想将它转换为字符串列表,在 python 中我使用这个解码函数:
x=[b'\xd8\xa8\xd9\x85\xd8\xb3\xd8\xa3\xd9\x84\xd8\xa9',
b'\xd8\xa5\xd9\x86\xd8\xb4\xd8\xa7\xd8\xa1',
b'\xd9\x82\xd8\xb6\xd8\xa7\xd8\xa1',
b'\xd8\xac\xd9\x86\xd8\xa7\xd8\xa6\xd9\x8a',
b'\xd8\xaf\xd9\x88\xd9\x84\xd9\x8a']
y=[ a.decode("utf-8") for a in x]
如何在 Tensorflow 中获得相同的结果?
谢谢
【问题讨论】:
-
在 TensorFlow 中没有任何可比性,原因很简单,在 TensorFlow 中,数据类型
tf.string等价于 Python 3 中的bytes(Python 2 中的str),并且没有数据类型 unicode 数据,如 Python 3 中的str(Python 2 中的unicode),所以不能有“解码”的概念。相关:How to decode Unicode string in Tensorflow's graph pipeline、Tensorflow batch: keep result as strings。
标签: python tensorflow tensorflow-datasets