python shutil.copy 复制文件
#对img和xml 复制10份
import shutil
import os
n = 332
s = 455 - 332
image_path = "D:/data/sg_wimg/v6/test_img_2021_7_19/50/VOCdevkit/JPEGImages"
xml_path = "D:/data/sg_wimg/v6/test_img_2021_7_19/50/VOCdevkit/Annotations"
out = "D:/data/sg_wimg/v6/test_img_2021_7_19/50/VOCdevkit/test"
xml_out = "D:/data/sg_wimg/v6/test_img_2021_7_19/50/VOCdevkit/test2"
for i in range(10):
for i2 in range(n, n + s):
img_path = os.path.join(image_path,str(i2 - i*s)+".jpg")
out_path = os.path.join(out, str(i2) + ".jpg")
shutil.copy(img_path,out_path)
n += s
n = 332
s = 455 - 332
for i in range(10):
for i2 in range(n, n + s):
img_path = os.path.join(xml_path,str(i2 - i*s)+".xml")
out_path = os.path.join(xml_out, str(i2) + ".xml")
shutil.copy(img_path,out_path)
n += s
n = 332
for i in range(454, n + s*10):
print(f"./JPEGImages/{i}.jpg ./Annotations/{i}.xml")