Advertisement
Guest User

SimSwap_Device_Agnositc_Patch.bat

a guest
Jul 6th, 2021
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <# :
  2. @echo off
  3. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  4. : #>
  5. $search_replace = @{
  6.     "if len(self.opt.gpu_ids)" = "if torch.cuda.is_available() and len(self.opt.gpu_ids)";
  7.     "torch.device(`'cuda:0`')" = "torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`')";
  8.     "torch.load(netArc_checkpoint)" = "torch.load(netArc_checkpoint) if torch.cuda.is_available() else torch.load(netArc_checkpoint, map_location=torch.device(`'cpu`'))";
  9.     ".cuda()" = ".to(torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`'))";
  10.     ".to('cuda')" = ".to(torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`'))";
  11. }
  12.  
  13. ForEach ($File in (Get-ChildItem -Path '.\*.py' -Recurse -File)) {
  14.     $content = (Get-Content $File)
  15.     if ($content.length -gt 0) {
  16.         ForEach ($search in $search_replace.Keys) {
  17.             $content = $content.replace("$search", "$($search_replace[$search])")
  18.         }
  19.         Set-Content $File $content
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement