Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# :
- @echo off
- setlocal enabledelayedexpansion
- set "POWERSHELL_STAGE=SHOW_PS_VERSION"
- powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
- if not exist downloads\ mkdir downloads
- if not exist anaconda3\ mkdir anaconda3
- if not exist simswap\ mkdir simswap
- if not exist anaconda3\_conda.exe (
- set "POWERSHELL_STAGE=DOWNLOAD_ANACONDA"
- powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
- if !errorlevel! equ 1 (
- pause
- exit /b
- )
- for %%i in (downloads\anaconda3*exe) do (
- echo Installing %%~ni...
- start /wait "" %%i /InstallationType=JustMe /AddToPath=1 /RegisterPython=0 /NoRegistry=1 /S /D=%~dp0anaconda3
- echo Done!
- goto INSTALL_SIMSWAP_MODELS
- )
- exit /b
- )
- :INSTALL_SIMSWAP_MODELS
- if not exist simswap\arcface_model\arcface_checkpoint.tar (
- set "POWERSHELL_STAGE=SETUP_SIMSWAP_MODELS"
- powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
- )
- if exist "simswap\README.md" (
- set "POWERSHELL_STAGE=SETUP_SIMSWAP"
- powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
- )
- if not exist "simswap\Drop_videos.bat" (
- set "POWERSHELL_STAGE=EXPORT_BATCH_FILES"
- powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
- )
- call anaconda3\Scripts\activate.bat %~dp0anaconda3
- cd simswap
- call conda create -n simswap python=3.6 --yes
- call conda activate simswap
- call conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch --yes
- call pip install --ignore-installed imageio
- call pip install insightface==0.2.1 onnxruntime moviepy
- exit /b
- : #>
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- $ProgressPreference = "SilentlyContinue"
- $simswap_path = "simswap\"
- if ($env:POWERSHELL_STAGE -eq "SHOW_PS_VERSION") {
- Write-Host "PowerShell version:"
- $PSVersionTable.PSVersion
- }
- if ($env:POWERSHELL_STAGE -eq "DOWNLOAD_ANACONDA") {
- $target_hash = "93db42390444019e98b442ab281e1091671b6dce64daf08928d337ffc83cf3d2"
- $url = "https://repo.anaconda.com/archive/Anaconda3-2021.05-Windows-x86_64.exe"
- $file = "downloads\$($url.split('/') | Select -Last 1)"
- if (!(Test-Path $file)) {
- Write-Host "Downloading $file..."
- Invoke-WebRequest $url -OutFile $file
- Write-Host "Downloaded!"
- }
- Write-Host "Verifying the installer data integrity..."
- $file_hash = Get-FileHash $file -Algorithm "SHA256"
- if ($file_hash.Hash -ne $target_hash) {
- Write-Host "Hash mismatch! Try again!" $file_hash.Hash $target_hash
- Remove-Item $file
- exit 1
- }
- Write-Host "Done!"
- }
- if ($env:POWERSHELL_STAGE -eq "SETUP_SIMSWAP_MODELS") {
- $url = "https://drive.google.com/uc?export=download&id=1rm9Ea_8P25-bU0NGjqncWBqbkvX1ZtPx"
- $file = "downloads\SimSwap-main-cpu.7z"
- if (!(Test-Path $file)) {
- Write-Host "Downloading $file..."
- $response = Invoke-WebRequest $url -SessionVariable "session"
- if ($response -match "confirm=(?<confirm_key>.*?)&") {
- $url = $url.replace("export=download", "export=download&confirm=$($Matches["confirm_key"])")
- Invoke-WebRequest $url -OutFile $file -WebSession $session
- Write-Host "Downloaded!"
- } else {
- Write-Host "Something went wrong..."
- exit 1
- }
- }
- Write-Host "Unzipping $file..."
- if (!(Get-Module -ListAvailable -Name "7Zip4PowerShell")) {
- Write-Host "Have to instal 7zip module first..."
- Install-PackageProvider -Name "NuGet" -MinimumVersion "2.8.5.201" -Scope "CurrentUser" -Force
- Set-PSRepository -Name "PSGallery" -SourceLocation "https://www.powershellgallery.com/api/v2" -InstallationPolicy "Trusted"
- Install-Module -Name "7Zip4PowerShell" -Scope "CurrentUser" -Force
- Write-Host "Unzipping..."
- }
- Expand-7Zip $file -TargetPath $simswap_path
- Set-Location $simswap_path
- Get-ChildItem "SimSwap-main-cpu" | Move-Item -Destination ".\"
- Remove-Item "SimSwap-main-cpu"
- Set-Location "..\"
- Write-Host "Done!"
- }
- if ($env:POWERSHELL_STAGE -eq "SETUP_SIMSWAP") {
- $url = "https://github.com/neuralchen/SimSwap/archive/refs/heads/main.zip"
- $file = "downloads\SimSwap-main.zip"
- if (!(Test-Path $file)) {
- Write-Host "Downloading $file..."
- Invoke-WebRequest $url -OutFile $file -WebSession $session
- Write-Host "Downloaded!"
- }
- Write-Host "Unzipping $file..."
- Expand-Archive $file -DestinationPath $simswap_path
- Set-Location $simswap_path
- Get-ChildItem "SimSwap-main" -Directory -Recurse -Name | where { !(Test-Path("$_")) } | % { Move-Item -Path "\SimSwap-main\$_" -Destination ".\$_" }
- Get-ChildItem "SimSwap-main" -File -Recurse -Name | % { Move-Item -Path "SimSwap-main\$_" -Destination ".\$_" -Force }
- Remove-Item "SimSwap-main" -Recurse
- Write-Host "Done!"
- Write-Host "Applying patches..."
- $search_replace = @{
- "if len(self.opt.gpu_ids)" = "if torch.cuda.is_available() and len(self.opt.gpu_ids)";
- "torch.device(`"cuda:0`")" = "torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`')";
- "torch.load(netArc_checkpoint)" = "torch.load(netArc_checkpoint) if torch.cuda.is_available() else torch.load(netArc_checkpoint, map_location=torch.device(`'cpu`'))";
- ".cuda()" = ".to(torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`'))";
- ".to('cuda')" = ".to(torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`'))";
- }
- ForEach ($File in (Get-ChildItem -Path ".\*.py" -Recurse -File)) {
- $content = (Get-Content $File)
- if ($content.length -gt 0) {
- ForEach ($search in $search_replace.Keys) {
- $content = $content.replace("$search", "$($search_replace[$search])")
- }
- Set-Content $File $content
- }
- }
- Remove-Item "README.md"
- Set-Location "..\"
- Write-Host "Done!"
- }
- if ($env:POWERSHELL_STAGE -eq "EXPORT_BATCH_FILES") {
- Set-Location $simswap_path
- Set-Content "Drop_picture_or_video.bat" @"
- `@echo off
- set "FACE_IMG="
- set "VIDEO="
- set "OUTPUT_FILE=output\"
- set "FILE=%~2"
- if "%~x1"==".jpg" set "FACE_IMG=%~1"
- if "%~x1"==".jpeg" set "FACE_IMG=%~1"
- if "%~x1"==".png" set "FACE_IMG=%~1"
- if [%~1] neq [] (
- echo %~1
- if [%FILE%] equ [] (
- if defined FACE_IMG (echo Path to video file:) else (echo Path to face image file:)
- set /p "FILE="
- )
- )
- for %%f in ("%FILE%") do set "FILENAME=%%~nf"
- if defined FACE_IMG (
- set "VIDEO=%FILE%"
- set "OUTPUT_FILE=%OUTPUT_FILE%%~n1_%FILENAME%.mp4"
- ) else (
- set "VIDEO=%~1"
- set "FACE_IMG=%FILE%"
- set "OUTPUT_FILE=%OUTPUT_FILE%%FILENAME%_%~n1.mp4"
- )
- if not defined VIDEO goto wrong_args
- if not defined FACE_IMG goto wrong_args
- echo Face image file: %FACE_IMG%
- echo Video file: %VIDEO%
- call %userprofile%\anaconda3\Scripts\activate.bat %userprofile%\anaconda3
- cd %~dp0
- call activate simswap
- call python test_video_swapmulti.py --isTrain false --name people --Arc_path arcface_model/arcface_checkpoint.tar --temp_path ./temp_results ^
- --pic_a_path %FACE_IMG% ^
- --video_path %VIDEO% ^
- --output_path ./%OUTPUT_FILE%
- if exist %~dp0%OUTPUT_FILE% call explorer /select,%~dp0%OUTPUT_FILE%
- goto :eof
- :wrong_args
- echo No video or face image provided^!
- echo Args: %~1 %FILE%
- "@
- Set-Content "Drop_videos.bat" @"
- `@echo off
- set "FACE_IMG="
- set "VIDEOS="
- set "OUTPUT_DIR=output\"
- if "%~1"=="" (
- echo Pass at least one video file!
- pause
- goto :eof
- )
- echo Path to face image:
- set /p "FACE_IMG="
- for %%i in ("%FACE_IMG%") do (
- if "%%~xi"==".jpg" set "FACE_IMG=%%i"
- if "%%~xi"==".jpeg" set "FACE_IMG=%%i"
- if "%%~xi"==".png" set "FACE_IMG=%%i"
- )
- if not defined FACE_IMG goto wrong_args
- echo Face image file is: %FACE_IMG%
- for %%i in ("%FACE_IMG%") do set "FACE_NAME=%%~ni"
- call %userprofile%\anaconda3\Scripts\activate.bat %userprofile%\anaconda3
- cd %~dp0
- call activate simswap
- :swap_video
- echo Swapping video: %~nx1
- call python test_video_swapmulti.py --isTrain false --name people --Arc_path arcface_model/arcface_checkpoint.tar --temp_path ./temp_results ^
- --pic_a_path %FACE_IMG% ^
- --video_path %~1 ^
- --output_path "./%OUTPUT_DIR%%FACE_NAME%_%~n1.mp4"
- )
- shift
- if not "%~1"=="" goto :swap_video
- if exist %~dp0%OUTPUT_DIR% call explorer /select,%~dp0%OUTPUT_DIR%
- goto :eof
- :wrong_args
- echo No face image provided^!
- echo Args: %~1 %VIDEO%
- "@
- Set-Location "..\"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement