1、openpose 参考代码
code link:https://github.com/YangZeyu95/unofficial-implement-of-openpose
inference : https://www.aiuai.cn/aifarm292.html
2、人脸识别 (可参考上一篇文章)
参考 https://github.com/ageitgey/face_recognition
3、代码结构如下
4、主要代码 附上
rgb_face_pose.py
import argparse
import tensorflow as tf
import sys
import time
import logging
import cv2
import numpy as np
from tensorflow.contrib import slim
import vgg
from cpm import PafNet
import common
from tensblur.smoother import Smoother
from estimator import PoseEstimator, TfPoseEstimator
import face_recognition
from read_data import read_name_list
from read_data import read_file
all_encoding, lable_list, counter = read_file('./dataset')
name_list = read_name_list('./dataset')
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True
logger = logging.getLogger('run')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Training codes for Openpose using Tensorflow')
parser.add_argument('--checkpoint_path', type=str, default='checkpoints/train/2018-12-13-16-56-49/')
parser.add_argument('--backbone_net_ckpt_path', type=str, default='checkpoints/vgg/vgg_19.ckpt')
parser.add_argument('--image', type=str, default=None)
# parser.add_argument('--run_model', type=str, default='img')
parser.add_argument('--video', type=str, default=None)
parser.add_argument('--train_vgg', type=bool, default=True)
parser.add_argument('--use_bn', type=bool, default=False)
parser.add_argument('--save_video', type=str, default='result/our.mp4')
args = parser.parse_args()
checkpoint_path = args.checkpoint_path
logger.info('checkpoint_path: ' + checkpoint_path)
with tf.name_scope('inputs'):
raw_img = tf.placeholder(tf.float32, shape=[None, None, None, 3])
img_size = tf.placeholder(dtype=tf.int32, shape=(2,), name='original_image_size')
img_normalized = raw_img / 255 - 0.5
# define vgg19
with slim.arg_scope(vgg.vgg_arg_scope()):
vgg_outputs, end_points = vgg.vgg_19(img_normalized)
# get net graph
logger.info('initializing model...')
net = PafNet(inputs_x=vgg_outputs, use_bn=args.use_bn)
hm_pre, cpm_pre, added_layers_out = net.gen_net()
hm_up = tf.image.resize_area(hm_pre[5], img_size)
cpm_up = tf.image.resize_area(cpm_pre[5], img_size)
# hm_up = hm_pre[5]
# cpm_up = cpm_pre[5]
smoother = Smoother({'data': hm_up}, 25, 3.0)
gaussian_heatMat = smoother.get_output()
max_pooled_in_tensor = tf.nn.pool(gaussian_heatMat, window_shape=(3, 3), pooling_type='MAX', padding='SAME')
tensor_peaks = tf.where(tf.equal(gaussian_heatMat, max_pooled_in_tensor), gaussian_heatMat,
tf.zeros_like(gaussian_heatMat))
logger.info('initialize saver...')
# trainable_var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='openpose_layers')
# trainable_var_list = []
trainable_var_list = tf.get_colle