RyanHangZhou commited on
Commit
f576d1d
·
verified ·
1 Parent(s): 64b9e67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -100,7 +100,8 @@ def pics_pairwise_inference(background, img_a, mask_a, img_b, mask_b):
100
  ddim_sampler = DDIMSampler(model)
101
 
102
  # 唯一改动:对接 Gradio 的 PIL 转 OpenCV
103
- back_image = cv2.cvtColor(np.array(background), cv2.COLOR_RGB2BGR)
 
104
 
105
  item_with_collage = {}
106
  objs = [(img_a, mask_a), (img_b, mask_b)]
@@ -155,11 +156,16 @@ def pics_pairwise_inference(background, img_a, mask_a, img_b, mask_b):
155
  # 但由于你 207 脚本最后写的是 cv2.imwrite(..., gen_image[:, :, ::-1]),
156
  # 说明在你的 crop_back 之后结果是 BGR。
157
  # 为了保险,我们在这里把模型结果转成 BGR 再给 crop_back
158
- pred_bgr = cv2.cvtColor(pred_res, cv2.COLOR_RGB2BGR)
159
- final_bgr = crop_back(pred_bgr, back_image, item_with_collage['extra_sizes'],
160
- item_with_collage['hint_sizes0'], item_with_collage['hint_sizes1'], is_masked=True)
161
 
162
- return cv2.cvtColor(final_bgr, cv2.COLOR_BGR2RGB)
 
 
 
 
 
163
 
164
  with gr.Blocks(title="PICS: Pairwise Spatial Compositing") as demo:
165
  gr.Markdown("# 🚀 PICS: Pairwise Image Compositing (5-Input Framework)")
 
100
  ddim_sampler = DDIMSampler(model)
101
 
102
  # 唯一改动:对接 Gradio 的 PIL 转 OpenCV
103
+ # back_image = cv2.cvtColor(np.array(background), cv2.COLOR_RGB2BGR)
104
+ back_image = np.array(background)
105
 
106
  item_with_collage = {}
107
  objs = [(img_a, mask_a), (img_b, mask_b)]
 
156
  # 但由于你 207 脚本最后写的是 cv2.imwrite(..., gen_image[:, :, ::-1]),
157
  # 说明在你的 crop_back 之后结果是 BGR。
158
  # 为了保险,我们在这里把模型结果转成 BGR 再给 crop_back
159
+ # pred_bgr = cv2.cvtColor(pred_res, cv2.COLOR_RGB2BGR)
160
+ # final_bgr = crop_back(pred_bgr, back_image, item_with_collage['extra_sizes'],
161
+ # item_with_collage['hint_sizes0'], item_with_collage['hint_sizes1'], is_masked=True)
162
 
163
+ # return cv2.cvtColor(final_bgr, cv2.COLOR_BGR2RGB)
164
+ final_image = crop_back(pred_res, back_image, item_with_collage['extra_sizes'],
165
+ item_with_collage['hint_sizes0'], item_with_collage['hint_sizes1'], is_masked=True)
166
+
167
+ # 直接返回,因为 Gradio 也要 RGB
168
+ return final_image
169
 
170
  with gr.Blocks(title="PICS: Pairwise Spatial Compositing") as demo:
171
  gr.Markdown("# 🚀 PICS: Pairwise Image Compositing (5-Input Framework)")