In [24]:
import json
import yaml
faces_dict = dict()
lefte_dict = dict()
righte_dict = dict()
# collect dict values into lists
faces_l, left_l, right_l = [], [], []
with open('data/faces_bboxes.txt') as faces_file:
# faces = json.load(faces_file)
faces = yaml.safe_load(faces_file)
for f in faces['faces']:
for k, v in f.items():
faces_dict[k] = v
faces_l.append(v)
#load eye bounding boxes
with open('data/left_eyes_bboxes.txt') as lefte_file:
# faces = json.load(faces_file)
left_eye = yaml.safe_load(lefte_file)
for f in left_eye['left_eyes']:
for k, v in f.items():
lefte_dict[k] = v
left_l.append(v)
#load right eye bounding boxes
with open('data/right_eyes_bboxes.txt') as righte_file:
# faces = json.load(faces_file)
right_eye = yaml.safe_load(righte_file)
for f in right_eye['right_eyes']:
for k, v in f.items():
righte_dict[k] = v
right_l.append(v)
faceAndEyesDict = [faces_dict, lefte_dict, righte_dict]
for k in [faces_l, left_l, right_l]:
print(len(k))
In [19]:
face_d = faceAndEyesDict[0]
left_d = faceAndEyesDict[1]
right_d = faceAndEyesDict[2]
face_1 = (face_d['face_259_image.jpg'])
face_2 = face_d['face_258_image.jpg']
faces = [face_1 , face_2]
# for k, v in face_d.items():
# faces.append(v)
import numpy as np
print(faces)
faces_np = np.array(faces)
print(faces_np.shape)
# import torch
# faces_t = torch.stack(faces, 0)
# print(faces_t)
list(faces_l, left_l, right_l)
In [31]:
from PIL import Image
from os import listdir
def loadImages( path):
# return array of images
imagesList = listdir(path)
loadedImages, faces_bbox = [], []
#load serially to ensure labels match
for image in imagesList:
img = Image.open(path + image)
loadedImages.append(img)
return loadedImages
true = loadImages("../manikin/raw/face_images/")
print(len(true))
In [78]:
import numpy as np
left_right = np.concatenate((left_l, right_l), axis=1)
#split faces list of lists to ease numpy concatenation
faces_top, faces_bot = [], []
#arrange faces_l into a 1x8 array
for i in range(len(faces_l)):
faces_top.append(faces_l[i][0])
faces_bot.append(faces_l[i][1])
labels = [1] * len(faces_top)
# print(labels.shape)
# print(np.array(faces_top).shape, np.array(faces_bot).shape)
# First 4 cols represent face boxes, last four cols are left and right eye centers
face_left_right = np.concatenate((faces_top, faces_bot, left_right), axis=1)
print(face_left_right.shape)