#!usr/bin/python
# -*- coding:utf-8 -*-
import os
# source train dir,训练集文件夹
train_img_dir = "D:/gyh/DataSets/长微博数据/data"
# source train dir,训练标注集文件夹
train_txt_dir = "D:/gyh/DataSets/长微博数据/txt"
# rename and move img to target_img_dir
# train img
i=0
for file in os.listdir(train_img_dir):
i=i+1
img_name = os.path.splitext(os.path.basename(file))
for txtfile in os.listdir(train_txt_dir):
txt_name = os.path.splitext(os.path.basename(txtfile))
if txt_name[0] == img_name[0]:
os.rename(os.path.join(train_img_dir, file),
os.path.join(train_img_dir, "cwb_" + str(i) + ".jpg"))
os.rename(os.path.join(train_txt_dir, txtfile),
os.path.join(train_txt_dir, "cwb_" + str(i) + ".txt"))
网友评论