Pull request #4: waitress as webserver

Merge in RR/fb_detr_prediction_container from suppress_userwarnings to master

Squashed commit of the following:

commit ecdacd449b466b206434fd8d6729e55f91f7c171
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 9 14:58:00 2022 +0100

    updated submodule

commit 114c0b963de024cfef30a3f7ac084751611c4ea0
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 9 14:47:00 2022 +0100

    fixed docker build invocation

commit daa01cda5328d0e25694f89e83a1aa9e21d4bfcb
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 9 14:45:40 2022 +0100

    refactoring; added waitress wrapper

commit d9828dfcc86cdd021f4fc37078f133d8c1fe4924
Merge: 32ffd0e 9a2a5b2
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 9 13:22:26 2022 +0100

    Merge branch 'master' of ssh://git.iqser.com:2222/rr/fb_detr_prediction_container into suppress_userwarnings

commit 32ffd0ea97ee39af7526966efc8ec46b7553b415
Author: Julius Unverfehrt <Julius.Unverfehrt@iqser.com>
Date:   Wed Feb 9 13:09:31 2022 +0100

    typo fixed

commit 6d03a590434c70feb4836a0e024b24e92ed98f73
Author: Julius Unverfehrt <Julius.Unverfehrt@iqser.com>
Date:   Wed Feb 9 13:06:58 2022 +0100

    added suppress function to suppress pytorch-futre warnings cluttering the service logs
This commit is contained in:
Julius Unverfehrt 2022-02-09 15:10:02 +01:00 committed by Matthias Bisping
parent 9a2a5b2362
commit b00ff021f8
4 changed files with 21 additions and 4 deletions

@ -1 +1 @@
Subproject commit c17cddd980ae3003a2633a65744d2265228e4c71
Subproject commit 0d2808c70737fb9fed665334c4cdec7fd39b2e4b

View File

@ -13,3 +13,4 @@ iteration-utilities==0.11.0
dvc==2.9.3
dvc[ssh]
frozendict==2.3.0
waitress==2.0.0

View File

@ -12,4 +12,4 @@ dvc pull
git submodule update --init --recursive
docker build -f Dockerfile-base -t detr-server-base .
docker build -f Dockerfile -t detr-server . --build-arg
docker build -f Dockerfile -t detr-server .

View File

@ -4,14 +4,21 @@ import os
from fb_detr.locations import DATA_DIR
from fb_detr.locations import TORCH_HOME
from fb_detr.predictor import Predictor
from waitress import serve
from flask import Flask, request, jsonify
from pdf2image import pdf2image
from fb_detr.utils.config import read_config
def suppress_userwarnings():
import warnings
warnings.filterwarnings("ignore")
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--resume")
parser.add_argument("--warnings", action="store_true", default=False)
args = parser.parse_args()
return args
@ -32,10 +39,19 @@ def set_torch_env():
def main(args):
if not args.warnings:
suppress_userwarnings()
run_server(args.resume)
def run_server(resume):
set_torch_env()
def initialize_predictor():
checkpoint = get_checkpoint() if not args.resume else args.resume
checkpoint = get_checkpoint() if not resume else resume
predictor = Predictor(checkpoint, classes=load_classes(), rejection_class=read_config("rejection_class"))
return predictor
@ -58,7 +74,7 @@ def main(args):
predictor = initialize_predictor()
app.run(host="127.0.0.1", port=5000)
serve(app, host="127.0.0.1", port=5000)
if __name__ == "__main__":