我正在尝试使用 MXNet/Gluon 训练对象检测模型(特别是图像中一种类型对象的多个实例),并且 im2rec 工具似乎没有将边界框信息添加到 .rec 文件中。
mxnet.recordio.pack_img()
似乎完成了将图像和标签打包在一起的工作,但我找不到在哪里/如何在像素空间中包含边界框信息。来自文档:
label = 4 # label can also be a 1-D array, for example: label = [1,2,3]
id = 2574
header = mx.recordio.IRHeader(0, label, id, 0)
img = cv2.imread('test.jpg')
packed_s = mx.recordio.pack_img(header, img)
标题没有用于放置边界框信息的位置。知道如何做到这一点吗?
最佳答案
我相信我已经找到答案了。 .lst 文件中的标签打包可以包含一组扩展信息。 documentation这里描述了如何预期该信息。
那么剩下的就是编辑 im2rec.py用扩展信息替换单纯的标签索引(截至撰写本文时第 50 和 60 行)。像这样的东西:
def parse_label_file(fp):
with open(fp, 'r') as f:
data = f.readlines() # or json.load() if appropriate
### Some code here to parse and return the image dimensions
### width, height, id, xmin, ymin, xmax, ymax
return (4, 5, width, id, height, xmin, ymin, xmax, ymax)
...
label_file_path = path[:-4] + ".txt" # or .json as appropriate
if path not in cat:
cat[path] = parse_label_file(label_file_path)
...
关于computer-vision - 可以在 RecordIO 中用图像打包边界框和标签吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47745218/