-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat_dog_rm_anomaly.py
55 lines (40 loc) · 1.26 KB
/
cat_dog_rm_anomaly.py
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
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 26 11:35:12 2018
@author: dawa
"""
import os
import random
import shutil
anomaly_dir = ''
train_dog_dir = 'data\\train_all\\dogs'
train_cat_dir = 'data\\train_all\\cats'
anomaly_dir = 'data\\Anomaly_data\\Obvious'
valid_dog_dir = 'data\\valid\\dogs'
valid_cat_dir = 'data\\valid\\cats'
anomaly_list = os.listdir(anomaly_dir)
for i in range(len(anomaly_list)):
dog_file = os.path.join(train_dog_dir, anomaly_list[i])
cat_file = os.path.join(train_cat_dir, anomaly_list[i])
if (os.path.exists(dog_file)):
print(dog_file)
os.remove(dog_file)
if (os.path.exists(cat_file)):
print(cat_file)
os.remove(cat_file)
#valid_dog = []
#valid_cat = []
#test_dog = []
dog_list = os.listdir(train_dog_dir)
cat_list = os.listdir(train_cat_dir)
valid_dog = random.sample(dog_list, 2500)
valid_cat = random.sample(cat_list, 2500)
for name in valid_dog:
srcname = os.path.join(train_dog_dir, name)
dstname = os.path.join(valid_dog_dir, name)
shutil.move(srcname,dstname)
for name in valid_cat:
srcname = os.path.join(train_cat_dir, name)
dstname = os.path.join(valid_cat_dir, name)
shutil.move(srcname,dstname)
#shutil.move(srcfile,dstfile) #移动文件