Spaces:
Running
on
Zero
Running
on
Zero
Update inference_i2mv_sdxl.py
Browse files- inference_i2mv_sdxl.py +46 -11
inference_i2mv_sdxl.py
CHANGED
@@ -103,17 +103,52 @@ def remove_bg(image: Image.Image, net, transform, device, mask: Image.Image = No
|
|
103 |
return image
|
104 |
|
105 |
|
106 |
-
def remove_bg(image, net, transform, device):
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
|
119 |
|
|
|
103 |
return image
|
104 |
|
105 |
|
106 |
+
# def remove_bg(image, net, transform, device):
|
107 |
+
# image_size = image.size
|
108 |
+
# input_images = transform(image).unsqueeze(0).to(device)
|
109 |
+
# with torch.no_grad():
|
110 |
+
# preds = net(input_images)[0].sigmoid().cpu()
|
111 |
+
# #preds = net(input_images)[-1] if isinstance(net(input_images), list) else net(input_images)
|
112 |
+
# pred = preds[0].squeeze()
|
113 |
+
# pred_pil = transforms.ToPILImage()(pred)
|
114 |
+
# mask = pred_pil.resize(image_size)
|
115 |
+
# image.putalpha(mask)
|
116 |
+
# return image
|
117 |
+
|
118 |
+
|
119 |
+
# def remove_bg(image: Image.Image, net, transform, device):
|
120 |
+
# """
|
121 |
+
# Applies a pre-existing mask to an image to make the background transparent.
|
122 |
+
# Args:
|
123 |
+
# image (PIL.Image.Image): The input image.
|
124 |
+
# net: Pre-trained neural network (not used but kept for compatibility).
|
125 |
+
# transform: Image transformation object (not used but kept for compatibility).
|
126 |
+
# device: Device used for inference (not used but kept for compatibility).
|
127 |
+
# Returns:
|
128 |
+
# PIL.Image.Image: The modified image with transparent background.
|
129 |
+
# """
|
130 |
+
# image_size = image.size
|
131 |
+
# input_images = transform(image).unsqueeze(0).to(device)
|
132 |
+
|
133 |
+
# with torch.no_grad():
|
134 |
+
# preds = net(input_images)[-1].sigmoid().cpu()
|
135 |
+
|
136 |
+
# pred = preds[0].squeeze()
|
137 |
+
# pred_pil = transforms.ToPILImage()(pred)
|
138 |
+
|
139 |
+
# # Resize the mask to match the original image size
|
140 |
+
# mask = pred_pil.resize(image_size, Image.LANCZOS)
|
141 |
+
|
142 |
+
# # Create a new image with the same size and mode as the original
|
143 |
+
# output_image = Image.new("RGBA", image_size)
|
144 |
+
|
145 |
+
# # Apply the mask to the original image
|
146 |
+
# image.putalpha(mask)
|
147 |
+
|
148 |
+
# # Composite the original image with the mask
|
149 |
+
# output_image.paste(image, (0, 0), image)
|
150 |
+
|
151 |
+
# return output_image
|
152 |
|
153 |
|
154 |
|