python - Tensorflow 对象检测 API : how to create tfrecords with images not containing any labels (hard negatives)?

标签 python tensorflow deep-learning object-detection-api

你好。

我目前在自己的数据集上使用 tensorflow 对象检测 API(带有 Faster Rcnn),对于我的一些标签,我已经确定了很可能被检测为误报的对象,并且我知道该 API 使用hard examples mining,所以我想做的是将包含这些 hard objects 的图像引入训练中,以便 miner 可以将它们作为 hard negatives。

在这个对话之后 知乎 https://github.com/tensorflow/models/issues/2544有人告诉我这是可能的

You can have purely negative images and faster_rcnn models will sample from anchors from them.

所以我的问题是:如何使用一些没有任何边界框的图像创建 tfrecords?我应该在关联的 .xml 文件中放入什么?

最佳答案

在您的 tfrecords 生成脚本中,确保您将硬底片图像的元数据添加到 tf 记录中,就像这样 -

tf_example = tf.train.Example(features=tf.train.Features(feature={
            'image/height': dataset_util.int64_feature(height),
            'image/width': dataset_util.int64_feature(width),
            'image/filename': dataset_util.bytes_feature(filename),
            'image/source_id': dataset_util.bytes_feature(filename),
            'image/encoded': dataset_util.bytes_feature(encoded_jpg),
            'image/format': dataset_util.bytes_feature(image_format)
            }))

对于带有对象的图像,您还必须添加边界框和标签信息 -

tf_example = tf.train.Example(features=tf.train.Features(feature={
            'image/height': dataset_util.int64_feature(height),
            'image/width': dataset_util.int64_feature(width),
            'image/filename': dataset_util.bytes_feature(filename),
            'image/source_id': dataset_util.bytes_feature(filename),
            'image/encoded': dataset_util.bytes_feature(encoded_jpg),
            'image/format': dataset_util.bytes_feature(image_format),
            'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
            'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
            'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
            'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
            'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
            'image/object/class/label': dataset_util.int64_list_feature(classes),
        }))

还要确保在 pipeline.config 文件中将 min_negatives_per_image 设置为正数,否则它不会使用负图像进行训练

关于python - Tensorflow 对象检测 API : how to create tfrecords with images not containing any labels (hard negatives)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47351307/

相关文章:

python - 使用 OpenCV 的 VideoCapture 和 Python 从视频中抓取慢速图像(帧)

python - Keras:将模型扁平化输出与向量连接起来

python - 在 python 中使用编解码器 utf-8 文件打开错误

python - 使用按钮事件 tkinter 在 Canvas 中创建图像

Python:做 r = random_stuff() 而不是 meets_condition(r)

python - Django 用户登录表单用户为无

python - 如何在 Tensorboard 中加载选定范围的样本

python - 如何使用 Tensorflow 检测图像中的物体位置?

python - TensorFlow freeze_graph.py : The name 'save/Const:0' refers to a Tensor which does not exist

machine-learning - 如何在PyTorch中实现学习率的随机对数空间搜索?