gpt4 book ai didi

machine-learning - 在 TensorFlow 中将多个字节读取到单个值中

转载 作者:行者123 更新时间:2023-11-30 08:35:03 24 4
gpt4 key购买 nike

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

 ....
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)
....

问题是,如果label_byte大于1(例如2),result.label似乎变成了两个元素的张量(每个元素都是1) -字节)。我只想将连续的 label_bytes 字节表示为单个值。我该怎么做?

谢谢

最佳答案

创建第二个解码器,用它解码 int16 并将第一个元素作为标签

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

可能有更好的解决方案,但它有效。

关于machine-learning - 在 TensorFlow 中将多个字节读取到单个值中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34542274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com