-
Notifications
You must be signed in to change notification settings - Fork 0
/
chek.py
48 lines (42 loc) · 1.31 KB
/
chek.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
"""
Delete truncated images from FaceShifter and NeuralTextures.
"""
from PIL import Image
import os
from os.path import join
import shutil
import argparse
import subprocess
from tqdm import tqdm
DATASET_PATHS = {
# for FaceForencics++
'FaceShifter': 'FakeImgDatasets/FaceShifter',
'NeuralTextures': 'FakeImgDatasets/NeuralTextures'
}
def delete_truncated_images(dataset,splt):
data_path = 'DataSet/train_test_images_cropped'
path = join(data_path, DATASET_PATHS[dataset],splt)
all_imgs = os.listdir(path)
for img in tqdm(all_imgs):
imgpath = join(path,img)
try:
img = Image.open(imgpath)
img.load()
except OSError as error:
os.remove(imgpath)
if __name__ == '__main__':
p = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
p.add_argument('--dataset', '-d', type=str,
choices=list(DATASET_PATHS.keys()) + ['all'],
default='all')
p.add_argument('--splt', type=str)
# splt has value train or test or valid
args = p.parse_args()
if args.dataset == 'all':
for dataset in DATASET_PATHS.keys():
args.dataset = dataset
delete_truncated_images(**vars(args))
else:
delete_truncated_images(**vars(args))