【发布时间】:2016-10-28 22:19:39
【问题描述】:
我正在使用 Tensorflow/python API 实现一个将图像映射到姿势的回归网络,并尝试处理 FixedLengthRecordReader 的输出。
我正在尝试将 cifar10 example 调整到最低限度以满足我的目的。
cifar10 示例读取原始字节,解码,然后拆分。
result.key, value = reader.read(filename_queue)
# Convert from a string to a vector of uint8 that is record_bytes long.
record_bytes = tf.decode_raw(value, tf.uint8)
# The first bytes represent the label, which we convert from uint8->int32.
result.label = tf.cast(
tf.slice(record_bytes, [0], [label_bytes]), tf.int32)
# The remaining bytes after the label represent the image, which we reshape
# from [depth * height * width] to [depth, height, width].
depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
[result.depth, result.height, result.width])
# Convert from [depth, height, width] to [height, width, depth].
result.uint8image = tf.transpose(depth_major, [1, 2, 0])
我正在从二进制文件列表中读取数据,这些文件保存为 (pose_data, image_data)。因为我的pose数据是float32,而我的图片数据是uint8,所以想先slice,再cast。不幸的是,reader.read 的 value 结果是一个零维字符串张量,所以切片不起作用。
key, value = reader.read(filename_queue)
print value.dtype
print value.get_shape()
<dtype: 'string'>
()
tf.decode_raw(value, dtype) 的结果是一维数组,但需要指定 dtype,而 tf.string 不是它所采用的有效类型。
解码前可以切片吗?还是我必须解码 -> 案例回到字符串 -> 切片 -> 重铸?还有其他方法吗?
【问题讨论】:
标签: python tensorflow slice