mirror of
https://github.com/serengil/deepface.git
synced 2025-06-05 19:15:23 +00:00
bug in how.py sorted
This commit is contained in:
parent
6c5c3511f4
commit
9fed010762
@ -1,30 +1,28 @@
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from deepface.basemodels import VGGFace
|
from deepface import DeepFace
|
||||||
from deepface.commons import functions
|
from deepface.commons import functions
|
||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# build face recognition model
|
# build face recognition model
|
||||||
|
|
||||||
model = VGGFace.loadModel()
|
model_name = "VGG-Face"
|
||||||
|
|
||||||
try:
|
model = DeepFace.build_model(model_name=model_name)
|
||||||
input_shape = model.layers[0].input_shape[1:3]
|
|
||||||
except: # issue 470
|
|
||||||
input_shape = model.layers[0].input_shape[0][1:3]
|
|
||||||
|
|
||||||
print("model input shape: ", model.layers[0].input_shape[1:])
|
target_size = functions.find_target_size(model_name)
|
||||||
print("model output shape: ", model.layers[-1].input_shape[-1])
|
|
||||||
|
print(f"target_size: {target_size}")
|
||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# load images and find embeddings
|
# load images and find embeddings
|
||||||
|
|
||||||
# img1 = functions.detectFace("dataset/img1.jpg", input_shape)
|
img1 = DeepFace.extract_faces(img_path="dataset/img1.jpg", target_size=target_size)[0]["face"]
|
||||||
img1 = functions.preprocess_face("dataset/img1.jpg", input_shape)
|
img1 = np.expand_dims(img1, axis=0) # to (1, 224, 224, 3)
|
||||||
img1_representation = model.predict(img1)[0, :]
|
img1_representation = model.predict(img1)[0, :]
|
||||||
|
|
||||||
# img2 = functions.detectFace("dataset/img3.jpg", input_shape)
|
img2 = DeepFace.extract_faces(img_path="dataset/img3.jpg", target_size=target_size)[0]["face"]
|
||||||
img2 = functions.preprocess_face("dataset/img3.jpg", input_shape)
|
img2 = np.expand_dims(img2, axis=0)
|
||||||
img2_representation = model.predict(img2)[0, :]
|
img2_representation = model.predict(img2)[0, :]
|
||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
@ -58,7 +56,7 @@ distance_graph = np.array(distance_graph)
|
|||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
|
|
||||||
ax1 = fig.add_subplot(3, 2, 1)
|
ax1 = fig.add_subplot(3, 2, 1)
|
||||||
plt.imshow(img1[0][:, :, ::-1])
|
plt.imshow(img1[0])
|
||||||
plt.axis("off")
|
plt.axis("off")
|
||||||
|
|
||||||
ax2 = fig.add_subplot(3, 2, 2)
|
ax2 = fig.add_subplot(3, 2, 2)
|
||||||
@ -66,7 +64,7 @@ im = plt.imshow(img1_graph, interpolation="nearest", cmap=plt.cm.ocean)
|
|||||||
plt.colorbar()
|
plt.colorbar()
|
||||||
|
|
||||||
ax3 = fig.add_subplot(3, 2, 3)
|
ax3 = fig.add_subplot(3, 2, 3)
|
||||||
plt.imshow(img2[0][:, :, ::-1])
|
plt.imshow(img2[0])
|
||||||
plt.axis("off")
|
plt.axis("off")
|
||||||
|
|
||||||
ax4 = fig.add_subplot(3, 2, 4)
|
ax4 = fig.add_subplot(3, 2, 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user