sczhou commited on
Commit
50cfdd0
·
1 Parent(s): 9ea1225

fix issues for pytorch<1.9.0.

Browse files
.gitignore CHANGED
@@ -123,4 +123,6 @@ venv.bak/
123
 
124
  # project
125
  results/
 
126
  *_old*
 
 
123
 
124
  # project
125
  results/
126
+ dlib/
127
  *_old*
128
+
facelib/detection/yolov5face/face_detector.py CHANGED
@@ -17,6 +17,9 @@ from facelib.detection.yolov5face.utils.general import (
17
  scale_coords_landmarks,
18
  )
19
 
 
 
 
20
  def isListempty(inList):
21
  if isinstance(inList, list): # Is a list
22
  return all(map(isListempty, inList))
@@ -116,8 +119,14 @@ class YoloDetector:
116
  origimgs = copy.deepcopy(images)
117
 
118
  images = self._preprocess(images)
119
- with torch.inference_mode(): # change this with torch.no_grad() for pytorch <1.8 compatibility
120
- pred = self.detector(images)[0]
 
 
 
 
 
 
121
  bboxes, points = self._postprocess(images, origimgs, pred, conf_thres, iou_thres)
122
 
123
  # return bboxes, points
 
17
  scale_coords_landmarks,
18
  )
19
 
20
+ IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) >= (1, 9, 0)
21
+
22
+
23
  def isListempty(inList):
24
  if isinstance(inList, list): # Is a list
25
  return all(map(isListempty, inList))
 
119
  origimgs = copy.deepcopy(images)
120
 
121
  images = self._preprocess(images)
122
+
123
+ if IS_HIGH_VERSION:
124
+ with torch.inference_mode(): # for pytorch>=1.9
125
+ pred = self.detector(images)[0]
126
+ else:
127
+ with torch.no_grad(): # for pytorch<1.9
128
+ pred = self.detector(images)[0]
129
+
130
  bboxes, points = self._postprocess(images, origimgs, pred, conf_thres, iou_thres)
131
 
132
  # return bboxes, points
facelib/detection/yolov5face/models/yolo.py CHANGED
@@ -87,7 +87,8 @@ class Detect(nn.Module):
87
 
88
  @staticmethod
89
  def _make_grid(nx=20, ny=20):
90
- yv, xv = torch.meshgrid([torch.arange(ny), torch.arange(nx)], indexing="ij")
 
91
  return torch.stack((xv, yv), 2).view((1, 1, ny, nx, 2)).float()
92
 
93
 
 
87
 
88
  @staticmethod
89
  def _make_grid(nx=20, ny=20):
90
+ # yv, xv = torch.meshgrid([torch.arange(ny), torch.arange(nx)], indexing="ij") # for pytorch>=1.10
91
+ yv, xv = torch.meshgrid([torch.arange(ny), torch.arange(nx)])
92
  return torch.stack((xv, yv), 2).view((1, 1, ny, nx, 2)).float()
93
 
94
 
facelib/utils/face_restoration_helper.py CHANGED
@@ -69,7 +69,7 @@ class FaceRestoreHelper(object):
69
  self.face_template = np.array([[192, 240], [319, 240], [257, 371]])
70
  else:
71
  # standard 5 landmarks for FFHQ faces with 512 x 512
72
- # # xintao
73
  self.face_template = np.array([[192.98138, 239.94708], [318.90277, 240.1936], [256.63416, 314.01935],
74
  [201.26117, 371.41043], [313.08905, 371.15118]])
75
 
 
69
  self.face_template = np.array([[192, 240], [319, 240], [257, 371]])
70
  else:
71
  # standard 5 landmarks for FFHQ faces with 512 x 512
72
+ # facexlib
73
  self.face_template = np.array([[192.98138, 239.94708], [318.90277, 240.1936], [256.63416, 314.01935],
74
  [201.26117, 371.41043], [313.08905, 371.15118]])
75
 
inference_codeformer.py CHANGED
@@ -91,8 +91,6 @@ if __name__ == '__main__':
91
  face_helper.clean_all()
92
 
93
  img_name = os.path.basename(img_path)
94
- # if not '04' in img_name:
95
- # continue
96
  print(f'Processing: {img_name}')
97
  basename, ext = os.path.splitext(img_name)
98
  img = cv2.imread(img_path, cv2.IMREAD_COLOR)
 
91
  face_helper.clean_all()
92
 
93
  img_name = os.path.basename(img_path)
 
 
94
  print(f'Processing: {img_name}')
95
  basename, ext = os.path.splitext(img_name)
96
  img = cv2.imread(img_path, cv2.IMREAD_COLOR)