-
Notifications
You must be signed in to change notification settings - Fork 4
/
patch_cpu.ps1
31 lines (29 loc) · 1.36 KB
/
patch_cpu.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Patch for making SimSwap CPU-compatible.
# Should be executed from SimSwap folder.
<# :
@echo off
powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
exit /b
: #>
<# :
@echo off
powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
exit /b
: #>
$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`'))";
"net.load_state_dict(torch.load(save_pth))" = "net.load_state_dict(torch.load(save_pth)) if torch.cuda.is_available() else net.load_state_dict(torch.load(save_pth, 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
}
}