【问题标题】:Reading multiple bytes into a single value in TensorFlow在 TensorFlow 中将多个字节读入单个值
【发布时间】:2015-12-31 06:40:20
【问题描述】:

我正在尝试以与 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 字节表示为单个值。我该怎么做?

谢谢

【问题讨论】:

    标签: machine-learning computer-vision tensorflow


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢,这也是我想出来的,我想解码两次太浪费了。不过,我仍在寻找更好的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 2020-09-17
    • 2014-01-02
    • 1970-01-01
    相关资源
    最近更新 更多