File size: 1,463 Bytes
d52d35f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import shutil
from pathlib import Path

def move_images():
    # 基础路径
    eval_dir = Path('jk_zfls/round0_eval')
    train_dir = Path('jk_zfls/round0_train')
    
    
    # 处理前20个类别
    for class_idx in range(20):
        # 使用zfill(2)来生成带前导零的类别名称(00, 01, 02...)
        class_name = str(class_idx).zfill(2)
        eval_class_dir = eval_dir / class_name
        train_class_dir = train_dir / class_name
        
        # 获取评估集中该类别的所有图片
        if not eval_class_dir.exists():
            print(f"Warning: Directory {eval_class_dir} does not exist")
            continue
            
        # 修改这里:获取label编号在200-239之间的图片
        images = []
        for i in range(200, 240):  # 200到239
            img_name = f"label{class_name}_{str(i).zfill(3)}.jpg"
            img_path = eval_class_dir / img_name
            if img_path.exists():
                images.append(img_path)
        
        # 移动图片
        for img_path in images:
            target_path = train_class_dir
            try:
                shutil.move(str(img_path), str(target_path))
                print(f"Moved {img_path.name} to {target_path}")
            except Exception as e:
                print(f"Error moving {img_path}: {e}")

if __name__ == '__main__':
    move_images()
    print("Image moving completed!")