YulianSa commited on
Commit
79c1f1a
·
1 Parent(s): c18f6d1
Files changed (1) hide show
  1. infer_api.py +7 -3
infer_api.py CHANGED
@@ -200,6 +200,7 @@ def inference(validation_pipeline, input_image, vae, feature_extractor, image_en
200
  print("OUT!!!!!!")
201
 
202
  img_buf = io.BytesIO()
 
203
  img_buf.seek(0)
204
  img = Image.open(img_buf)
205
 
@@ -254,8 +255,11 @@ class TestConfig:
254
  def convert_to_numpy(tensor):
255
  return tensor.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to("cpu", torch.uint8).numpy()
256
 
257
- def save_image(tensor):
 
 
258
  ndarr = convert_to_numpy(tensor)
 
259
  return save_image_numpy(ndarr)
260
 
261
  def save_image_numpy(ndarr):
@@ -324,8 +328,8 @@ def run_multiview_infer(data, pipeline, cfg: TestConfig, num_levels=3):
324
  color = images_pred[idx]
325
 
326
  ## save color and normal---------------------
327
- new_normal = save_image(normal)
328
- new_color = save_image(color)
329
 
330
  if num_levels == 2:
331
  results[level+1]['normals'].append(new_normal)
 
200
  print("OUT!!!!!!")
201
 
202
  img_buf = io.BytesIO()
203
+ save_image(out[0], img_buf, format='PNG')
204
  img_buf.seek(0)
205
  img = Image.open(img_buf)
206
 
 
255
  def convert_to_numpy(tensor):
256
  return tensor.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to("cpu", torch.uint8).numpy()
257
 
258
+ # 定义一个函数,用于保存图像
259
+ def save_image2(tensor):
260
+ # 将tensor转换为numpy数组
261
  ndarr = convert_to_numpy(tensor)
262
+ # 调用save_image_numpy函数,保存图像
263
  return save_image_numpy(ndarr)
264
 
265
  def save_image_numpy(ndarr):
 
328
  color = images_pred[idx]
329
 
330
  ## save color and normal---------------------
331
+ new_normal = save_image2(normal)
332
+ new_color = save_image2(color)
333
 
334
  if num_levels == 2:
335
  results[level+1]['normals'].append(new_normal)