• 大小: 70.58MB
    文件类型: .zip
    金币: 2
    下载: 2 次
    发布日期: 2023-01-15
  • 语言: Python
  • 标签:

资源简介

TensorFlow实现的人脸性别/年龄识别

资源截图

代码片段和文件信息

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License Version 2.0 (the “License“);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing software
# distributed under the License is distributed on an “AS IS“ BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

“““Converts MNIST data to TFRecords file format with Example protos.“““
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import os
import sys
from datetime import datetime
from scipy.io import loadmat

import tensorflow as tf

from imutils.face_utils import FaceAligner
from imutils.face_utils import rect_to_bb
import argparse
import imutils
import dlib
import cv2
import pandas as pd
import numpy as np
import skimage.io as io
from tqdm import tqdm

from sklearn.model_selection import train_test_split
FLAGS = None

def _int64_feature(value):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))


def _bytes_feature(value):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))


def convert_to(data_set name):
    “““Converts a dataset to tfrecords.“““
    file_name = data_set.file_name
    genders = data_set.gender
    ages = data_set.age
    face_score = data_set.score
    second_face_score = data_set.second_score
    num_examples = data_set.shape[0]
    base_dir = “data/imdb_crop“

    # initialize dlib‘s face detector (HOG-based) and then create
    # the facial landmark predictor and the face aligner
    shape_predictor = ‘shape_predictor_68_face_landmarks.dat‘
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(shape_predictor)
    fa = FaceAligner(predictor desiredFaceWidth=64)

    error=0
    total=0
    # if images.shape[0] != num_examples:
    #     raise ValueError(‘Images size %d does not match label size %d.‘ %
    #                      (images.shape[0] num_examples))
    # rows = images.shape[1]
    # cols = images.shape[2]
    # depth = images.shape[3]

    filename = os.path.join(name + ‘.tfrecords‘)
    print(‘Writing‘ filename)
    with tf.python_io.TFRecordWriter(filename) as writer:
        for index in tqdm(range(num_examples)):
            if face_score[index] < 0.75:
                continue
            # if (~np.isnan(second_face_score[index])) and second_face_score[index] > 0.0:
            #     continue
            if ~(0 <= ages[index] <= 100):
                continue

            if np.isnan(genders[index]):
                continue

            try:
                # image_raw = io.imread(o

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-06 12:15  Age-Gender-Estimate-TF-master\
     文件        1063  2018-03-06 12:15  Age-Gender-Estimate-TF-master\LICENSE
     文件        5920  2018-03-06 12:15  Age-Gender-Estimate-TF-master\README.md
     文件        6930  2018-03-06 12:15  Age-Gender-Estimate-TF-master\convert_to_records.py
     文件       10643  2018-03-06 12:15  Age-Gender-Estimate-TF-master\convert_to_records_multiCPU.py
     文件        4926  2018-03-06 12:15  Age-Gender-Estimate-TF-master\demo.py
     目录           0  2018-03-06 12:15  Age-Gender-Estimate-TF-master\demo\
     文件     1119763  2018-03-06 12:15  Age-Gender-Estimate-TF-master\demo\demo.gif
     文件      218316  2018-03-06 12:15  Age-Gender-Estimate-TF-master\demo\demo.jpg
     文件       58018  2018-03-06 12:15  Age-Gender-Estimate-TF-master\demo\demo1.jpg
     文件       29944  2018-03-06 12:15  Age-Gender-Estimate-TF-master\demo\demo2.jpg
     文件        4903  2018-03-06 12:15  Age-Gender-Estimate-TF-master\eval.py
     文件       12956  2018-03-06 12:15  Age-Gender-Estimate-TF-master\inception_resnet_v1.py
     文件        9063  2018-03-06 12:15  Age-Gender-Estimate-TF-master\inception_resnet_v1.pyc
     文件        5527  2018-03-06 12:15  Age-Gender-Estimate-TF-master\inspect_checkpoint.py
     文件      370329  2018-03-06 12:15  Age-Gender-Estimate-TF-master\libboost_python.so.1.65.1
     文件        1316  2018-03-06 12:15  Age-Gender-Estimate-TF-master\model_transfer.py
     目录           0  2018-03-06 12:15  Age-Gender-Estimate-TF-master\models\
     文件           0  2018-03-06 12:15  Age-Gender-Estimate-TF-master\models\Put pretrained model here
     文件        5553  2018-03-06 12:15  Age-Gender-Estimate-TF-master\print_parameter.ipynb
     文件       47396  2018-03-06 12:15  Age-Gender-Estimate-TF-master\read_images.ipynb
     文件       19029  2018-03-06 12:15  Age-Gender-Estimate-TF-master\resnet_model.py
     文件        1658  2018-03-06 12:15  Age-Gender-Estimate-TF-master\saved_model.py
     文件    99693937  2018-03-06 12:15  Age-Gender-Estimate-TF-master\shape_predictor_68_face_landmarks.dat
     文件        6492  2018-03-06 12:15  Age-Gender-Estimate-TF-master\test.py
     文件        7643  2018-03-06 12:15  Age-Gender-Estimate-TF-master\train.py
     目录           0  2018-03-06 12:15  Age-Gender-Estimate-TF-master\train_log\
     文件      107935  2018-03-06 12:15  Age-Gender-Estimate-TF-master\train_log\train_log.jpg
     文件        4638  2018-03-06 12:15  Age-Gender-Estimate-TF-master\utils.py

评论

共有 条评论