Facepalm0 commited on
Commit
d52d35f
·
verified ·
1 Parent(s): 5e6fb83

Upload move_pictures.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. move_pictures.py +42 -0
move_pictures.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ from pathlib import Path
4
+
5
+ def move_images():
6
+ # 基础路径
7
+ eval_dir = Path('jk_zfls/round0_eval')
8
+ train_dir = Path('jk_zfls/round0_train')
9
+
10
+
11
+ # 处理前20个类别
12
+ for class_idx in range(20):
13
+ # 使用zfill(2)来生成带前导零的类别名称(00, 01, 02...)
14
+ class_name = str(class_idx).zfill(2)
15
+ eval_class_dir = eval_dir / class_name
16
+ train_class_dir = train_dir / class_name
17
+
18
+ # 获取评估集中该类别的所有图片
19
+ if not eval_class_dir.exists():
20
+ print(f"Warning: Directory {eval_class_dir} does not exist")
21
+ continue
22
+
23
+ # 修改这里:获取label编号在200-239之间的图片
24
+ images = []
25
+ for i in range(200, 240): # 200到239
26
+ img_name = f"label{class_name}_{str(i).zfill(3)}.jpg"
27
+ img_path = eval_class_dir / img_name
28
+ if img_path.exists():
29
+ images.append(img_path)
30
+
31
+ # 移动图片
32
+ for img_path in images:
33
+ target_path = train_class_dir
34
+ try:
35
+ shutil.move(str(img_path), str(target_path))
36
+ print(f"Moved {img_path.name} to {target_path}")
37
+ except Exception as e:
38
+ print(f"Error moving {img_path}: {e}")
39
+
40
+ if __name__ == '__main__':
41
+ move_images()
42
+ print("Image moving completed!")