当前位置:   article > 正文

数据格式处理:数据转换(yolo转voc和voc转coco)及voc数据删除等_voc 格式转coco

voc 格式转coco

yolo转voc:

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # @Time :2021/8/31 下午3:06
  4. # @Author :
  5. # @ProjectName :mmdetection-master
  6. # @File :yolo2voc.py
  7. # @Description :
  8. import os
  9. import codecs
  10. import cv2
  11. import random
  12. import xml.etree.ElementTree as ET
  13. from xml.dom.minidom import parse
  14. def vocXMLFormat(filePath, imgName, imgW, imgH, objNames, locs, depth=3, truncated=0, difficult=0):
  15. """
  16. Generate xml annotation file,eg:
  17. vocXMLFormat("0000.xml", "0001.png", 608, 608, ["person", "TV"], [[24, 32, 156, 145], [124, 76, 472, 384]])
  18. Args:
  19. filePath:The path of the file saved in the generated xml
  20. imgName:xml file annotates the name of the picture
  21. imgW:
  22. imgH:
  23. objNames:The object contained in the picture, format: ["object label 1", "object label 2"...]
  24. locs:The picture contains the coordinates of the object, format: [[x,y,w,h],[x,y,w,h]...]
  25. depth:
  26. truncated:
  27. difficult:
  28. Returns:
  29. """
  30. if (objNames == None) or (locs == None):
  31. print("The objNames or locs is None!!!")
  32. return
  33. with codecs.open(filePath, 'w', 'utf-8') as xml:
  34. xml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
  35. xml.write('<annotation>\n')
  36. xml.write('\t<folder>' + 'voc format' + '</folder>\n')
  37. xml.write('\t<filename>' + imgName + '</filename>\n')
  38. xml.write('\t<path>' + imgName + '</path>\n')
  39. xml.write('\t<source>\n')
  40. xml.write('\t\t<database>weiz</database>\n')
  41. xml.write('\t</source>\n')
  42. xml.write('\t<size>\n')
  43. xml.write('\t\t<width>' + str(imgW) + '</width>\n')
  44. xml.write('\t\t<height>' + str(imgH) + '</height>\n')
  45. xml.write('\t\t<depth>' + str(depth) + '</depth>\n')
  46. xml.write('\t</size>\n')
  47. xml.write('\t<segmented>0</segmented>\n')
  48. for ind, name in enumerate(objNames):
  49. xml.write('\t<object>\n')
  50. xml.write('\t\t<name>' + name + '</name>\n')
  51. xml.write('\t\t<pose>Unspecified</pose>\n')
  52. xml.write('\t\t<truncated>' + str(truncated) + '</truncated>\n')
  53. xml.write('\t\t<difficult>' + str(difficult) + '</difficult>\n')
  54. xml.write('\t\t<bndbox>\n')
  55. xml.write('\t\t\t<xmin>' + str(locs[ind][0]) + '</xmin>\n')
  56. xml.write('\t\t\t<ymin>' + str(locs[ind][1]) + '</ymin>\n')
  57. xml.write('\t\t\t<xmax>' + str(locs[ind][0] + locs[ind][2]) + '</xmax>\n')
  58. xml.write('\t\t\t<ymax>' + str(locs[ind][1] + locs[ind][3]) + '</ymax>\n')
  59. xml.write('\t\t</bndbox>\n')
  60. xml.write('\t</object>\n')
  61. xml.write('</annotation>')
  62. xml.close()
  63. print("The {} accomplish!".format(filePath))
  64. def read_line(file_name):
  65. """
  66. read file by line
  67. :param file_name:
  68. :return:
  69. """
  70. lines = []
  71. file = open(file_name)
  72. for line in file:
  73. line = line.strip('\n')
  74. lines.append(line)
  75. file.close()
  76. return lines
  77. def showAnnotions(image, locs, labels):
  78. """
  79. show annotions
  80. :param locs:
  81. :param labels:
  82. :return:
  83. """
  84. for ind, (x, y, w, h) in enumerate(locs):
  85. cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
  86. cv2.putText(image, labels[ind], (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 1)
  87. cv2.imshow("iamge", image)
  88. cv2.waitKey(30)
  89. def yolo2voc(txt_path, image_path, save_xml_path, label_path):
  90. """
  91. Args:
  92. txt_path:
  93. image_path:
  94. save_xml_path:
  95. label_path:
  96. Returns:
  97. """
  98. txt_list = os.listdir(txt_path)
  99. label_list = read_line(label_path)
  100. for txt_name in txt_list:
  101. image_name, _ = os.path.splitext(txt_name)
  102. for extension in ["png", "jpg"]: # read image
  103. image_name_path = image_name + '.' + extension
  104. image_name_path = os.path.join(image_path, image_name_path)
  105. if os.path.exists(image_name_path):
  106. image = cv2.imread(image_name_path)
  107. image_h, image_w, image_channel = image.shape
  108. break
  109. else:
  110. continue
  111. txt_name_path = os.path.join(txt_path, txt_name)
  112. lines = read_line(txt_name_path)
  113. object_locs = []
  114. object_labels = []
  115. for line in lines:
  116. ind, center_x, center_y, w, h = line.split(' ')
  117. x = (float(center_x) - float(w) / 2) * image_w
  118. y = (float(center_y) - float(h) / 2) * image_h
  119. w = float(w) * image_w
  120. h = float(h) * image_h
  121. object_locs.append([int(x), int(y), int(w), int(h)])
  122. object_labels.append(label_list[int(ind)])
  123. # showAnnotions(image, object_locs, object_labels)
  124. xml_name_path = os.path.join(save_xml_path, image_name + ".xml")
  125. vocXMLFormat(xml_name_path, os.path.split(image_name_path)[-1], image_w, image_h, object_labels, object_locs,
  126. image_channel)
  127. def fractionalSet(imagePath, txtSavePath):
  128. """
  129. Args:
  130. imagePath:
  131. txtSavePath:
  132. Returns:
  133. """
  134. testPercent = 0.1
  135. valPercent = 0.1
  136. trainPercent = 0.8
  137. imageNames = os.listdir(imagePath)
  138. testNum = int(len(imageNames) * testPercent)
  139. print("testNum:", testNum)
  140. valNum = int(len(imageNames) * valPercent)
  141. print("valNum:", valNum)
  142. trainNum = len(imageNames) - testNum - valNum
  143. print("trainNum", trainNum)
  144. trainValNum = trainNum + valNum
  145. print("trainValNum:", trainValNum)
  146. test = random.sample(imageNames, testNum)
  147. imageNamesTrainVal = list(set(imageNames) - set(test))
  148. val = random.sample(imageNamesTrainVal, valNum)
  149. train = list(set(imageNamesTrainVal) - set(val))
  150. ftrainval_path = os.path.join(txtSavePath, "trainval.txt")
  151. ftest_path = os.path.join(txtSavePath, "test.txt")
  152. ftrain_path = os.path.join(txtSavePath, "train.txt")
  153. fval_path = os.path.join(txtSavePath, "val.txt")
  154. ftrainval = open(ftrainval_path, 'w')
  155. ftest = open(ftest_path, 'w')
  156. ftrain = open(ftrain_path, 'w')
  157. fval = open(fval_path, 'w')
  158. for imageName in imageNames:
  159. if imageName in test:
  160. imageName = imageName.split('.')[0] + "\n"
  161. ftest.write(imageName)
  162. else:
  163. if imageName in val:
  164. imageName = imageName.split('.')[0] + "\n"
  165. fval.write(imageName)
  166. else:
  167. imageName = imageName.split('.')[0] + "\n"
  168. ftrain.write(imageName)
  169. ftrainval.write(imageName)
  170. ftrainval.close()
  171. ftrain.close()
  172. fval.close()
  173. ftest.close()
  174. def convert(size, box):
  175. """
  176. ·µ»Ø¹éÒ»»¯ºóµÄÖÐÐĵ㣬¿í¸ßÖµ
  177. :param size:
  178. :param box:
  179. :return:
  180. """
  181. dw = 1./(size[0])
  182. dh = 1./(size[1])
  183. x = (box[0] + box[1])/2.0 - 1
  184. y = (box[2] + box[3])/2.0 - 1
  185. w = box[1] - box[0]
  186. h = box[3] - box[2]
  187. x = x*dw
  188. w = w*dw
  189. y = y*dh
  190. h = h*dh
  191. return (x,y,w,h)
  192. def count_label_num(xml_path):
  193. """
  194. Args:
  195. xml_path:
  196. Returns:
  197. """
  198. classes = []
  199. num = []
  200. xml_list = os.listdir(xml_path)
  201. for xml_name in xml_list:
  202. xml_name_path = os.path.join(xml_path, xml_name)
  203. et = ET.parse(xml_name_path)
  204. root = et.getroot()
  205. for obj in root.iter('object'):
  206. cls = obj.find("name").text
  207. try:
  208. cls_id = classes.index(cls)
  209. except ValueError:
  210. classes.append(cls)
  211. num.append(0)
  212. print("add new label:{}".format(cls))
  213. cls_id = classes.index(cls)
  214. num[cls_id] += 1
  215. return classes, num
  216. def checkLabel(imagePath, labelPath):
  217. """
  218. Ëæ»ú³é²é¼ì²é±ê×¢Êý¾ÝÊÇ·ñÕýÈ·
  219. :param imagePath:
  220. :param labelPath:
  221. :return:
  222. """
  223. labelNames = os.listdir(labelPath)
  224. while True:
  225. index = random.randint(0, len(labelNames) - 1)
  226. labelPath_tmp = os.path.join(labelPath, labelNames[index])
  227. tree = ET.parse(labelPath_tmp)
  228. root = tree.getroot()
  229. imageName = root.find('filename').text
  230. labels = [] # ±êÇ©ÐÅÏ¢[[x,y,w,h,label]]
  231. for obj in root.iter('object'):
  232. x1 = int(obj.find("bndbox").find("xmin").text)
  233. y1 = int(obj.find("bndbox").find("ymin").text)
  234. x2 = int(obj.find("bndbox").find("xmax").text)
  235. y2 = int(obj.find("bndbox").find("ymax").text)
  236. name = obj.find("name").text
  237. labels.append([x1, y1, x2, y2, name])
  238. imagePath_tmp = os.path.join(imagePath, imageName)
  239. img = cv2.imread(imagePath_tmp)
  240. for label in labels:
  241. cv2.rectangle(img, (label[0], label[1]), (label[2], label[3]), (0, 0, 255))
  242. cv2.putText(img, label[-1], (label[0], label[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2)
  243. cv2.imshow(imageName, img)
  244. k = cv2.waitKey(0)
  245. # °´Esc¼üÍ˳ö
  246. if k == 27:
  247. break
  248. # °´ÓÒ¼ýÍ·ºÍϼýÍ·¼ÌÐø¼ì²â
  249. if k != 1 and k != 2:
  250. if k == 27:
  251. break
  252. k = cv2.waitKey(0)
  253. if k == 27:
  254. break
  255. cv2.destroyAllWindows()
  256. txt_path = "/home/zyy/桌面/label"
  257. image_path = "./defect4/JPEGImages"
  258. save_xml_path = "./defect4/Annotations"
  259. image_sets = "./defect4/ImageSets/Main"
  260. label_path = "./defect4/label.txt"
  261. setNames = ["test.txt", "val.txt", "train.txt", "trainval.txt"]
  262. def main():
  263. # yolo2voc(txt_path, image_path, save_xml_path, label_path)
  264. # fractionalSet(image_path, image_sets)
  265. # classes, num = count_label_num(save_xml_path)
  266. # print(classes)
  267. # print(num)
  268. checkLabel(image_path, save_xml_path)
  269. if __name__ == "__main__":
  270. main()

voc转coco

  1. import xml.etree.ElementTree as ET
  2. import os
  3. import json
  4. coco = dict()
  5. coco['images'] = []
  6. coco['type'] = 'instances'
  7. coco['annotations'] = []
  8. coco['categories'] = []
  9. category_set = dict()
  10. image_set = set()
  11. category_item_id = -1
  12. image_id = 20180000000
  13. annotation_id = 0
  14. def addCatItem(name):
  15. global category_item_id
  16. category_item = dict()
  17. category_item['supercategory'] = 'none'
  18. category_item_id += 1
  19. category_item['id'] = category_item_id
  20. category_item['name'] = name
  21. coco['categories'].append(category_item)
  22. category_set[name] = category_item_id
  23. return category_item_id
  24. def addImgItem(file_name, size):
  25. global image_id
  26. if file_name is None:
  27. raise Exception('Could not find filename tag in xml file.')
  28. if size['width'] is None:
  29. raise Exception('Could not find width tag in xml file.')
  30. if size['height'] is None:
  31. raise Exception('Could not find height tag in xml file.')
  32. image_id += 1
  33. image_item = dict()
  34. image_item['id'] = image_id
  35. image_item['file_name'] = file_name
  36. image_item['width'] = size['width']
  37. image_item['height'] = size['height']
  38. coco['images'].append(image_item)
  39. image_set.add(file_name)
  40. return image_id
  41. def addAnnoItem(object_name, image_id, category_id, bbox):
  42. global annotation_id
  43. annotation_item = dict()
  44. annotation_item['segmentation'] = []
  45. seg = []
  46. # bbox[] is x,y,w,h
  47. # left_top
  48. seg.append(bbox[0])
  49. seg.append(bbox[1])
  50. # left_bottom
  51. seg.append(bbox[0])
  52. seg.append(bbox[1] + bbox[3])
  53. # right_bottom
  54. seg.append(bbox[0] + bbox[2])
  55. seg.append(bbox[1] + bbox[3])
  56. # right_top
  57. seg.append(bbox[0] + bbox[2])
  58. seg.append(bbox[1])
  59. annotation_item['segmentation'].append(seg)
  60. annotation_item['area'] = bbox[2] * bbox[3]
  61. annotation_item['iscrowd'] = 0
  62. annotation_item['ignore'] = 0
  63. annotation_item['image_id'] = image_id
  64. annotation_item['bbox'] = bbox
  65. annotation_item['category_id'] = category_id
  66. annotation_id += 1
  67. annotation_item['id'] = annotation_id
  68. coco['annotations'].append(annotation_item)
  69. def _read_image_ids(image_sets_file):
  70. ids = []
  71. with open(image_sets_file) as f:
  72. for line in f:
  73. ids.append(line.rstrip())
  74. return ids
  75. def parseXmlFiles_by_txt(data_dir, json_save_path, split='train'):
  76. """
  77. Args:
  78. data_dir:
  79. json_save_path:
  80. split: 'train' 'trainval' 'test'
  81. Returns:
  82. """
  83. labelfile = split + ".txt"
  84. image_sets_file = data_dir + "/ImageSets/Main/" + labelfile
  85. ids = _read_image_ids(image_sets_file)
  86. for _id in ids:
  87. xml_file = data_dir + f"/Annotations/{_id}.xml"
  88. bndbox = dict()
  89. size = dict()
  90. current_image_id = None
  91. current_category_id = None
  92. file_name = None
  93. size['width'] = None
  94. size['height'] = None
  95. size['depth'] = None
  96. tree = ET.parse(xml_file)
  97. root = tree.getroot()
  98. if root.tag != 'annotation':
  99. raise Exception('pascal voc xml root element should be annotation, rather than {}'.format(root.tag))
  100. # elem is <folder>, <filename>, <size>, <object>
  101. for elem in root:
  102. current_parent = elem.tag
  103. current_sub = None
  104. object_name = None
  105. if elem.tag == 'folder':
  106. continue
  107. if elem.tag == 'filename':
  108. file_name = elem.text
  109. if file_name in category_set:
  110. raise Exception('file_name duplicated')
  111. # add img item only after parse <size> tag
  112. elif current_image_id is None and file_name is not None and size['width'] is not None:
  113. if file_name not in image_set:
  114. current_image_id = addImgItem(file_name, size)
  115. print('add image with {} and {}'.format(file_name, size))
  116. else:
  117. raise Exception('duplicated image: {}'.format(file_name))
  118. # subelem is <width>, <height>, <depth>, <name>, <bndbox>
  119. for subelem in elem:
  120. bndbox['xmin'] = None
  121. bndbox['xmax'] = None
  122. bndbox['ymin'] = None
  123. bndbox['ymax'] = None
  124. current_sub = subelem.tag
  125. if current_parent == 'object' and subelem.tag == 'name':
  126. object_name = subelem.text
  127. if object_name not in category_set:
  128. current_category_id = addCatItem(object_name)
  129. else:
  130. current_category_id = category_set[object_name]
  131. elif current_parent == 'size':
  132. if size[subelem.tag] is not None:
  133. raise Exception('xml structure broken at size tag.')
  134. size[subelem.tag] = int(subelem.text)
  135. # option is <xmin>, <ymin>, <xmax>, <ymax>, when subelem is <bndbox>
  136. for option in subelem:
  137. if current_sub == 'bndbox':
  138. if bndbox[option.tag] is not None:
  139. raise Exception('xml structure corrupted at bndbox tag.')
  140. bndbox[option.tag] = int(option.text)
  141. # only after parse the <object> tag
  142. if bndbox['xmin'] is not None:
  143. if object_name is None:
  144. raise Exception('xml structure broken at bndbox tag')
  145. if current_image_id is None:
  146. raise Exception('xml structure broken at bndbox tag')
  147. if current_category_id is None:
  148. raise Exception('xml structure broken at bndbox tag')
  149. bbox = []
  150. # x
  151. bbox.append(bndbox['xmin'])
  152. # y
  153. bbox.append(bndbox['ymin'])
  154. # w
  155. bbox.append(bndbox['xmax'] - bndbox['xmin'])
  156. # h
  157. bbox.append(bndbox['ymax'] - bndbox['ymin'])
  158. print('add annotation with {},{},{},{}'.format(object_name, current_image_id, current_category_id,
  159. bbox))
  160. addAnnoItem(object_name, current_image_id, current_category_id, bbox)
  161. json.dump(coco, open(json_save_path, 'w'))
  162. """Ö±½Ó´ÓxmlÎļþ¼ÐÖÐÉú³É"""
  163. def parseXmlFiles(xml_path, json_save_path):
  164. for f in os.listdir(xml_path):
  165. if not f.endswith('.xml'):
  166. continue
  167. bndbox = dict()
  168. size = dict()
  169. current_image_id = None
  170. current_category_id = None
  171. file_name = None
  172. size['width'] = None
  173. size['height'] = None
  174. size['depth'] = None
  175. xml_file = os.path.join(xml_path, f)
  176. print(xml_file)
  177. tree = ET.parse(xml_file)
  178. root = tree.getroot()
  179. if root.tag != 'annotation':
  180. raise Exception('pascal voc xml root element should be annotation, rather than {}'.format(root.tag))
  181. # elem is <folder>, <filename>, <size>, <object>
  182. for elem in root:
  183. current_parent = elem.tag
  184. current_sub = None
  185. object_name = None
  186. if elem.tag == 'folder':
  187. continue
  188. if elem.tag == 'filename':
  189. file_name = elem.text
  190. if file_name in category_set:
  191. raise Exception('file_name duplicated')
  192. # add img item only after parse <size> tag
  193. elif current_image_id is None and file_name is not None and size['width'] is not None:
  194. if file_name not in image_set:
  195. current_image_id = addImgItem(file_name, size)
  196. print('add image with {} and {}'.format(file_name, size))
  197. else:
  198. raise Exception('duplicated image: {}'.format(file_name))
  199. # subelem is <width>, <height>, <depth>, <name>, <bndbox>
  200. for subelem in elem:
  201. bndbox['xmin'] = None
  202. bndbox['xmax'] = None
  203. bndbox['ymin'] = None
  204. bndbox['ymax'] = None
  205. current_sub = subelem.tag
  206. if current_parent == 'object' and subelem.tag == 'name':
  207. object_name = subelem.text
  208. if object_name not in category_set:
  209. current_category_id = addCatItem(object_name)
  210. else:
  211. current_category_id = category_set[object_name]
  212. elif current_parent == 'size':
  213. if size[subelem.tag] is not None:
  214. raise Exception('xml structure broken at size tag.')
  215. size[subelem.tag] = int(subelem.text)
  216. # option is <xmin>, <ymin>, <xmax>, <ymax>, when subelem is <bndbox>
  217. for option in subelem:
  218. if current_sub == 'bndbox':
  219. if bndbox[option.tag] is not None:
  220. raise Exception('xml structure corrupted at bndbox tag.')
  221. bndbox[option.tag] = int(option.text)
  222. # only after parse the <object> tag
  223. if bndbox['xmin'] is not None:
  224. if object_name is None:
  225. raise Exception('xml structure broken at bndbox tag')
  226. if current_image_id is None:
  227. raise Exception('xml structure broken at bndbox tag')
  228. if current_category_id is None:
  229. raise Exception('xml structure broken at bndbox tag')
  230. bbox = []
  231. # x
  232. bbox.append(bndbox['xmin'])
  233. # y
  234. bbox.append(bndbox['ymin'])
  235. # w
  236. bbox.append(bndbox['xmax'] - bndbox['xmin'])
  237. # h
  238. bbox.append(bndbox['ymax'] - bndbox['ymin'])
  239. print('add annotation with {},{},{},{}'.format(object_name, current_image_id, current_category_id,
  240. bbox))
  241. addAnnoItem(object_name, current_image_id, current_category_id, bbox)
  242. json.dump(coco, open(json_save_path, 'w'))
  243. if __name__ == '__main__':
  244. # 下面三个test.json、train.json、val.json只能一个一个运行
  245. voc_data_dir = "./defect4"
  246. json_save_path = "./defect4/test.json"
  247. parseXmlFiles_by_txt(voc_data_dir, json_save_path, "test")
  248. # json_save_path = "./defect4/train.json"
  249. # parseXmlFiles_by_txt(voc_data_dir, json_save_path, "train")
  250. # json_save_path = "./defect4/val.json"
  251. # parseXmlFiles_by_txt(voc_data_dir, json_save_path, "val")
  252. # ann_path = "E:/VOCdevkit/VOC2007/Annotations"
  253. # json_save_path = "E:/VOCdevkit/test.json"
  254. # parseXmlFiles(ann_path, json_save_path)

voc数据删除指定类别或更改类别名称

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # @Time :2023/8/8 9:08
  4. # @Author :weiz
  5. # @ProjectName :jiangling_new
  6. # @File :xml_process.py
  7. # @Description :
  8. # Copyright (C) 2021-2025 Jiangxi Institute Of Intelligent Industry Technology Innovation
  9. import os
  10. import xml.dom.minidom
  11. import xml.etree.cElementTree as ET
  12. def delete_specified_cls(xmlFolderPath, xmlSavePath, delete_cls):
  13. xml_list = os.listdir(xmlFolderPath)
  14. for xml_name in xml_list:
  15. xml_tree = ET.parse(os.path.join(xmlFolderPath, xml_name))
  16. xml_root = xml_tree.getroot()
  17. total_class_num = 0
  18. class_del_num = 0
  19. for xml_child in xml_root.findall("object"):
  20. total_class_num = total_class_num + 1
  21. old_cls = xml_child.find("name").text
  22. if old_cls in delete_cls:
  23. class_del_num = class_del_num + 1
  24. xml_root.remove(xml_child)
  25. if total_class_num == class_del_num:
  26. print("类别全部被删除了,请删除该文件及对应的图片:", xml_name)
  27. xml_tree.write(os.path.join(xmlSavePath, xml_name))
  28. else:
  29. xml_tree.write(os.path.join(xmlSavePath, xml_name))
  30. print(xml_name, "删除指定类别成功")
  31. def change_class_name(xmlFolderPath, xmlSavePath, old_class, new_class):
  32. """
  33. voc 数据类别替换
  34. :param xmlFolderPath:
  35. :param xmlSavePath:
  36. :param old_class:
  37. :param new_class:
  38. :return:
  39. """
  40. xml_list = os.listdir(xmlFolderPath)
  41. for xml_name in xml_list:
  42. xml_dom = xml.dom.minidom.parse(os.path.join(xmlFolderPath, xml_name))
  43. root = xml_dom.documentElement
  44. newfilename = root.getElementsByTagName('name')
  45. for i, node in enumerate(newfilename):
  46. for j, cls in enumerate(old_class):
  47. if node.firstChild.data == cls:
  48. newfilename[i].firstChild.data = new_class[j]
  49. with open(os.path.join(xmlSavePath, xml_name), 'w') as fh:
  50. xml_dom.writexml(fh)
  51. print(xml_name, "文件类别替换成功")
  52. g_delete_cls = ["spare_tire"]
  53. # g_old_class = ["EKS_18_19", "EKS_20寸", "743出口", "743国内", "743BEV", "756"]
  54. # g_new_class = ["NS1-1532-EA", "NS1-1352-DB", "MS1-1532-BA", "FS1-1532-AC", "KS2-1352-AA", "KS1-1532-AA"]
  55. # g_old_class = ["fuel_92", "fuel_91", "fuel_87", "gasolina", "fuel_91_ron"]
  56. # g_new_class = ["FS1-9A095-AB", "LK29-9A095-BA", "NS1-9A095-CA", "MS1-9A095-AA", "NS1-9A095-AA"]
  57. g_old_class = ["strchromium", "nonchromium"]
  58. g_new_class = ["KS1-D13210-BFD1", "KS1-D13210-ADD1"]
  59. g_xmlFolderPath = r"E:\江铃工业相机及手机采集数据\FL09\燃油标签\Annotations"
  60. g_xmlSavePath = r"E:\江铃工业相机及手机采集数据\FL09\燃油标签\Annotations"
  61. if __name__ == "__main__":
  62. change_class_name(g_xmlFolderPath, g_xmlSavePath, g_old_class, g_new_class)
  63. #delete_specified_cls(g_xmlFolderPath, g_xmlSavePath, g_delete_cls)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/869552
推荐阅读
相关标签
  

闽ICP备14008679号