spark-tfrecord icon indicating copy to clipboard operation
spark-tfrecord copied to clipboard

spark 读取 tfrecord文件,解析tf.train.Feature(bytes_list=tf.train.BytesList(np.array(feature, dtype=np.float32).tobytes())) 文件字节码异常

Open shaoshuaig opened this issue 3 years ago • 1 comments

  1. 如下图所示:用spark直接去读取tfrecord数据,string类型的字段可以直接读取,但是adc_traj等numpy.array的数据会是乱码的形式。 image
  2. 原因是spark加载tfrecord数据的时候,会默认把bytes类型的数据转成str,目前不清楚字符编码。而adc_traj存储的时候是用tf.train.Feature(bytes_list=tf.train.BytesList(np.array(feature, dtype=np.float32).tobytes()))方式存储的。
  3. 用 np.frombuffer(str_y., dtype=np.float32)去解析数据 数据还是会报错: ValueError: buffer size must be a multiple of element size

shaoshuaig avatar Apr 26 '22 03:04 shaoshuaig

Hello, I think your issue is related to spark encoding, can you try the charset option? This stackoverflow thread may be helpful to you: https://stackoverflow.com/questions/51957742/read-a-bytes-column-in-spark

mizhou-in avatar Sep 09 '22 17:09 mizhou-in