Reading multiple bytes into a single value in Tens

2019-05-12 04:03发布

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

1条回答
SAY GOODBYE
2楼-- · 2019-05-12 04:35

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.

查看更多
登录 后发表回答