-
Notifications
You must be signed in to change notification settings - Fork 0
/
3DMD_server.py
40 lines (31 loc) · 1.13 KB
/
3DMD_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pathlib import Path
import fastapi
import pydantic
import xvfbwrapper # for headless rendering
from mvlm import pipeline
try:
vdisplay = xvfbwrapper.Xvfb(width=256, height=256)
vdisplay.start()
print("Started virtual display with Xvfb")
except Exception as e:
print("Could not start virtual display with Xvfb", e)
pass
class Item(pydantic.BaseModel):
path_in: str
class Landmarks(pydantic.BaseModel):
landmarks: list[list[float]]
app = fastapi.FastAPI()
dm = pipeline.BU3DFEPipeline()
@app.post("/landmarks3d")
def get_3d_landmarks(item: Item):
path_in = Path(item.path_in)
landmarks = dm.predict_one_file(path_in)
landmarks = landmarks.tolist()
return Landmarks(landmarks=landmarks)
# start with
# uvicorn 3DMD_server:app --port 10000 --host 0.0.0.0
# for debug, LIBGL_DEBUG=verbose before
# NOTE this might not work on other machines via ssh. to solve this:
# - in the /anaconda3/envs/<name>/lib/libstdcc.so.6 rename (preferred) or delete the file
# - and don't lock the screen on a machine with x-server running and monitor attached
# - install xvfbwrapper (via pypi) and xvfb (via apt-get)