-
大小: 12KB文件类型: .py金币: 1下载: 0 次发布日期: 2021-05-18
- 语言: Python
- 标签: TensorFlow 人脸识别
资源简介
TensorFlow实现人脸识别(3)--------对人脸样本进行训练,保存人脸识别模型
具体解释参考http://blog.csdn.net/yunge812/article/details/79447179
代码片段和文件信息
#-*- coding:UTF-8 -*-
import random
import os
import numpy as np
from sklearn.cross_validation import train_test_split
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense Dropout Activation Flatten
from keras.layers import Convolution2D MaxPooling2D
from keras.optimizers import SGD
from keras.utils import np_utils
from keras.models import load_model
from keras import backend as K
import cv2
from imgProcess import load_dataset resize_imageIMAGE_SIZE #调用两个函数和一个宏定义
class Dataset:
def __init__(selfpath_name):
self.train_img = None
self.train_labels = None
self.valid_img = None
self.valid_labels = None
self.test_img = None
self.test_labels = None
self.path_name = path_name
self.input_shape = None
def loadAllData(selfpath_name):
positive_data_imagespositive_data_labels=load_dataset(path_name‘traindata‘)
negative_data_imagesnegative_data_labels=load_dataset(path_name‘testdata‘)
images =np.concatenate((positive_data_images negative_data_images) axis=0) #数组拼接
labels=np.concatenate((positive_data_labels negative_data_labels) axis=0)
return imageslabels
# 加载数据集并按照交叉验证的原则划分数据集并进行相关预处理工作
def load(selfimg_rows=IMAGE_SIZEimg_cols=IMAGE_SIZEimg_channels=3nb_classes=2):
imageslabels = self.loadAllData(self.path_name) #images为四维数组,尺寸为(图片数量总(包括test+train)*IMAGE_SIZE*IMAGE_SIZE*3)
#随机划分训练集和验证集
train_imagesvalid_imagestrain_labelsvalid_labels = train_test_split(images labels test_size = 0.3random_state = random.randint(0100))
_ test_images_ test_labels = train_test_split(images labels test_size = 0.3random_state = random.randint(0100))
# 当前的维度顺序如果为‘th‘,则输入图片数据时的顺序为:channelsrowscols,否则:rowscolschannels
# 这部分代码就是根据keras库要求的维度顺序重组训练数据集
if K.image_dim_ordering() == ‘th‘: #theano的格式
train_images = train_images.reshape(train_images.shape[0] img_channels img_rows img_cols)
valid_images = valid_images.reshape(valid_images.shape[0] img_channels img_rows img_cols)
test_images = test_images.reshape( test_images.shape[0] img_channels img_rows img_cols)
self.input_shape = (img_channels img_rows img_cols)
else: # tensorflow格式
train_images = train_images.reshape(train_images.shape[0] img_rows img_cols img_channels)
valid_images = valid_images.reshape(valid_images.shape[0] img_rows img_cols img_channels)
test_images = test_images.reshape( test_images.shape[0] img_rows img_cols img_channels)
self.input_shape = (img_rows img_cols img_channels)
# 输出训练集、验证集、测试集的数量
print(train_images.shape[0] ‘train samples‘
相关资源
- Python-手势识别使用在TensorFlow中卷积神
- Python+Tensorflow+CNN实现车牌识别的
- 基于TensorFlow实现的闲聊机器人
- CBAM_MNIST.py
- TensorFlow 实现 Yolo
- 基于tensorflow的遥感影像分类
- 安装步骤。提取码也在里面
- 神经网络模型python模板
- autoencoder自编码器tensorflow代码
- CNN卷积神经网络TensorFlow代码
- 百度人脸识别-人脸对比
- Python+OpenCv实现AI人脸识别身份认证系
- Tensorflow笔记-中国大学全部讲义源代码
- 人脸识别UI Pythone+pyq5+opencv 多线程模式
- python调用opencv实现人脸识别的简单D
- 基于tensorflow的二分类的python实现注释
- tensorflow的ckpt文件转pb模型文件
- tensorflow-C3D-ucf101网络
- lstm_tensorflow
- 《TensorFlow2深度学习》
- Drowsiness_Detection
- TensorFlow Python API documentation.pdf
- Python-使用最新版本的tensorflow实现se
- BP神经网络及代码分析(python+tensorf
- Python-用TensorFlow实现神经网络实体关系
- python3.7+dlib19.17人脸识别库
- 莫烦全部代码Reinforcement-learning-with-
- 基于OpenCV的人脸识别-python3.zip
- Python-基于TensorFlow和BERT的管道式实体
- Tensorflow gpu_accelerate
评论
共有 条评论