File tree 3 files changed +31
-23
lines changed
3 files changed +31
-23
lines changed Original file line number Diff line number Diff line change 1
- # FROM python:3.6
2
-
3
- # RUN apt-get update
4
- # RUN apt-get install -y git libsm6 libxrender1 libfontconfig1
5
-
6
- # WORKDIR /workspace
7
-
8
- # COPY ./requirements_container.txt /workspace
9
- # # Install python package dependices
10
- # RUN pip install -r requirements_container.txt
11
-
12
- # WORKDIR /workspace/
13
-
14
-
15
- # COPY ./dextr_pb2.py /workspace
16
- # COPY ./dextr_pb2_grpc.py /workspace
17
- # COPY ./server.py /workspace
18
- # COPY ./dextr.proto /workspace
19
-
20
- # ENTRYPOINT [ "python", "server.py" ]
21
-
22
1
FROM python:3.8.5
23
2
24
3
RUN apt-get update
@@ -36,6 +15,6 @@ RUN pip install gunicorn==20.0.4
36
15
COPY server.py /workspace
37
16
38
17
EXPOSE 8000
39
-
18
+ ENV DEVICE=cpu
40
19
WORKDIR /workspace
41
20
CMD [ "gunicorn" , "-w 6" , "-b 0.0.0.0:8000" , "server:app" ]
Original file line number Diff line number Diff line change
1
+ FROM pytorch/pytorch:1.7.0-cuda11.0-cudnn8-runtime
2
+
3
+
4
+ RUN apt-get update
5
+ RUN apt-get install 'ffmpeg'\
6
+ 'libsm6'\
7
+ 'libxext6' -y
8
+
9
+ RUN apt install liblzma-dev
10
+
11
+ WORKDIR /workspace
12
+ COPY requirements_container.txt /workspace
13
+ RUN pip install -r requirements_container.txt
14
+ RUN python -c "from dextr.model import DextrModel; DextrModel.pascalvoc_resunet101()"
15
+ RUN pip install gunicorn==20.0.4
16
+ COPY server.py /workspace
17
+
18
+ EXPOSE 8000
19
+ ENV DEVICE=cuda:0
20
+ WORKDIR /workspace
21
+ CMD [ "gunicorn", "-w 6", "-b 0.0.0.0:8000", "server:app" ]
Original file line number Diff line number Diff line change 4
4
from PIL import Image
5
5
import numpy as np
6
6
import time
7
+ import torch
8
+ import os
7
9
8
10
from imantics import Mask
9
11
12
+ device = os .getenv ("DEVICE" , "cpu" )
13
+ torch_device = torch .device (device )
10
14
11
15
app = Flask (__name__ )
12
16
model = DextrModel .pascalvoc_resunet101 ()
17
+ model .eval ()
13
18
14
19
15
20
@app .route ("/" , methods = ["GET" , "POST" ])
@@ -25,8 +30,11 @@ def hello_world():
25
30
image = Image .open (path )
26
31
print (f"Image Size: { image .size } " , flush = True )
27
32
33
+ # points come in [x,y] order; this must be flipped
34
+ points = points [:, ::- 1 ]
28
35
mask = model .predict ([image ], [points ])[0 ]
29
- polygons = Mask (mask ).polygons ().points
36
+ mask_bin = mask >= 0.5
37
+ polygons = Mask (mask_bin ).polygons ().points
30
38
polygons = [polygon .tolist () for polygon in polygons if len (polygon ) > 2 ]
31
39
print (f"Result: { polygons } " , flush = True )
32
40
You can’t perform that action at this time.
0 commit comments