primerz commited on
Commit
f15847d
·
verified ·
1 Parent(s): 62ea67e

Upload 3 files

Browse files
Files changed (3) hide show
  1. config.py +7 -7
  2. generator.py +13 -2
  3. utils.py +15 -15
config.py CHANGED
@@ -24,18 +24,18 @@ TRIGGER_WORD = "p1x3l4rt, pixel art"
24
 
25
  # Face detection configuration
26
  FACE_DETECTION_CONFIG = {
27
- "model_name": "antelopev2",
28
  "det_size": (640, 640),
29
  "ctx_id": 0
30
  }
31
 
32
- # Recommended resolutions
33
  RECOMMENDED_SIZES = [
34
- (896, 1152), # Portrait
35
- (1152, 896), # Landscape
36
- (832, 1216), # Tall portrait
37
- (1216, 832), # Wide landscape
38
- (1024, 1024) # Square
39
  ]
40
 
41
  # Default generation parameters
 
24
 
25
  # Face detection configuration
26
  FACE_DETECTION_CONFIG = {
27
+ "model_name": "buffalo_l",
28
  "det_size": (640, 640),
29
  "ctx_id": 0
30
  }
31
 
32
+ # Recommended resolutions (multiples of 64 for stable diffusion)
33
  RECOMMENDED_SIZES = [
34
+ (896, 1152), # Portrait (14:18 ratio)
35
+ (1152, 896), # Landscape (18:14 ratio)
36
+ (832, 1216), # Tall portrait (13:19 ratio)
37
+ (1216, 832), # Wide landscape (19:13 ratio)
38
+ (1024, 1024) # Square (1:1 ratio)
39
  ]
40
 
41
  # Default generation parameters
generator.py CHANGED
@@ -161,11 +161,22 @@ class RetroArtConverter:
161
  # Get original dimensions
162
  orig_width, orig_height = image.size
163
 
 
 
 
 
 
 
 
 
 
 
 
164
  # Generate depth map with Leres (better quality than Zoe)
165
  with torch.no_grad():
166
- depth_image = self.leres_depth(image)
167
 
168
- # Ensure output matches original size
169
  if depth_image.size != (orig_width, orig_height):
170
  depth_image = depth_image.resize((orig_width, orig_height), Image.LANCZOS)
171
 
 
161
  # Get original dimensions
162
  orig_width, orig_height = image.size
163
 
164
+ # Ensure dimensions are multiples of 64 for better processing
165
+ detect_width = int((orig_width // 64) * 64) or 64
166
+ detect_height = int((orig_height // 64) * 64) or 64
167
+
168
+ # Resize if needed
169
+ if detect_width != orig_width or detect_height != orig_height:
170
+ detect_image = image.resize((detect_width, detect_height), Image.LANCZOS)
171
+ print(f"[DEPTH] Resized for detection: {orig_width}x{orig_height} -> {detect_width}x{detect_height}")
172
+ else:
173
+ detect_image = image
174
+
175
  # Generate depth map with Leres (better quality than Zoe)
176
  with torch.no_grad():
177
+ depth_image = self.leres_depth(detect_image)
178
 
179
+ # Resize back to original dimensions
180
  if depth_image.size != (orig_width, orig_height):
181
  depth_image = depth_image.resize((orig_width, orig_height), Image.LANCZOS)
182
 
utils.py CHANGED
@@ -395,10 +395,10 @@ def get_demographic_description(age, gender_code):
395
 
396
  def calculate_optimal_size(original_width, original_height, recommended_sizes=None, max_dimension=1536):
397
  """
398
- Calculate optimal size maintaining aspect ratio with dimensions as multiples of 8.
399
 
400
  This updated version supports ANY aspect ratio (not just predefined ones),
401
- while ensuring dimensions are multiples of 8 and keeping total pixels reasonable.
402
 
403
  Args:
404
  original_width: Original image width
@@ -407,7 +407,7 @@ def calculate_optimal_size(original_width, original_height, recommended_sizes=No
407
  max_dimension: Maximum allowed dimension (default 1536)
408
 
409
  Returns:
410
- Tuple of (optimal_width, optimal_height) as multiples of 8
411
  """
412
  aspect_ratio = original_width / original_height
413
 
@@ -423,15 +423,15 @@ def calculate_optimal_size(original_width, original_height, recommended_sizes=No
423
  best_diff = diff
424
  best_match = (width, height)
425
 
426
- # Ensure dimensions are multiples of 8
427
  width, height = best_match
428
- width = int((width // 8) * 8)
429
- height = int((height // 8) * 8)
430
 
431
  return width, height
432
 
433
  # NEW: Support any aspect ratio
434
- # Strategy: Keep aspect ratio, scale to reasonable total pixels, round to multiples of 8
435
 
436
  # Target total pixels (around 1 megapixel for SDXL, adjustable)
437
  target_pixels = 1024 * 1024 # ~1MP, good balance for SDXL
@@ -455,23 +455,23 @@ def calculate_optimal_size(original_width, original_height, recommended_sizes=No
455
  optimal_height = max_dimension
456
  optimal_width = optimal_height * aspect_ratio
457
 
458
- # Round to nearest multiple of 8
459
- width = int(round(optimal_width / 8) * 8)
460
- height = int(round(optimal_height / 8) * 8)
461
 
462
  # Ensure minimum size (at least 512 on shortest side)
463
  min_dimension = 512
464
  if min(width, height) < min_dimension:
465
  if width < height:
466
  width = min_dimension
467
- height = int(round((width / aspect_ratio) / 8) * 8)
468
  else:
469
  height = min_dimension
470
- width = int(round((height * aspect_ratio) / 8) * 8)
471
 
472
- # Final safety check: ensure multiples of 8
473
- width = max(8, int((width // 8) * 8))
474
- height = max(8, int((height // 8) * 8))
475
 
476
  print(f"[SIZING] Aspect ratio: {aspect_ratio:.3f}, Output: {width}x{height} ({width*height/1e6:.2f}MP)")
477
 
 
395
 
396
  def calculate_optimal_size(original_width, original_height, recommended_sizes=None, max_dimension=1536):
397
  """
398
+ Calculate optimal size maintaining aspect ratio with dimensions as multiples of 64.
399
 
400
  This updated version supports ANY aspect ratio (not just predefined ones),
401
+ while ensuring dimensions are multiples of 64 and keeping total pixels reasonable.
402
 
403
  Args:
404
  original_width: Original image width
 
407
  max_dimension: Maximum allowed dimension (default 1536)
408
 
409
  Returns:
410
+ Tuple of (optimal_width, optimal_height) as multiples of 64
411
  """
412
  aspect_ratio = original_width / original_height
413
 
 
423
  best_diff = diff
424
  best_match = (width, height)
425
 
426
+ # Ensure dimensions are multiples of 64
427
  width, height = best_match
428
+ width = int((width // 64) * 64)
429
+ height = int((height // 64) * 64)
430
 
431
  return width, height
432
 
433
  # NEW: Support any aspect ratio
434
+ # Strategy: Keep aspect ratio, scale to reasonable total pixels, round to multiples of 64
435
 
436
  # Target total pixels (around 1 megapixel for SDXL, adjustable)
437
  target_pixels = 1024 * 1024 # ~1MP, good balance for SDXL
 
455
  optimal_height = max_dimension
456
  optimal_width = optimal_height * aspect_ratio
457
 
458
+ # Round to nearest multiple of 64
459
+ width = int(round(optimal_width / 64) * 64)
460
+ height = int(round(optimal_height / 64) * 64)
461
 
462
  # Ensure minimum size (at least 512 on shortest side)
463
  min_dimension = 512
464
  if min(width, height) < min_dimension:
465
  if width < height:
466
  width = min_dimension
467
+ height = int(round((width / aspect_ratio) / 64) * 64)
468
  else:
469
  height = min_dimension
470
+ width = int(round((height * aspect_ratio) / 64) * 64)
471
 
472
+ # Final safety check: ensure multiples of 64
473
+ width = max(64, int((width // 64) * 64))
474
+ height = max(64, int((height // 64) * 64))
475
 
476
  print(f"[SIZING] Aspect ratio: {aspect_ratio:.3f}, Output: {width}x{height} ({width*height/1e6:.2f}MP)")
477