我使用 TensorFlow 1.12 急切执行,我有以下(不完整的)函数,我想在其中检查一些中间张量:
def parse_example(example_proto, width, height, num_classes):
features = {
'image/encoded': tf.FixedLenFeature((), tf.string),
'image/height': tf.FixedLenFeature((), tf.int64),
'image/width': tf.FixedLenFeature((), tf.int64),
'image/filename': tf.FixedLenFeature((), tf.string),
'image/object/bbox/xmin': tf.VarLenFeature(tf.float32),
'image/object/bbox/xmax': tf.VarLenFeature(tf.float32),
'image/object/bbox/ymin': tf.VarLenFeature(tf.float32),
'image/object/bbox/ymax': tf.VarLenFeature(tf.float32),
'image/object/class/label': tf.VarLenFeature(tf.int64),
'image/object/class/text': tf.VarLenFeature(tf.string),
'image/object/mask': tf.VarLenFeature(tf.string),
'image/depth': tf.FixedLenFeature((), tf.string)
}
parsed_example = tf.parse_single_example(example_proto, features)
#print(tf.sparse_tensor_to_dense(parsed_example['image/object/mask'], default_value=0))
# Decode image
image = tf.image.decode_jpeg(parsed_example['image/encoded'])
parsed_example['image/encoded'] = image
# Depth + RGBD
depth = utilities.decode_depth(parsed_example['image/depth'])
parsed_example['image/depth'] = depth
rgbd = tf.concat([tf.image.convert_image_dtype(image, tf.float32), depth], axis=2)
rgbd = tf.reshape(rgbd, shape=tf.stack([height, width, 4]))
parsed_example['image/rgbd'] = rgbd
mask = tf.sparse.to_dense(parsed_example['image/object/mask'], default_value="")
mask = tf.map_fn(utilities.decode_png_mask, mask, dtype=tf.uint8)
mask = tf.reshape(mask, shape=tf.stack([-1, height, width]), name='mask')
print(mask)
sys.exit()
但是,print(mask)
仅返回Tensor("mask:0", shape=(?, 1000, 1200), dtype=uint8)
,而我想查看实际值。正如TensorFlow 的急切执行指南中所展示的,这应该是可能的。我也试过tf.print(mask, output_stream=sys.stdout)
了,但只打印了一个空行。mask.dtype
是uint8
,所以我猜它应该包含整数,因为它有一个形状。我还觉得奇怪的是mask.device
空字符串。它应该存储在某些设备上,对吧?
如何打印mask
张量的内容?