Esempio n. 1
0
import sys, shutil, os
import random
import string
from file_utils import files_with_ext, create_dir
from tqdm import tqdm
import multiprocessing
mypath = sys.argv[1]

#jpegfiles = [os.path.join(mypath, s.strip()+'.jpg') for s in open(source_text,'r').readlines()]

copyfiles = files_with_ext(mypath, '.jpg')  #jpegfiles
#jpegfiles = files_with_ext(mypath, '.jpg') # get all the files with extentsion

from PIL import Image


def checkImage(f):
    try:
        im = Image.open(f)
        s = im.convert('RGB')
    except Exception as ex:
        os.remove(f)


import cv2
jobs = []
for f in tqdm(copyfiles):
    checkImage(f)
#    p = multiprocessing.Process(target=checkImage, args=(f,))
#    jobs.append(p)
#    p.start()
Esempio n. 2
0
import shutil, os
from file_utils import files_with_ext, create_dir
import sys
from random import shuffle

xmls = files_with_ext(sys.argv[1], '.xml')

imagesPath = sys.argv[2]
#print(xmls[0])
xmls = [xml.split('/')[-1].split('.xml')[0] for xml in xmls]

xmls = [
    xml for xml in xmls
    if os.path.exists(os.path.join(imagesPath, xml + '.jpg'))
]
shuffle(xmls)

trainingFraction = 0.90
valFraction = 0.05
testFraction = 0.05

train = []
val = []
test = []

trainLen = int(trainingFraction * len(xmls))
valLen = int(valFraction * len(xmls))
train.extend(xmls[:trainLen])
val.extend(xmls[trainLen:trainLen + valLen])
test.extend(xmls[trainLen + valLen:])
Esempio n. 3
0
import multiprocessing


def random_str(N):
    # generate random string of length N
    return ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(N))


mypath = sys.argv[1]
newpath = sys.argv[2]

create_dir(newpath)

jpegfiles = files_with_ext(mypath, '.jpg')  # get all the files with extentsion


def flip_image(jpeg):
    try:
        img = Image.open(jpeg).transpose(Image.FLIP_LEFT_RIGHT)
        img.save(os.path.dirname(jpeg) + '/vflip_' + os.path.basename(jpeg))
    except Exception as ex:
        print(ex)


if __name__ == '__main__':

    jobs = []
    print("processing:")
    for idx, jpeg in enumerate(jpegfiles):
Esempio n. 4
0
import sys, shutil, os
import random
import string
from file_utils import files_with_ext, create_dir
import pickle

mypath = sys.argv[1]

ages = pickle.load(open(sys.argv[2], "rb"))

#source_text = sys.argv[3]

jpegfiles = files_with_ext(
    mypath, '.jpg'
)  #[os.path.join(mypath, s.strip()+'.jpg') for s in open(source_text,'r').readlines()]

copyfiles = jpegfiles
#jpegfiles = files_with_ext(mypath, '.jpg') # get all the files with extentsion

remove = []
for f in copyfiles:
    #    dest = os.path.join(newpath, os.path.basename(f))
    if os.path.basename(f) not in ages:
        #        remove.append(f)
        os.remove(f)
#       shutil.copy(f, dest)
print(len(remove))