Spaces:
Runtime error
Runtime error
Update utils_mask.py
Browse files- utils_mask.py +10 -11
utils_mask.py
CHANGED
|
@@ -60,7 +60,7 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
| 60 |
elif model_type == 'dc':
|
| 61 |
arm_width = 45
|
| 62 |
else:
|
| 63 |
-
raise ValueError("model_type must be
|
| 64 |
|
| 65 |
parse_head = (parse_array == 1).astype(np.float32) + \
|
| 66 |
(parse_array == 3).astype(np.float32) + \
|
|
@@ -77,17 +77,18 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
| 77 |
arms_left = (parse_array == 14).astype(np.float32)
|
| 78 |
arms_right = (parse_array == 15).astype(np.float32)
|
| 79 |
|
| 80 |
-
|
| 81 |
if category == 'dresses':
|
| 82 |
# Initial dress mask for the upper body
|
| 83 |
-
parse_mask_upper = (parse_array ==
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Create a separate mask for the legs
|
| 88 |
parse_mask_legs = (parse_array == 12).astype(np.float32) + \
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
| 93 |
|
|
@@ -97,9 +98,8 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
| 97 |
# Combine the filled leg mask with the upper body mask
|
| 98 |
combined_mask = np.maximum(parse_mask_upper, leg_mask_filled)
|
| 99 |
|
| 100 |
-
# Final dilation to
|
| 101 |
-
parse_mask =
|
| 102 |
-
|
| 103 |
|
| 104 |
elif category == 'upper_body':
|
| 105 |
parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
|
@@ -140,7 +140,6 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
| 140 |
size_right = [shoulder_right[0] - ARM_LINE_WIDTH // 2, shoulder_right[1] - ARM_LINE_WIDTH // 2, shoulder_right[0] + ARM_LINE_WIDTH // 2,
|
| 141 |
shoulder_right[1] + ARM_LINE_WIDTH // 2]
|
| 142 |
|
| 143 |
-
|
| 144 |
if wrist_right[0] <= 1. and wrist_right[1] <= 1.:
|
| 145 |
im_arms_right = arms_right
|
| 146 |
else:
|
|
|
|
| 60 |
elif model_type == 'dc':
|
| 61 |
arm_width = 45
|
| 62 |
else:
|
| 63 |
+
raise ValueError("model_type must be 'hd' or 'dc'!")
|
| 64 |
|
| 65 |
parse_head = (parse_array == 1).astype(np.float32) + \
|
| 66 |
(parse_array == 3).astype(np.float32) + \
|
|
|
|
| 77 |
arms_left = (parse_array == 14).astype(np.float32)
|
| 78 |
arms_right = (parse_array == 15).astype(np.float32)
|
| 79 |
|
|
|
|
| 80 |
if category == 'dresses':
|
| 81 |
# Initial dress mask for the upper body
|
| 82 |
+
parse_mask_upper = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
| 83 |
+
parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
|
| 84 |
+
(parse_array == label_map["pants"]).astype(np.float32)
|
| 85 |
+
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
| 86 |
+
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
| 87 |
|
| 88 |
# Create a separate mask for the legs
|
| 89 |
parse_mask_legs = (parse_array == 12).astype(np.float32) + \
|
| 90 |
+
(parse_array == 13).astype(np.float32) + \
|
| 91 |
+
(parse_array == 6).astype(np.float32)
|
| 92 |
|
| 93 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
| 94 |
|
|
|
|
| 98 |
# Combine the filled leg mask with the upper body mask
|
| 99 |
combined_mask = np.maximum(parse_mask_upper, leg_mask_filled)
|
| 100 |
|
| 101 |
+
# Final mask without further dilation to avoid affecting the upper body mask
|
| 102 |
+
parse_mask = combined_mask
|
|
|
|
| 103 |
|
| 104 |
elif category == 'upper_body':
|
| 105 |
parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
|
|
|
| 140 |
size_right = [shoulder_right[0] - ARM_LINE_WIDTH // 2, shoulder_right[1] - ARM_LINE_WIDTH // 2, shoulder_right[0] + ARM_LINE_WIDTH // 2,
|
| 141 |
shoulder_right[1] + ARM_LINE_WIDTH // 2]
|
| 142 |
|
|
|
|
| 143 |
if wrist_right[0] <= 1. and wrist_right[1] <= 1.:
|
| 144 |
im_arms_right = arms_right
|
| 145 |
else:
|