一、不能直接用record文件训练
之前想偷懒,直接用windows下做的record文件、pbtxt文件,config文件传到ubuntu上,想直接用来跑,没想到浪费了时间做出来的pb文件根本什么效果也没有,一脸懵逼,遂在大哥群里问,大哥答复不能只用record脱离数据集图片,那好吧,那就把数据集传到ubuntu吧,可是xml都做好了啊,里面还包含路径,怎么整,于是目录二便诞生了..........
二、更改labelImg做的xml文件里的图片路径
P话不多说,直接上代码,(这也是大哥们的代码改装而来)
import xml.etree.ElementTree as ET import os path = "E:\\tensorflow-models\\models-master\\research\\object_detection\\images\\img\\" # xml文件存放路径 sv_path = "E:\\tensorflow-models\\models-master\\research\\object_detection\\images\\images\\" # 修改后的xml文件存放路径 imgpath = "/home/Z/models/research/object_detection/test01/images/" # 新的path路径 files = os.listdir(path) # 读取路径下所有文件名 for xmlFile in files: if xmlFile.endswith('.xml'): tree = ET.ElementTree(file=path + xmlFile) # 打开xml文件,送到tree解析 root = tree.getroot() # 得到文档元素对象 root[0].text = 'ImageSets' # root[0].text是annotation下第一个子节点中内容,直接赋值替换文本内容 root[2].text = imgpath + xmlFile # 替换后的内容保存在内存中需要将其写出 tree.write(sv_path + xmlFile)