Spaces:
Running
on
Zero
Running
on
Zero
Update utils_mask.py
Browse files- utils_mask.py +21 -17
utils_mask.py
CHANGED
|
@@ -78,27 +78,31 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
| 78 |
arms_right = (parse_array == label_map["right_arm"]).astype(np.float32)
|
| 79 |
|
| 80 |
if category == 'dresses':
|
| 81 |
-
#
|
| 82 |
-
parse_mask_upper = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
parse_mask_legs = (parse_array == 6).astype(np.float32) + \
|
| 88 |
(parse_array == 12).astype(np.float32) + \
|
| 89 |
(parse_array == 13).astype(np.float32) + \
|
| 90 |
-
(parse_array == 5).astype(np.float32)
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
|
| 100 |
-
# Combine
|
| 101 |
-
parse_mask = np.
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
elif category == 'upper_body':
|
|
|
|
| 78 |
arms_right = (parse_array == label_map["right_arm"]).astype(np.float32)
|
| 79 |
|
| 80 |
if category == 'dresses':
|
| 81 |
+
# Combine upper body category logic
|
| 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 |
+
# Combine lower body category logic
|
| 89 |
parse_mask_legs = (parse_array == 6).astype(np.float32) + \
|
| 90 |
(parse_array == 12).astype(np.float32) + \
|
| 91 |
(parse_array == 13).astype(np.float32) + \
|
| 92 |
+
(parse_array == 5).astype(np.float32)
|
| 93 |
+
parser_mask_fixed += (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
|
| 94 |
+
(parse_array == label_map["left_arm"]).astype(np.float32) + \
|
| 95 |
+
(parse_array == label_map["right_arm"]).astype(np.float32)
|
| 96 |
+
|
| 97 |
+
# Include parse_mask_legs in parser_mask_changeable
|
| 98 |
+
parser_mask_changeable = np.logical_or(parser_mask_changeable, parse_mask_legs)
|
| 99 |
+
|
| 100 |
+
parse_mask_legs = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
|
| 101 |
|
| 102 |
+
# Combine the upper body mask with the leg mask
|
| 103 |
+
parse_mask = np.logical_and(parser_mask_changeable, np.logical_not(parse_mask))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
|
| 107 |
|
| 108 |
elif category == 'upper_body':
|