File size: 1,064 Bytes
b83d9ec |
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 44 45 46 47 48 |
import os
import shutil
def make_dir(path):
import os
dir = os.path.exists(path)
if not dir:
os.makedirs(path)
def get_filename_and_houzhui(full_path):
import os
path, file_full_name = os.path.split(full_path)
file_name, 后缀名 = os.path.splitext(file_full_name)
return path,file_name,后缀名
dataset_root_path = '../data/cat_vs_dog'
train_path_cat_new = os.path.join(dataset_root_path, 'new/train/cat')
train_path_dog_new = os.path.join(dataset_root_path, 'new/train/dog')
make_dir(train_path_cat_new)
make_dir(train_path_dog_new)
image_dir_path = os.path.join(dataset_root_path,'train')
image_name_list = os.listdir(image_dir_path)
for image_name in image_name_list:
image_path = os.path.join(image_dir_path,image_name)
path, file_name, 后缀名 = get_filename_and_houzhui(full_path=image_path)
print("file_name:", file_name)
if('cat' in file_name):
shutil.copy(image_path,train_path_cat_new)
elif('dog' in file_name):
shutil.copy(image_path, train_path_dog_new)
|