-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-inference.py
executable file
·36 lines (30 loc) · 1.12 KB
/
docker-inference.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
#! /usr/bin/env python
"""
Wrapper to docker-compose to run inference on single image
"""
import yaml
import argparse
from pathlib import Path
from os import system
yaml_template = """
version: '3'
services:
checkbox_classification:
image: ardiya/checkbox_classification:latest
"""
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("image_path", type=str, help="Path to the image to be inferred")
args = parser.parse_args()
image_path = Path(args.image_path)
docker_path = Path("/root/checkbox_classification/data") / image_path.name
if not image_path.exists():
print("Unable to find file ", image_path)
from sys import exit
exit(1)
yaml_cfg = yaml.safe_load(yaml_template)
yaml_cfg["services"]["checkbox_classification"]["volumes"] = [f"{image_path.absolute()}:{docker_path}"]
yaml_cfg["services"]["checkbox_classification"]["command"] = f"python -u main_inference.py {docker_path}"
with open("docker-compose-inference.yaml", "w") as fp:
yaml.safe_dump(yaml_cfg, fp)
system("docker-compose -f docker-compose-inference.yaml up")