Files
MPKFNet/creat_coco_annotation.py
T
2026-07-17 18:55:31 +08:00

26 lines
1.4 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'''
author : Hatcher W
Email: hcwang@semi.ac.cn
use: 用于根据VOC的images中train和test的图像文件分成annotation 的xml文件,将Annotation分开放到Anno_train,Anno_val中,
input:images/train ,test 图像文件路径
output:COCO/Anno_train and COCO/Anno_val
'''
import os,shutil
from tqdm import tqdm
rootPath = "/data4/Hatcher/smallobject/voc_class/CDB_vehicle/images/train"
rootPathxml = "/data4/Hatcher/smallobject/voc_class/CDB_vehicle/Annotations"
rootresultpath = "/data4/Hatcher/smallobject/voc_class/CDB_vehicle/COCO/Anno_train"
if not os.path.exists(rootresultpath):
os.makedirs(rootresultpath)
for image in tqdm(os.listdir(rootPath)):
shutil.copy(os.path.join(rootPathxml,image.replace(".jpg",".xml").replace(".png",".xml")),os.path.join(rootresultpath,image.replace(".jpg",".xml").replace(".png",".xml")))
#exit()
rootPath = "/data4/Hatcher/smallobject/voc_class/CDB_vehicle/images/test"
rootPathxml = "/data4/Hatcher/smallobject/voc_class/CDB_vehicle/Annotations"
rootresultpath = "/data4/Hatcher/smallobject/voc_class/CDB_vehicle/COCO/Anno_test"
if not os.path.exists(rootresultpath):
os.makedirs(rootresultpath)
for image in tqdm(os.listdir(rootPath)):
shutil.copy(os.path.join(rootPathxml,image.replace(".jpg",".xml").replace(".png",".xml")),os.path.join(rootresultpath,image.replace(".jpg",".xml").replace(".png",".xml")))