Matthias Bisping e4dc6631b5 Pull request #1: Setup
Merge in RR/fb_detr_prediction_container from setup to master

Squashed commit of the following:

commit 7fae4878d4250676367b7201fa163a4b67f79f84
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Feb 3 11:22:12 2022 +0100

    readded annotation to client

commit ff788030f6b3b342919a7fd31dfa66940033d7e1
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Feb 3 11:15:16 2022 +0100

    applied black

commit 3521444f678950a2772b725c6964751e0e655736
Merge: 4080aff 51d6597
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Feb 3 10:39:11 2022 +0100

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

commit 4080affd21a02ad32c61fbd2027511f51a202d63
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Feb 3 10:39:02 2022 +0100

    added poppler-utils download to Dockerfile, since pdf2image only is a wrapper for it

commit 51d6597b056ae9ac693280f65a3f37d46b1276cf
Author: Julius Unverfehrt <Julius.Unverfehrt@iqser.com>
Date:   Thu Feb 3 09:43:35 2022 +0100

    Structure change for local backbone lookup (working now)

commit ac314d5148d6e026c67f00df45a8bbc70c15b52d
Author: Julius Unverfehrt <Julius.Unverfehrt@iqser.com>
Date:   Thu Feb 3 09:35:41 2022 +0100

    env bug fixed

commit 1c3221fe4956911b29fd8fede8d07dcdefad06d8
Author: Julius Unverfehrt <Julius.Unverfehrt@iqser.com>
Date:   Thu Feb 3 09:23:55 2022 +0100

    ENV correctly set now

commit 58069440583f1f78cfb2fb796fa4dc4a63e2916a
Author: Julius Unverfehrt <Julius.Unverfehrt@iqser.com>
Date:   Thu Feb 3 08:41:29 2022 +0100

    ENV for local torch model lookup set

commit f0501cf0bf904793e8e04afbd3d80ee84af9d981
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 18:28:44 2022 +0100

    changed host and port for flask

commit 986fda22f6656b10930628d0d284995b33ea2df5
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 17:33:07 2022 +0100

    added debug webserver method

commit 64b857ce53757ec2b7e7c327962fa65b551603a0
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 16:59:11 2022 +0100

    moved utils into module; fixed open-cv (maybe)

commit c62ada183135e12b41a29c6822472e33698f947f
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 15:55:10 2022 +0100

    made bash scripts executable

commit 982bdd7503c14fcf1776ae10c38589475199545e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 15:35:16 2022 +0100

    service building logic added (WIP)

commit 46e5e3b8e67e54ecedaeee4765a3437f08fa4b17
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 14:37:28 2022 +0100

    applied black

commit ad93130e66d2e87bc86b2bf1de6234f3c037df48
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 14:36:09 2022 +0100

    fixed formatting (w, h -> x2, y2); added drawing logic to caller mock

commit df76f033599e66aaa52143f5e2b156530f643df9
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 13:54:34 2022 +0100

    page indices in predictions

commit 5e87c57dff752419486d1a44de9a734e3f840816
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 13:17:34 2022 +0100

    service main loop WIP (working in basic version)

commit ba5ec3d57621d090201413309126955940602be9
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 13:03:52 2022 +0100

    service main loop WIP

commit 77266f6982ec826eadcdd8a18c5ccf0fc380611b
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 11:24:27 2022 +0100

    fixed bug for self.classes == None

commit 858ef7589d6914ad503660a3ddc5e75bf72a6bb7
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Wed Feb 2 11:09:11 2022 +0100

    removed 'postprocessors' argument and attribute

... and 32 more commits
2022-02-03 11:44:11 +01:00

59 lines
1.3 KiB
Python

import argparse
import json
from operator import itemgetter
import pdf2image
import requests
from PIL import ImageDraw
def draw_coco_box(draw: ImageDraw.Draw, bbox, klass):
x1, y1, x2, y2 = itemgetter("x1", "y1", "x2", "y2")(bbox)
draw.rectangle(((x1, y1), (x2, y2)), outline="red")
draw.text((x1, y1), text=klass, fill=(0, 0, 0, 100))
def draw_coco_boxes(image, bboxes, classes):
draw = ImageDraw.Draw(image)
for bbox, klass in zip(bboxes, classes):
draw_coco_box(draw, bbox, klass)
return image
def annotate(pdf_path, predictions):
pages = pdf2image.convert_from_path(pdf_path)
for prd in predictions:
page_idx, boxes, classes = itemgetter("page_idx", "bboxes", "classes")(prd)
page = pages[page_idx]
image = draw_coco_boxes(page, boxes, classes)
image.save(f"/tmp/serv_out/{page_idx}.png")
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--pdf_path", required=True)
args = parser.parse_args()
return args
def main(args):
response = requests.post("http://0.0.0.0:8080", data=open(args.pdf_path, "rb"))
response.raise_for_status()
predictions = response.json()
print(json.dumps(predictions, indent=2))
annotate(args.pdf_path, predictions)
if __name__ == "__main__":
args = parse_args()
main(args)