Delete sp.py
Browse files
sp.py
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import shutil
|
| 3 |
-
import random
|
| 4 |
-
|
| 5 |
-
# 获取所有图片文件
|
| 6 |
-
image_dir = 'images'
|
| 7 |
-
image_files = [f for f in os.listdir(image_dir) if f.endswith(('.png', '.jpg', '.jpeg'))]
|
| 8 |
-
|
| 9 |
-
# 随机打乱图片列表
|
| 10 |
-
random.shuffle(image_files)
|
| 11 |
-
|
| 12 |
-
# 计算分割点
|
| 13 |
-
split_point = len(image_files) // 2
|
| 14 |
-
|
| 15 |
-
# 创建两个目标文件夹
|
| 16 |
-
os.makedirs('dataset_1', exist_ok=True)
|
| 17 |
-
os.makedirs('dataset_2', exist_ok=True)
|
| 18 |
-
|
| 19 |
-
# 分别移动文件到两个文件夹
|
| 20 |
-
for i, img_file in enumerate(image_files):
|
| 21 |
-
# 获取对应的txt文件名
|
| 22 |
-
txt_file = os.path.splitext(img_file)[0] + '.txt'
|
| 23 |
-
|
| 24 |
-
# 确定目标文件夹
|
| 25 |
-
target_dir = 'dataset_1' if i < split_point else 'dataset_2'
|
| 26 |
-
|
| 27 |
-
# 移动图片和txt文件
|
| 28 |
-
shutil.move(os.path.join(image_dir, img_file), os.path.join(target_dir, img_file))
|
| 29 |
-
if os.path.exists(os.path.join(image_dir, txt_file)):
|
| 30 |
-
shutil.move(os.path.join(image_dir, txt_file), os.path.join(target_dir, txt_file))
|
| 31 |
-
|
| 32 |
-
print(f'已将{len(image_files)}个图文对平均分配到dataset_1和dataset_2文件夹中')
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|