From 499e8de65b5a1ef3e429cc7560f6580e1277db4b Mon Sep 17 00:00:00 2001 From: lext Date: Wed, 20 Nov 2019 12:52:42 +0200 Subject: [PATCH] Made deployment script --- .dockerignore | 3 ++- .gitignore | 2 ++ deploy.sh | 14 ++++++++++ Dockerfile.cpu => docker/Dockerfile.cpu | 1 + Dockerfile.gpu => docker/Dockerfile.gpu | 0 docker/docker-compose-cpu.yml | 0 docker/docker-compose-gpu.yml | 36 +++++++++++++++++++++++++ ouludeepknee/inference/app.py | 5 ++-- 8 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 deploy.sh rename Dockerfile.cpu => docker/Dockerfile.cpu (71%) rename Dockerfile.gpu => docker/Dockerfile.gpu (100%) create mode 100644 docker/docker-compose-cpu.yml create mode 100644 docker/docker-compose-gpu.yml diff --git a/.dockerignore b/.dockerignore index 54ca50c..3de575a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ snapshots_knee_grading/* -*.egg-info \ No newline at end of file +*.egg-info +snapshots_release_kneel/* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6872782..4e6bd89 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ __pycache__/ # C extensions *.so .idea/* +./snapshots_knee_grading/* +./snapshots_release_kneel/* # Distribution / packaging .Python env/ diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..0f6efef --- /dev/null +++ b/deploy.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +if [ ! -d "snapshots_release_kneel" ]; then + wget http://mipt-ml.oulu.fi/models/KNEEL/snapshots_release.tar.xz + tar -xvf snapshots_release.tar.xz + rm snapshots_release.tar.xz + mv snapshots_release snapshots_release_kneel +fi + +if [ ! -d "snapshots_knee_grading" ]; then + sh ./fetch_snapshots.sh +fi + +docker-compose -f ./docker/docker-compose-$1.yml up \ No newline at end of file diff --git a/Dockerfile.cpu b/docker/Dockerfile.cpu similarity index 71% rename from Dockerfile.cpu rename to docker/Dockerfile.cpu index 154bf2b..1aacfc3 100644 --- a/Dockerfile.cpu +++ b/docker/Dockerfile.cpu @@ -1,3 +1,4 @@ +# KNEEL and DeepKnee inference packages share the same docker image. FROM miptmloulu/kneel:cpu MAINTAINER Aleksei Tiulpin, University of Oulu, Version 1.0 diff --git a/Dockerfile.gpu b/docker/Dockerfile.gpu similarity index 100% rename from Dockerfile.gpu rename to docker/Dockerfile.gpu diff --git a/docker/docker-compose-cpu.yml b/docker/docker-compose-cpu.yml new file mode 100644 index 0000000..e69de29 diff --git a/docker/docker-compose-gpu.yml b/docker/docker-compose-gpu.yml new file mode 100644 index 0000000..d20138c --- /dev/null +++ b/docker/docker-compose-gpu.yml @@ -0,0 +1,36 @@ +version: "2.3" +services: + kneel: + runtime: nvidia + image: "miptmloulu/kneel:gpu" + ports: + - "5000:5000" + volumes: + - type: bind + source: ../snapshots_release_kneel # The snapshots are stored in the root directory + target: /snapshots/ + read_only: true + entrypoint: ["python", "-u", "-m", "kneel.inference.app", + "--lc_snapshot_path", "/snapshots/lext-devbox_2019_07_14_16_04_41", + "--hc_snapshot_path", "/snapshots/lext-devbox_2019_07_14_19_25_40", + "--refine", "True", "--mean_std_path", "/snapshots/mean_std.npy", + "--deploy", "True", "--device", "cuda"] + deepknee-backend: + runtime: nvidia + depends_on: + - kneel + build: + context: ../ + dockerfile: ./docker/Dockerfile.gpu + ports: + - "5001:5001" + volumes: + - type: bind + source: ../snapshots_knee_grading/ # The snapshots are stored in the root directory + target: /snapshots/ + read_only: true + environment: + - KNEEL_ADDR=http://127.0.0.1:5000 + entrypoint: ["python", "-m", "ouludeepknee.inference.app", + "--snapshots_path", "/snapshots/", + "--device", "cuda", "--deploy", "True"] diff --git a/ouludeepknee/inference/app.py b/ouludeepknee/inference/app.py index a1036a9..e6723b7 100644 --- a/ouludeepknee/inference/app.py +++ b/ouludeepknee/inference/app.py @@ -62,6 +62,7 @@ def analyze_single_knee(): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--snapshots_path', default='') + parser.add_argument('--deploy_addr', default='0.0.0.0') parser.add_argument('--device', default='cuda') parser.add_argument('--sizemm', type=int, default=140) parser.add_argument('--pad', type=int, default=300) @@ -74,7 +75,7 @@ def analyze_single_knee(): device=args.device) if args.deploy: - http_server = WSGIServer(('', 5001), app) + http_server = WSGIServer((args.deploy_addr, 5001), app) http_server.serve_forever() else: - app.run(host='', port=5001, debug=True) + app.run(host=args.deploy_addr, port=5001, debug=True)