Siam2315 commited on
Commit
64b9375
·
verified ·
1 Parent(s): 87b4e2b

Update CodeFormer/basicsr/utils/misc.py

Browse files
Files changed (1) hide show
  1. CodeFormer/basicsr/utils/misc.py +16 -0
CodeFormer/basicsr/utils/misc.py CHANGED
@@ -3,6 +3,22 @@ import re
3
  import random
4
  import time
5
  import torch
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  import numpy as np
7
  from os import path as osp
8
 
 
3
  import random
4
  import time
5
  import torch
6
+ def gpu_is_available():
7
+ return torch.cuda.is_available()
8
+
9
+ # Note: get_device is also often missing, so it's best practice to add it too.
10
+ def get_device(gpu_id=None):
11
+ if gpu_id is None:
12
+ gpu_str = ''
13
+ elif isinstance(gpu_id, int):
14
+ gpu_str = f':{gpu_id}'
15
+ else:
16
+ raise TypeError('Input should be int value. ')
17
+
18
+ # Prioritize CUDA (GPU) if available, otherwise use CPU
19
+ if torch.cuda.is_available() and torch.backends.cudnn.is_available():
20
+ return torch.device(f'cuda{gpu_str}')
21
+ return torch.device('cpu')
22
  import numpy as np
23
  from os import path as osp
24