Ashrafb commited on
Commit
e410b45
·
verified ·
1 Parent(s): 4b8649d

Update vtoonify_model.py

Browse files
Files changed (1) hide show
  1. vtoonify_model.py +5 -6
vtoonify_model.py CHANGED
@@ -18,8 +18,7 @@ import gc
18
  import huggingface_hub
19
  import os
20
  import logging
21
- from PIL import Image
22
-
23
 
24
  # Configure logging
25
  logging.basicConfig(level=logging.INFO)
@@ -173,10 +172,10 @@ class Model():
173
  # Transform and crop the image
174
  transform_size = 256
175
  output_size = 256
176
- img = PIL.Image.fromarray(image)
177
- img = img.transform((transform_size, transform_size), PIL.Image.QUAD, (quad + 0.5).flatten(), PIL.Image.BILINEAR)
178
  if output_size < transform_size:
179
- img = img.resize((output_size, output_size), PIL.Image.ANTIALIAS)
180
 
181
  return np.array(img)
182
 
@@ -319,4 +318,4 @@ class Model():
319
  """Convert a tensor image to OpenCV format."""
320
  tmp = ((img.cpu().numpy().transpose(1, 2, 0) + 1.0) * 127.5).astype(np.uint8).copy()
321
  logging.debug(f"Converted image shape: {tmp.shape}, strides: {tmp.strides}")
322
- return cv2.cvtColor(tmp, cv2.COLOR_RGB2BGR)
 
18
  import huggingface_hub
19
  import os
20
  import logging
21
+ from PIL import Image # Importing Image from PIL
 
22
 
23
  # Configure logging
24
  logging.basicConfig(level=logging.INFO)
 
172
  # Transform and crop the image
173
  transform_size = 256
174
  output_size = 256
175
+ img = Image.fromarray(image) # Corrected to use PIL.Image
176
+ img = img.transform((transform_size, transform_size), Image.QUAD, (quad + 0.5).flatten(), Image.BILINEAR)
177
  if output_size < transform_size:
178
+ img = img.resize((output_size, output_size), Image.ANTIALIAS)
179
 
180
  return np.array(img)
181
 
 
318
  """Convert a tensor image to OpenCV format."""
319
  tmp = ((img.cpu().numpy().transpose(1, 2, 0) + 1.0) * 127.5).astype(np.uint8).copy()
320
  logging.debug(f"Converted image shape: {tmp.shape}, strides: {tmp.strides}")
321
+ return cv2.cvtColor(tmp, cv2.COLOR_RGB2BGR)