2019年1月16日星期三

TypeError: ...has type str, but expected one of: bytes

在python3环境中将数据转为TFRecord时遇到的问题
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
TypeError: 'rock' has type str, but expected one of: bytes

解决方式:
转byte feature时用tf.compat.as_bytes(value)将字节或 Unicode 转换为 bytes,使用 UTF-8 编码文本
def _bytes_feature(value):
  value = tf.compat.as_bytes(value)#####
  return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))

没有评论:

发表评论

Failed to find TIFF library

ImportError: Failed to find TIFF library. Make sure that libtiff is installed and its location is listed in PATH|LD_LIBRARY_PATH|.. 解决方法: ...