Python 如何可视化TFR记录?
我在另一个论坛上被问到这个问题,但我想我会把它贴在这里,为任何有TFRecords问题的人 如果TFRecord文件中的标签与labels.pbtxt文件中的标签不对齐,TensorFlow的对象检测API可能会产生奇怪的行为。它将运行,损耗可能会减少,但网络不会产生良好的检测 另外,我总是混淆X-Y和行-列空间,所以我总是喜欢仔细检查以确保我的注释实际上是对图像的正确部分进行注释 我发现最好的方法是解码TF记录并用TF工具绘制它。下面是一些代码:Python 如何可视化TFR记录?,python,tensorflow,object-detection,tfrecord,Python,Tensorflow,Object Detection,Tfrecord,我在另一个论坛上被问到这个问题,但我想我会把它贴在这里,为任何有TFRecords问题的人 如果TFRecord文件中的标签与labels.pbtxt文件中的标签不对齐,TensorFlow的对象检测API可能会产生奇怪的行为。它将运行,损耗可能会减少,但网络不会产生良好的检测 另外,我总是混淆X-Y和行-列空间,所以我总是喜欢仔细检查以确保我的注释实际上是对图像的正确部分进行注释 我发现最好的方法是解码TF记录并用TF工具绘制它。下面是一些代码: import matplotlib.pyplo
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from object_detection.utils import visualization_utils as vu
from object_detection.protos import string_int_label_map_pb2 as pb
from object_detection.data_decoders.tf_example_decoder import TfExampleDecoder as TfDecoder
from google.protobuf import text_format
def main(tfrecords_filename, label_map=None):
if label_map is not None:
label_map_proto = pb.StringIntLabelMap()
with tf.gfile.GFile(label_map,'r') as f:
text_format.Merge(f.read(), label_map_proto)
class_dict = {}
for entry in label_map_proto.item:
class_dict[entry.id] = {'name':entry.display_name}
sess = tf.Session()
decoder = TfDecoder(label_map_proto_file=label_map, use_display_name=False)
sess.run(tf.tables_initializer())
for record in tf.python_io.tf_record_iterator(tfrecords_filename):
example = decoder.decode(record)
host_example = sess.run(example)
scores = np.ones(host_example['groundtruth_boxes'].shape[0])
vu.visualize_boxes_and_labels_on_image_array(
host_example['image'],
host_example['groundtruth_boxes'],
host_example['groundtruth_classes'],
scores,
class_dict,
max_boxes_to_draw=None,
use_normalized_coordinates=True)
plt.imshow(host_example['image'])
plt.show()
谢谢你的密码,@Steve!我在github回购协议上到处找,找不到检查记录的方法 只是想指出,似乎缺少一个导入行:
from google.protobuf import text_format
添加此项后,它对我来说运行正常如果要直观地检查边界框/标签,可以检查此TFRecord Viewer: 谢谢你,米兰!