def get_mixs(name1, name2, points=46): img1 = align(name1) img2 = align(name2) z1 = encode(img1) z2 = encode(img2) imgs, _ = mix_range(z1, z2, points) return imgs
def encode(input_path): img = Image.open(input_path) img = align_face.align(input_path) img = np.reshape(img, [1,256,256,3]) t = time.time() eps = model.encode(img) print("Encoding latency {} sec/img".format(time.time() - t)) return eps
def get_encodings(model, image, get_box=False): face, box = af.align(image) emb = [] if len(face) > 1: for f in face: f = cv2.resize(f, dsize=(96, 96), interpolation=cv2.INTER_CUBIC) #f = f[...,::-1] f = np.array( [np.around(np.transpose(f, [2, 0, 1]) / 255.0, decimals=12)]) emb.append(model.predict_on_batch(f)) else: face = cv2.resize(face[0], dsize=(96, 96), interpolation=cv2.INTER_CUBIC) face = np.array( [np.around(np.transpose(face, [2, 0, 1]) / 255.0, decimals=12)]) emb.append(model.predict_on_batch(face)) if get_box: return emb, box return emb
def align_image(input_path, output_path): img = align_face.align(input_path) img = Image.fromarray(img).convert('RGB') img.save(output_path)
def get_manipulations(name, typ, points=46, scale=1.0): img = align(name) z = encode(img) imgs, _ = manipulate_range(z, typ, points, scale) return imgs