Spaces:
Running
on
Zero
Running
on
Zero
fix strength
Browse files- flux1_inpaint.py +8 -5
flux1_inpaint.py
CHANGED
|
@@ -24,9 +24,12 @@ def make_inpaint_condition(image, image_mask):
|
|
| 24 |
return None
|
| 25 |
|
| 26 |
image[image_mask > 0.5] = -1.0 # set as masked pixel
|
| 27 |
-
|
| 28 |
-
image =
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
|
|
@@ -40,7 +43,7 @@ def process_image(image,mask_image,prompt="a girl",negative_prompt="",model_id="
|
|
| 40 |
return None
|
| 41 |
|
| 42 |
#control_image=make_inpaint_condition(image,mask_image)
|
| 43 |
-
#
|
| 44 |
#image = control_image
|
| 45 |
|
| 46 |
pipe = FluxInpaintPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
|
|
@@ -50,7 +53,7 @@ def process_image(image,mask_image,prompt="a girl",negative_prompt="",model_id="
|
|
| 50 |
generator = torch.Generator(device).manual_seed(seed)
|
| 51 |
generators.append(generator)
|
| 52 |
|
| 53 |
-
output = pipe(prompt=prompt, image=image, mask_image=mask_image,generator=generator)
|
| 54 |
|
| 55 |
return output.images[0]
|
| 56 |
|
|
|
|
| 24 |
return None
|
| 25 |
|
| 26 |
image[image_mask > 0.5] = -1.0 # set as masked pixel
|
| 27 |
+
|
| 28 |
+
image = image.cpu().numpy() # torch.Tensor を NumPy 配列に変換
|
| 29 |
+
image = (image * 255).astype(np.uint8) # 0~1 の範囲を 0~255 に戻し、uint8 型にキャスト
|
| 30 |
+
image = image.transpose(0, 2, 3, 1) # (1, 3, H, W) から (1, H, W, 3) に形状を変更
|
| 31 |
+
|
| 32 |
+
return image[0]
|
| 33 |
|
| 34 |
|
| 35 |
|
|
|
|
| 43 |
return None
|
| 44 |
|
| 45 |
#control_image=make_inpaint_condition(image,mask_image)
|
| 46 |
+
#mask_image.save("_mask_image.jpg")
|
| 47 |
#image = control_image
|
| 48 |
|
| 49 |
pipe = FluxInpaintPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
|
|
|
|
| 53 |
generator = torch.Generator(device).manual_seed(seed)
|
| 54 |
generators.append(generator)
|
| 55 |
|
| 56 |
+
output = pipe(prompt=prompt, image=image, mask_image=mask_image,generator=generator,strength=strength)
|
| 57 |
|
| 58 |
return output.images[0]
|
| 59 |
|