yaghi27 commited on
Commit
bd3a67d
·
1 Parent(s): 6a407d9

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +13 -8
server.py CHANGED
@@ -27,24 +27,29 @@ async def root():
27
  with open("index.html", "r", encoding="utf-8") as f:
28
  return HTMLResponse(f.read())
29
 
30
-
31
  @app.post("/infer")
32
  async def run_inference(images: list[UploadFile] = File(...)):
33
- # save uploads
34
  img_paths = []
35
- for img in images:
36
- tmp = f"/tmp/{img.filename}"
37
- with open(tmp, "wb") as f:
38
- f.write(await img.read())
 
 
 
 
 
 
39
  img_paths.append(tmp)
40
 
41
- # run your BEV inference
42
  bev_paths = infer_images(img_paths)
43
 
44
- # base64-encode results
45
  output = []
46
  for p in bev_paths:
47
  with open(p, "rb") as f:
48
  b64 = base64.b64encode(f.read()).decode("utf-8")
49
  output.append({"bev_image": b64})
 
50
  return JSONResponse(content=output)
 
27
  with open("index.html", "r", encoding="utf-8") as f:
28
  return HTMLResponse(f.read())
29
 
 
30
  @app.post("/infer")
31
  async def run_inference(images: list[UploadFile] = File(...)):
 
32
  img_paths = []
33
+ for upload in images:
34
+ data = await upload.read()
35
+
36
+ # Decode bytes → BGR image, dropping any alpha channel
37
+ bgr = mmcv.imfrombytes(data, flag="color")
38
+
39
+ # Overwrite to disk as a 3-channel PNG (or JPEG)
40
+ tmp = f"/tmp/{upload.filename}"
41
+ mmcv.imwrite(bgr, tmp)
42
+
43
  img_paths.append(tmp)
44
 
45
+ # Now all inputs are (3, H, W)—your model won’t hit that dim==4 assertion
46
  bev_paths = infer_images(img_paths)
47
 
48
+ # Base64-encode outputs
49
  output = []
50
  for p in bev_paths:
51
  with open(p, "rb") as f:
52
  b64 = base64.b64encode(f.read()).decode("utf-8")
53
  output.append({"bev_image": b64})
54
+
55
  return JSONResponse(content=output)