一
在进行训练之前,我们首先需要对图片进行修改,使其长宽相等。
新建 训练模型.py
import tensorflow as tf
import cv2
import numpy as np
import os
import random
import sys
from sklearn.model_selection import train_test_split
my_faces_path = '/home/dong/PycharmProjects/untitled/人脸识别/data/me'
other_faces_path = '/home/dong/PycharmProjects/untitled/人脸识别/data/zhang'
size = 64
imgs = []
labs = []
def getPaddingSize(img):
h, w, _ = img.shape
top, bottom, left, right = (0, 0, 0, 0)
longest = max(h, w)
if w < longest:
tmp = longest - w # 相当于 h-w
# //表示整除符号
left = tmp // 2
right = tmp - left
elif h < longest:
tmp = longest - h
top = tmp // 2
bottom = tmp - top
else:
pass
return top, bottom, left, right
修改之前图片
修改之后的图片(长宽相等)
二
从文件中读取照片
继续添加代码
def readData(path, h=size, w=size):
for filename in os.listdir(path):
if filename.endswith('.jpg'):