OutOfRangeError (see above for traceback): PaddingFIFOQueue ‘

    xiaoxiao2022-07-02  94

    博主在用原始的NWPU VHR-10数据集进行训练的时候遇到这个错误,最后发现是原始数据集中的标签文件的长和宽被统一成了256x256,与实际图片的尺寸不符合就会引发这个错误,将xml文件中的width和height设置为真实值就可以了。代码如下:

    from xml.etree.ElementTree import ElementTree,Element import os import cv2 def read_xml(in_path): tree = ElementTree() tree.parse(in_path) return tree if __name__ == '__main__': source_pic_root_path = '/home/user8/Desktop/Calculate the size of target/nwpu/JPEGImages/' source_xml_root_path = '/home/user8/Desktop/Calculate the size of target/nwpu/Annotations/' for parent, _, files in os.walk(source_pic_root_path): for file in files: pic_path = os.path.join(parent, file) img = cv2.imread(pic_path) size = img.shape xml_path = os.path.join(source_xml_root_path, file[:-4] + '.xml') tree = read_xml(xml_path) root = tree.getroot() for h_node in root.iter('height'): height = str(size[0]) h_node.text = height for w_node in root.iter('width'): width = str(size[1]) w_node.text = width tree.write(xml_path)

    出现这种错误一般都不是代码的问题。

     

    承接Matlab、Python和C++的编程,机器学习、计算机视觉的理论实现及辅导,本科和硕士的均可,咸鱼交易,专业回答请走知乎,详谈请联系QQ号757160542,非诚勿扰。

     

    最新回复(0)