def create_subs(src_dir): # root_home = os.path.dirname(args.parent_dir) # JPEGImages_dir = os.path.join(args.parent_dir,'-'.format(idx) ,'JPEGImages\\') # Annotations_dir = os.path.join(args.parent_dir, '-'.format(idx) ,'Annotations\\') # io_utils.mkdir(JPEGImages_dir) # io_utils.mkdir(Annotations_dir) # io_utils.remove_all(JPEGImages_dir) # io_utils.remove_all(Annotations_dir) idx = 0 folder = 10 for s in os.listdir(src_dir): if idx % 200 == 0: JPEGImages_dir = os.path.join( args.parent_dir + '-{}'.format(folder), 'JPEGImages/') Annotations_dir = os.path.join( args.parent_dir + '-{}'.format(folder), 'Annotations/') io_utils.mkdir(JPEGImages_dir) io_utils.mkdir(Annotations_dir) io_utils.remove_all(JPEGImages_dir) io_utils.remove_all(Annotations_dir) folder += 1 idx += 1 file = os.path.join(src_dir, s) io_utils.copy(file, JPEGImages_dir)
def copy_to_JPEGImages(src_dir): #把处理好的图片放到JPEGImages target_dir = os.path.join(args.parent_dir, 'JPEGImages/') io_utils.mkdir(target_dir) io_utils.remove_all(target_dir) for s in os.listdir(src_dir): file = os.path.join(src_dir, s) io_utils.copy(file, target_dir)
def create_zip(src_dir, parent_dir): #分包加压缩 # root_home = os.path.dirname(args.parent_dir) # JPEGImages_dir = os.path.join(args.parent_dir,'-'.format(idx) ,'JPEGImages\\') # Annotations_dir = os.path.join(args.parent_dir, '-'.format(idx) ,'Annotations\\') # io_utils.mkdir(JPEGImages_dir) # io_utils.mkdir(Annotations_dir) # io_utils.remove_all(JPEGImages_dir) # io_utils.remove_all(Annotations_dir) idx = 0 folder = 0 for s in os.listdir(src_dir): if idx % 200 == 0: #每200张图片操作一次,从第0张开始 if folder >= 1: parent = temp_dir + '-{}'.format(folder - 1) parent_zip = temp_dir + '-{}.zip'.format(folder - 1) zip_dir(parent, parent_zip) temp_dir = os.path.join( parent_dir, str_date[0:4] + '-' + str_date[4:6] + '-' + str_date[6:8]) JPEGImages_dir = os.path.join(temp_dir + '-{}'.format(folder), 'JPEGImages/') #Annotations_dir = os.path.join(temp_dir + '-{}'.format(folder), 'Annotations\\') io_utils.mkdir(JPEGImages_dir) #io_utils.mkdir(Annotations_dir) io_utils.remove_all(JPEGImages_dir) #确保目标文件夹是空白的 #io_utils.remove_all(Annotations_dir) folder += 1 idx += 1 file = os.path.join(src_dir, s) io_utils.copy(file, JPEGImages_dir) #full_path = Annotations_dir + '\\' + 'test' + '.txt' # 加入了一个txt #open(full_path, 'w') # parent = temp_dir + '-{}'.format(folder - 1) parent_zip = temp_dir + '-{}.zip'.format(folder - 1) zip_dir(parent, parent_zip)
def rename_image(parent_dir, image_dir_name): #重命名 # image_dir_name = 'JPEGImages' data_dir = os.path.join(parent_dir, image_dir_name) data_rename_dir = os.path.join(parent_dir, '{}_rename'.format(image_dir_name)) io_utils.delete_file_folder(data_rename_dir) io_utils.mkdir(data_rename_dir) prefix = 'train' idx = 1000 #起始编码id cur_date = datetime.datetime.now() # str_date = '{year}{month}{day}'.format(year=cur_date.year, month=cur_date.month, day=cur_date.day) for s in os.listdir(data_dir): old = os.path.join(data_dir, s) new = os.path.join( data_rename_dir, '{}_{}_{}.jpg'.format( prefix, str_date[0:4] + '-' + str_date[4:6] + '-' + str_date[6:8], idx)) io_utils.copy(old, new) idx = idx + 1 return data_rename_dir