diff --git a/inference.py b/inference.py index a1819b41..0cb22466 100644 --- a/inference.py +++ b/inference.py @@ -29,7 +29,8 @@ args = options() def main(): - device = 'cuda' if torch.cuda.is_available() else 'cpu' + # device = 'cuda' if torch.cuda.is_available() else 'cpu' + device = torch.device('mps') print('[Info] Using {} for inference.'.format(device)) os.makedirs(os.path.join('temp', args.tmp_dir), exist_ok=True) diff --git a/third_part/GPEN/face_parse/face_parsing.py b/third_part/GPEN/face_parse/face_parsing.py index 39d7cb7f..f0485014 100644 --- a/third_part/GPEN/face_parse/face_parsing.py +++ b/third_part/GPEN/face_parse/face_parsing.py @@ -61,10 +61,18 @@ def process_tensor(self, imt): return mask + # def img2tensor(self, img): + # img = img[..., ::-1] # BGR to RGB + # img = img / 255. * 2 - 1 + # img_tensor = torch.from_numpy(img.transpose(2, 0, 1)).unsqueeze(0).to(self.device) + # return img_tensor.float() + def img2tensor(self, img): img = img[..., ::-1] # BGR to RGB img = img / 255. * 2 - 1 - img_tensor = torch.from_numpy(img.transpose(2, 0, 1)).unsqueeze(0).to(self.device) + a = img.transpose(2, 0, 1) + a = np.float32(a) + img_tensor = torch.from_numpy(a).unsqueeze(0).to(self.device) return img_tensor.float() def tenor2mask(self, tensor, masks):