def get_train_non_face_data(k=12, write_to_disk=False): ''' cut non-faces (negative examples) by pick random patch (if in not overlaped with any face bbox from all images in dataset return X - features y - labels cnt - count of examples ''' X = [] root = 'F:\\Datasets\\image_data_sets\\non-faces' pattern = "*.jpg" for path, subdirs, files in os.walk(root): for iname in files: if fnmatch(iname, pattern): ipath = os.path.join(path, iname) img = fr.get_frame(ipath) print('non_face:', ipath) if img == None: continue H, W = img.shape[:2] non_face = shuffle(fr.split_frame(img, wshape=(k, k)), random_state=42)[:25] for e in non_face: X.append(fr.frame_to_vect(e)) X = sp.array(X) y = sp.zeros(len(X)) return X, y
def get_train_non_face_data(k = 12,write_to_disk = False): ''' cut non-faces (negative examples) by pick random patch (if in not overlaped with any face bbox from all images in dataset return X - features y - labels cnt - count of examples ''' X = [] root = 'F:\\Datasets\\image_data_sets\\non-faces' pattern = "*.jpg" for path, subdirs, files in os.walk(root): for iname in files: if fnmatch(iname, pattern): ipath = os.path.join(path, iname) img = fr.get_frame(ipath) print('non_face:',ipath) if img == None: continue H,W = img.shape[:2] non_face = shuffle(fr.split_frame(img,wshape=(k,k)),random_state=42)[:25] for e in non_face: X.append(fr.frame_to_vect(e)) X = sp.array(X) y = sp.zeros(len(X)) return X,y
def get_train_non_face_data(k=12, patch_per_img=25, on_drive=False): ''' cut non-faces (negative examples) by pick random patch (if in not overlaped with any face bbox from all images in dataset return X - features y - labels cnt - count of examples ''' X = [] def yield_gen(data): data = shuffle(data)[:patch_per_img] for e in data: yield e root = 'F:\\Datasets\\image_data_sets\\non-faces' pattern = "*.jpg" c = 0 for path, subdirs, files in os.walk(root): for iname in files: if fnmatch(iname, pattern): ipath = os.path.join(path, iname) img = fr.get_frame(ipath) print('non_face:', ipath) if img == None: continue H, W = img.shape[:2] if not on_drive: for e in yield_gen(fr.split_frame(img, wshape=(k, k))): X.append(fr.frame_to_vect(e)) else: for e in yield_gen( fr.split_frame(img, wshape=(util.k_max, util.k_max))): fr.write_frame( 'F:\\train_data\\neg\\' + str(c) + '_' 'nonface' + '_neg', e) c += 1 X = sp.array(X) y = sp.zeros(len(X)) return X, y
def get_train_non_face_data(k = 12,patch_per_img = 25,on_drive = False): ''' cut non-faces (negative examples) by pick random patch (if in not overlaped with any face bbox from all images in dataset return X - features y - labels cnt - count of examples ''' X = [] def yield_gen(data): data = shuffle(data)[:patch_per_img] for e in data: yield e root = 'F:\\Datasets\\image_data_sets\\non-faces' pattern = "*.jpg" c = 0 for path, subdirs, files in os.walk(root): for iname in files: if fnmatch(iname, pattern): ipath = os.path.join(path, iname) img = fr.get_frame(ipath) print('non_face:',ipath) if img == None: continue H,W = img.shape[:2] if not on_drive: for e in yield_gen(fr.split_frame(img,wshape=(k,k))): X.append(fr.frame_to_vect(e)) else: for e in yield_gen(fr.split_frame(img,wshape=(util.k_max,util.k_max))): fr.write_frame('F:\\train_data\\neg\\' + str(c) + '_' 'nonface'+'_neg',e) c += 1 X = sp.array(X) y = sp.zeros(len(X)) return X,y