Skip to content

Instantly share code, notes, and snippets.

@haoxi911
Created March 15, 2018 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haoxi911/c75b65a421620b7f8cb0523c3cd069f1 to your computer and use it in GitHub Desktop.
Save haoxi911/c75b65a421620b7f8cb0523c3cd069f1 to your computer and use it in GitHub Desktop.
Remove invalid images from Oxford IIIT Pet dataset
from PIL import Image
import os
path = os.getcwd()
for folder in os.listdir(path):
if os.path.isdir(os.path.join(path, folder)):
for file in os.listdir(os.path.join(path, folder)):
extension = file.split('.')[-1]
if extension == 'jpg':
fileLoc = os.path.join(path, folder)+'/'+file
img = Image.open(fileLoc)
if img.mode != 'RGB':
os.remove(fileLoc)
@haoxi911
Copy link
Author

Egyptian_Mau_167.jpg, P
Egyptian_Mau_191.jpg, P
Egyptian_Mau_177.jpg, P
Egyptian_Mau_139.jpg, P
Egyptian_Mau_14.jpg, RGBA
Egyptian_Mau_129.jpg, L
Egyptian_Mau_186.jpg, RGBA
Egyptian_Mau_145.jpg, P
staffordshire_bull_terrier_2.jpg, L
staffordshire_bull_terrier_22.jpg, L
Abyssinian_5.jpg, RGBA
Abyssinian_34.jpg, P

@mayujie
Copy link

mayujie commented Dec 14, 2021

need to remove these two as well:
chihuahua_121
beagle_116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment