在TensorFlow中将多个字节读入单个值 [英] Reading multiple bytes into a single value in TensorFlow

查看:448
本文介绍了在TensorFlow中将多个字节读入单个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以类似于TensorFlow中的cifar10示例中所述的方式读取标签:

  ... 。
label_bytes = 2#在原始版本中为1
result.key,value = reader.read(filename_queue)
record_bytes = tf.decode_raw(value,tf.uint8)
result.label = tf.cast(tf.slice(record_bytes,[0],[label_bytes]),tf.int32)
....
pre>

问题是,如果label_byte大于1(例如2),result.label似乎变成了两个元素的张量字节)。我只想将连续的标签字节的字节表示为单个值。



感谢

解决方案

解码器,使用它解码int16并以第一个元素作为您的标签

  shorts = tf.decode_raw(value,tf.int16) 
result.label = tf.cast(shorts [0],tf.int32)

有一个更好的解决方案,但它的工作原理。


I'm trying to read the label in a similar way as described in cifar10 example in TensorFlow:

 ....
 label_bytes = 2 # it was 1 in the original version
 result.key, value = reader.read(filename_queue)
 record_bytes = tf.decode_raw(value, tf.uint8)
 result.label = tf.cast(tf.slice(record_bytes, [0], [label_bytes]), tf.int32)
 ....

The problem is, if label_byte is bigger than 1 (e.g.,2), result.label seems to become a tensor of two elements (each of which is 1-byte). I just want to represent the consecutive label_bytes of bytes into a single value. How do I do that?

Thanks

解决方案

Create a second decoder, decode int16 with it and take the first element as your label

shorts = tf.decode_raw(value, tf.int16)
result.label = tf.cast(shorts[0], tf.int32)

There's probably a better solution but it works.

这篇关于在TensorFlow中将多个字节读入单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆