-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Fix nopgadget's NewSwap PR #1579
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
Open
ZardashtKaya
wants to merge
4
commits into
hacksider:main
Choose a base branch
from
ZardashtKaya:New_swap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| @echo off | ||
| REM clone_or_update_deep_live_cam.bat - Clone or update Deep-Live-Cam repo in a separate folder and sync to local working folder | ||
| SET REPO_URL=https://github.com/hacksider/Deep-Live-Cam.git | ||
| SET TARGET_DIR=Deep-Live-Cam-remote | ||
| SET LOCAL_DIR=Deep-Live-Cam | ||
|
|
||
| IF EXIST %TARGET_DIR% ( | ||
| echo Updating existing repo in %TARGET_DIR% ... | ||
| cd %TARGET_DIR% | ||
| git pull | ||
| cd .. | ||
| ) ELSE ( | ||
| echo Cloning repo to %TARGET_DIR% ... | ||
| git clone %REPO_URL% %TARGET_DIR% | ||
| ) | ||
|
|
||
| REM Sync updated code to local working folder (excluding .git and models) | ||
| xcopy %TARGET_DIR% %LOCAL_DIR% /E /H /Y /EXCLUDE:exclude.txt | ||
|
|
||
| echo Done. Latest code is in %LOCAL_DIR%. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/zsh | ||
| # clone_or_update_deep_live_cam.sh - Clone or update Deep-Live-Cam repo in a separate folder (macOS/Linux) | ||
| REPO_URL="https://github.com/hacksider/Deep-Live-Cam.git" | ||
| TARGET_DIR="Deep-Live-Cam-remote" | ||
|
|
||
| if [ -d "$TARGET_DIR" ]; then | ||
| echo "Updating existing repo in $TARGET_DIR ..." | ||
| cd "$TARGET_DIR" | ||
| git pull | ||
| cd .. | ||
| else | ||
| echo "Cloning repo to $TARGET_DIR ..." | ||
| git clone "$REPO_URL" "$TARGET_DIR" | ||
| fi | ||
|
|
||
| # Sync updated code to local working folder (excluding .git and models) | ||
| LOCAL_DIR="Deep-Live-Cam" | ||
| rsync -av --exclude='.git' --exclude='models' --exclude='*.pth' --exclude='*.onnx' "$TARGET_DIR"/ "$LOCAL_DIR"/ | ||
|
|
||
| echo "Done. Latest code is in $LOCAL_DIR." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .git | ||
| models | ||
| *.pth | ||
| *.onnx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/bin/bash | ||
| # Deep-Live-Cam macOS Automated Setup | ||
| set -e | ||
|
|
||
| # 1. Ensure Homebrew is installed | ||
| if ! command -v brew &> /dev/null; then | ||
| echo "Homebrew not found. Please install Homebrew first: https://brew.sh/" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # 2. Install Python 3.10 and tkinter | ||
| brew install [email protected] [email protected] | ||
|
|
||
| # 3. Create and activate virtual environment | ||
| PYTHON_BIN=$(brew --prefix [email protected])/bin/python3.10 | ||
| $PYTHON_BIN -m venv venv | ||
| source venv/bin/activate | ||
|
|
||
| # 4. Upgrade pip and install dependencies | ||
| pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
|
|
||
| # 5. Download models if not present | ||
| mkdir -p models | ||
| if [ ! -f models/GFPGANv1.4.pth ]; then | ||
| curl -L -o models/GFPGANv1.4.pth "https://huggingface.co/hacksider/deep-live-cam/resolve/main/GFPGANv1.4.pth" | ||
| fi | ||
| if [ ! -f models/inswapper_128_fp16.onnx ]; then | ||
| curl -L -o models/inswapper_128_fp16.onnx "https://huggingface.co/hacksider/deep-live-cam/resolve/main/inswapper_128_fp16.onnx" | ||
| fi | ||
|
|
||
| # 6. Run instructions for user | ||
|
|
||
| echo "\nSetup complete!" | ||
| echo "To activate your environment and run Deep-Live-Cam, use one of the following commands:" | ||
| echo "" | ||
| echo "# For CUDA (Nvidia GPU, if supported):" | ||
| echo "source venv/bin/activate && python run.py --execution-provider cuda" | ||
| echo "" | ||
| echo "# For Apple Silicon (M1/M2/M3) CoreML:" | ||
| echo "source venv/bin/activate && python3.10 run.py --execution-provider coreml" | ||
| echo "" | ||
| echo "# For CPU only:" | ||
| echo "source venv/bin/activate && python run.py" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| @echo off | ||
| REM Deep-Live-Cam Windows Automated Setup | ||
|
|
||
| REM 1. Create virtual environment | ||
| python -m venv venv | ||
| if errorlevel 1 ( | ||
| echo Failed to create virtual environment. Ensure Python 3.10+ is installed and in PATH. | ||
| exit /b 1 | ||
| ) | ||
|
|
||
| REM 2. Activate virtual environment | ||
| call venv\Scripts\activate | ||
| if errorlevel 1 ( | ||
| echo Failed to activate virtual environment. | ||
| exit /b 1 | ||
| ) | ||
|
|
||
| REM 3. Install dependencies | ||
| pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
| if errorlevel 1 ( | ||
| echo Failed to install dependencies. | ||
| exit /b 1 | ||
| ) | ||
|
|
||
| REM 4. Download models (manual step if not present) | ||
| echo Downloading models (if not already in models/)... | ||
| if not exist models\GFPGANv1.4.pth ( | ||
| powershell -Command "Invoke-WebRequest -Uri https://huggingface.co/hacksider/deep-live-cam/resolve/main/GFPGANv1.4.pth -OutFile models\GFPGANv1.4.pth" | ||
| ) | ||
| if not exist models\inswapper_128_fp16.onnx ( | ||
| powershell -Command "Invoke-WebRequest -Uri https://huggingface.co/hacksider/deep-live-cam/resolve/main/inswapper_128_fp16.onnx -OutFile models\inswapper_128_fp16.onnx" | ||
| ) | ||
|
|
||
| REM 5. Run the app | ||
| python run.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,42 @@ | ||
| import numpy as np | ||
| from sklearn.cluster import KMeans | ||
| from sklearn.metrics import silhouette_score | ||
| from typing import Any | ||
| from typing import Any, List, Tuple | ||
|
|
||
|
|
||
| def find_cluster_centroids(embeddings, max_k=10) -> Any: | ||
| def find_cluster_centroids(embeddings: List[Any], max_k: int = 10) -> Any: | ||
| """Find optimal cluster centroids for a set of embeddings using KMeans.""" | ||
| 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_}) | ||
| try: | ||
| kmeans = KMeans(n_clusters=k, random_state=0) | ||
| kmeans.fit(embeddings) | ||
ZardashtKaya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| inertia.append(kmeans.inertia_) | ||
| cluster_centroids.append({"k": k, "centroids": kmeans.cluster_centers_}) | ||
| except Exception as e: | ||
| print(f"KMeans failed for k={k}: {e}") | ||
|
|
||
| if len(inertia) < 2: | ||
| return cluster_centroids[0]['centroids'] if cluster_centroids else [] | ||
|
|
||
| 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: | ||
|
|
||
| def find_closest_centroid(centroids: List[Any], normed_face_embedding: Any) -> Tuple[int, Any]: | ||
| """Find the index and value of the centroid closest to the given embedding.""" | ||
| 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 | ||
| except Exception as e: | ||
| print(f"Error in find_closest_centroid: {e}") | ||
| return -1, None | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing shebang line. Add
#!/bin/bashat the beginning to ensure the script runs with the correct interpreter.