<jupyter_start><jupyter_text>人脸识别程序- 该项目用于验证人脸识别的可用性- 依赖环境： tf20py36- 验证流程：  - 数据人脸库  - 对的图片进行人脸识别  - 给出识别结果<jupyter_code>import tensorflow
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import os
from os import path
def show_image(img_path, name=''):
    img = mpimg.imread(img_path)
    plt.figure()
    plt.imshow(img)
    plt.title(name)
    
def show_images(images):
    for name, img_path in images:
        show_image(img_path, name)
cd '~/jianzhou/facenet'
def load_db_images(DB_IMAGES_PATH):
    faces = [x for x in os.listdir(DB_IMAGES_PATH) if path.isdir(path.join(DB_IMAGES_PATH, x))]
    print('load faces: %s' % faces)

    # {face_dir: name, [img1, img2]}
    db_images = {}
    for face in faces:
        face_dir = path.join(DB_IMAGES_PATH, face)
        with open(path.join(face_dir, 'name.txt')) as r:
            name = r.read().strip()
        face_images = [path.join(face_dir, x) for x in os.listdir(face_dir) if x.endswith('.jpg')]
        db_images[face_dir] = name, face_images
    print('load db_images:')
    for face_dir in db_images:
        print(face_dir)
        name, images = db_images[face_dir]
        print('name: %s' % name + '\t'.join(images))
    return db_images

DB_IMAGES_PATH = './data/images'
db_images = load_db_images(DB_IMAGES_PATH)

for face_dir in db_images:
    name, images = db_images[face_dir]
    for img in images:       
        show_image(img, img)
test_img = './data/test_images/zy.jpg'
show_image(test_img)
#test_img = "./data/images/jz/jz2.jpg"
#show_image(test_img)
!source activate tf12py27 \
    && python src/recognize.py --gpu_memory_fraction 0.8 model/20180402-114759 \
    {test_img}
show_image("./data/images/zy/zy1.jpg")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12571103526734925, 'fraction_numerical': 0.015927189988623434, 'mean_word_length': 3.4872448979591835, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '507794', 'license': 'MIT', 'n_tokens_mistral': 727, 'n_tokens_neox': 725, 'n_words': 141, 'path': 'facenet.ipynb', 'repo_name': 'jojolin/facenet', 'size': '1758'}