PKUWilliamYang commited on
Commit
8a92539
1 Parent(s): 4dd3399

Update vtoonify_model.py

Browse files
Files changed (1) hide show
  1. vtoonify_model.py +4 -2
vtoonify_model.py CHANGED
@@ -57,6 +57,7 @@ class Model():
57
 
58
  self.vtoonify, self.exstyle = self._load_default_model()
59
  self.color_transfer = False
 
60
 
61
  @staticmethod
62
  def _create_dlib_landmark_model():
@@ -93,6 +94,7 @@ class Model():
93
  self.color_transfer = False
94
  if style_type not in self.style_types.keys():
95
  return None, 'Oops, wrong Style Type. Please select a valid model.'
 
96
  model_path, ind = self.style_types[style_type]
97
  style_path = os.path.join('models',os.path.dirname(model_path),'exstyle_code.npy')
98
  self.vtoonify.load_state_dict(torch.load(huggingface_hub.hf_hub_download(MODEL_REPO,'models/'+model_path),
@@ -213,7 +215,7 @@ class Model():
213
  y_tilde = self.vtoonify(inputs, s_w.repeat(inputs.size(0), 1, 1), d_s = style_degree)
214
  y_tilde = torch.clamp(y_tilde, -1, 1)
215
 
216
- return ((y_tilde[0].cpu().numpy().transpose(1, 2, 0) + 1.0) * 127.5).astype(np.uint8), 'Successfully toonify the image'
217
 
218
  def video_tooniy(self, aligned_video: str, instyle: torch.Tensor, exstyle: torch.Tensor, style_degree: float) -> tuple[str, str]:
219
  if aligned_video is None:
@@ -266,6 +268,6 @@ class Model():
266
 
267
  videoWriter.release()
268
  video_cap.release()
269
- return 'output.mp4', 'Successfully toonify video of %d frames'%(num)
270
 
271
 
 
57
 
58
  self.vtoonify, self.exstyle = self._load_default_model()
59
  self.color_transfer = False
60
+ self.style_name = 'cartoon1'
61
 
62
  @staticmethod
63
  def _create_dlib_landmark_model():
 
94
  self.color_transfer = False
95
  if style_type not in self.style_types.keys():
96
  return None, 'Oops, wrong Style Type. Please select a valid model.'
97
+ self.style_name = style_type
98
  model_path, ind = self.style_types[style_type]
99
  style_path = os.path.join('models',os.path.dirname(model_path),'exstyle_code.npy')
100
  self.vtoonify.load_state_dict(torch.load(huggingface_hub.hf_hub_download(MODEL_REPO,'models/'+model_path),
 
215
  y_tilde = self.vtoonify(inputs, s_w.repeat(inputs.size(0), 1, 1), d_s = style_degree)
216
  y_tilde = torch.clamp(y_tilde, -1, 1)
217
 
218
+ return ((y_tilde[0].cpu().numpy().transpose(1, 2, 0) + 1.0) * 127.5).astype(np.uint8), 'Successfully toonify the image with style of %s'%(self.style_name)
219
 
220
  def video_tooniy(self, aligned_video: str, instyle: torch.Tensor, exstyle: torch.Tensor, style_degree: float) -> tuple[str, str]:
221
  if aligned_video is None:
 
268
 
269
  videoWriter.release()
270
  video_cap.release()
271
+ return 'output.mp4', 'Successfully toonify video of %d frames with style of %s'%(num, self.style_name)
272
 
273