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))


302
302
302

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)


[[[468, 496, 849, 496], [468, 939, 849, 939]], [[497, 521, 884, 521], [497, 931, 884, 931]]]
(2, 2, 4)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-168c9dddae18> in <module>()
     18 # print(faces_t)
     19 
---> 20 list(faces_l, left_l, right_l)

TypeError: list() takes at most 1 argument (3 given)

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))


302

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)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-78-33ab984447da> in <module>()
     15 # print(np.array(faces_top).shape, np.array(faces_bot).shape)
     16 # First 4 cols represent face boxes, last four cols are left and right eye centers
---> 17 face_left_right = np.concatenate((labels, faces_top, faces_bot, left_right), axis=1)
     18 
     19 print(face_left_right.shape)

IndexError: axis 1 out of bounds [0, 1)