from Config import Config
from FaceDetection.MTCNNDetect import MTCNNDetect
import cv2
import tensorflow as tf
import keras
from keras import backend as K
from keras.layers import Input, Lambda, Dense, Dropout, Convolution2D, MaxPooling2D, Flatten, Concatenate, concatenate
from keras.models import Model
face_detect = MTCNNDetect(model_path=Config.MTCNN_MODEL)
from FaceRecognition.TensorflowGraph import FaceRecGraph
from src.FaceAlignment import AlignCustom
from FaceRecognition.FaceFeature import FaceFeature
FRGraph = FaceRecGraph()
aligner = AlignCustom()
extract_feature = FaceFeature(FRGraph)
img1 = cv2.imread('data5/s1/8.jpg')
rects, landmarks = face_detect.detect_face(img1, Config.MINIMUM_FACE_SIZE_FOR_REGISTRATION)
# print("length of rect", len(rects))
if len(rects) == 1:
for i, rect in enumerate(rects):
if rect != []:
aligned_face = aligner.align(160, img1, landmarks[i])
vector1 = np.squeeze(extract_feature.get_features(np.expand_dims(aligned_face, axis=0)), axis=0)
img2 = cv2.imread('data5/s1/10.jpg')
rects, landmarks = face_detect.detect_face(img2, Config.MINIMUM_FACE_SIZE_FOR_REGISTRATION)
# print("length of rect", len(rects))
if len(rects) == 1:
for i, rect in enumerate(rects):
if rect != []:
aligned_face = aligner.align(160, img2, landmarks[i])
vector2 = np.squeeze(extract_feature.get_features(np.expand_dims(aligned_face, axis=0)), axis=0)
vec1 = vector1.reshape(1, 128)
vec2 = vector2.reshape(1, 128)
data_tensor1 = tf.convert_to_tensor(vec1)
data_tensor2 = tf.convert_to_tensor(vec2)
input_dim = (224,224,3)
img_a = tf.keras.layers.Input(shape=input_dim)
img_b = tf.keras.layers.Input(shape=input_dim)
L1_layer = Lambda(lambda tensors: tf.abs(tensors[0] - tensors[1]))
L1_distance = L1_layer([data_tensor1, data_tensor2])
prediction = Dense(1, activation='sigmoid')(L1_distance)
siamese_net = Model(inputs=[img_a, img_b], outputs=prediction)
siamese_net.summary()
我正在尝试在现有FaceNet模型的基础上创建一个暹罗网络。 我正在使用预先训练的模型创建特征向量。
Vector1和Vector2是我正在馈送到我的暹罗网络的特征向量。 取得它们之间的绝对差异并将其馈送到密集层。
定义模型时出现以下错误:
*回溯(最近通话最近):
中的文件“ C:/ Users / techolution / Desktop / Facenet / Create Vectors / Siamese Network-Test.py”,第104行siamese_net = Model(inputs=[img_a, img_b], outputs=prediction)
文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ legacy \ interfaces.py”,包装中的第91行 返回func(* args,** kwargs)
第94行中的文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ engine \ network.py”, init self._init_graph_network(* args,** kwargs)
_init_graph_network中第241行的文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ engine \ network.py” self.inputs,self.outputs)
_map_graph_network中的第1434行,文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ engine \ network.py” tensor_index = tensor_index)
build_map中的文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ engine \ network.py”,第1421行 node_index,张量索引)
build_map中的文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ engine \ network.py”,第1421行 node_index,张量索引)
在build_map中的文件“ C:\ Users \ techolution \ Desktop \ Facenet \ Create Vectors \ venv \ lib \ site-packages \ keras \ engine \ network.py”,行1393 节点= layer._inbound_nodes [node_index]
AttributeError:“ NoneType”对象没有属性“ _inbound_nodes” *