-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclean_dataset.py
38 lines (34 loc) · 904 Bytes
/
clean_dataset.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
from glob import glob
import os
from PIL import Image
from skimage import io, color
from tqdm import tqdm
from dotenv import load_dotenv
load_dotenv()
files = glob(f"{os.getenv('FURNITURE_DATASET_DOWNLOAD_DIRECTORY')}/*/*/*")
with tqdm(total=len(files)) as pbar:
for filename in files:
try:
image = Image.open(filename)
image.verify()
mode = image.mode
if mode == 'RGB':
im = io.imread(filename)
io.imsave(filename, im)
elif mode == 'RGBA':
im = io.imread(filename)
im = color.rgba2rgb(im)
io.imsave(filename, im)
elif mode == 'L':
im = io.imread(filename)
im = color.gray2rgb(im)
io.imsave(filename, im)
elif mode == 'P':
os.remove(filename)
elif mode == 'CMYK':
os.remove(filename)
else:
pass
except:
os.remove(filename)
pbar.update(1)