-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for multiple faces #566
Changes from all commits
397c84f
53fc65c
da3498c
0a144ec
f122006
eb140e5
d7c6226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ models/inswapper_128.onnx | |
models/GFPGANv1.4.pth | ||
*.onnx | ||
models/DMDNet.pth | ||
faceswap/ | ||
.vscode/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import numpy as np | ||
from sklearn.cluster import KMeans | ||
from sklearn.metrics import silhouette_score | ||
from typing import Any | ||
|
||
|
||
def find_cluster_centroids(embeddings, max_k=10) -> Any: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (performance): Optimize the cluster centroid finding algorithm The current implementation runs K-means for every K up to max_k, which could be inefficient for large datasets. Consider using a more efficient method for determining the optimal number of clusters, such as the elbow method or silhouette analysis, without running K-means for every K.
|
||
inertia = [] | ||
cluster_centroids = [] | ||
K = range(1, max_k+1) | ||
|
||
for k in K: | ||
kmeans = KMeans(n_clusters=k, random_state=0) | ||
kmeans.fit(embeddings) | ||
inertia.append(kmeans.inertia_) | ||
cluster_centroids.append({"k": k, "centroids": kmeans.cluster_centers_}) | ||
|
||
diffs = [inertia[i] - inertia[i+1] for i in range(len(inertia)-1)] | ||
optimal_centroids = cluster_centroids[diffs.index(max(diffs)) + 1]['centroids'] | ||
|
||
return optimal_centroids | ||
|
||
def find_closest_centroid(centroids: list, normed_face_embedding) -> list: | ||
try: | ||
centroids = np.array(centroids) | ||
normed_face_embedding = np.array(normed_face_embedding) | ||
similarities = np.dot(centroids, normed_face_embedding) | ||
closest_centroid_index = np.argmax(similarities) | ||
|
||
return closest_centroid_index, centroids[closest_centroid_index] | ||
except ValueError: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (documentation): Consider clarifying the description of the --map-faces option
The current description 'map source target faces' is a bit ambiguous. Consider rephrasing to 'map source to target faces' for improved clarity while maintaining brevity.