From 9c0ec844516e9c1655480eac9de0cbccd0186568 Mon Sep 17 00:00:00 2001 From: Ryan Avery Date: Fri, 9 Dec 2022 12:14:25 -0800 Subject: [PATCH] pin docker container, change to 1280 resize, update readme --- api/megadetectorv5/README.md | 12 ++++++++---- api/megadetectorv5/docker_mdv5.sh | 2 +- api/megadetectorv5/mdv5_handler.py | 2 +- api/megadetectorv5/serve_megadetect.sh | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/megadetectorv5/README.md b/api/megadetectorv5/README.md index 6a8f513..981941e 100644 --- a/api/megadetectorv5/README.md +++ b/api/megadetectorv5/README.md @@ -1,24 +1,28 @@ # Setup Instructions ## Download weights and torchscript model -From root directory, run: +From this directory, run: ``` aws s3 sync s3://animl-model-zoo/megadetectorv5/ models/megadetectorv5/ ``` ## Export yolov5 weights as torchscript model -Size needs to be same as in mdv5_handler.py for good performance + +first, clone and install yolov5 dependencies and yolov5 following these instructions: https://docs.ultralytics.com/tutorials/torchscript-onnx-coreml-export/ + +Size needs to be same as in mdv5_handler.py for good performance. Run this from this directory ``` -python yolov5/export.py --weights models/megadetectorv5/md_v5a.0.0.pt --img 640 640 --batch 1 +python ../../../yolov5/export.py --weights models/megadetectorv5/md_v5a.0.0.pt --img 1280 1280 --batch 1 ``` this will create models/megadetectorv5/md_v5a.0.0.torchscript ## Run model archiver +first, `pip install torch-model-archiver` then, ``` torch-model-archiver --model-name mdv5 --version 1.0.0 --serialized-file models/megadetectorv5/md_v5a.0.0.torchscript --extra-files index_to_name.json --handler mdv5_handler.py mkdir -p model_store -mv mdv5.mar model_store/megadetectorv5-yolov5-1-batch-640-640.mar +mv mdv5.mar model_store/megadetectorv5-yolov5-1-batch-1280-1280.mar ``` The .mar file is what is served by torchserve. diff --git a/api/megadetectorv5/docker_mdv5.sh b/api/megadetectorv5/docker_mdv5.sh index 77fb0e2..b47f7bd 100644 --- a/api/megadetectorv5/docker_mdv5.sh +++ b/api/megadetectorv5/docker_mdv5.sh @@ -1,3 +1,3 @@ # dockerized version of the above, ran into dependency issue for termcolor # https://github.com/pytorch/serve/tree/master/docker -docker run --rm -p 8080:8080 -p 8081:8081 -p 8082:8082 -p 7070:7070 -p 7071:7071 -v "$(pwd)":/app -it pytorch/torchserve:latest bash /app/serve_megadetect.sh +docker run --rm -p 8080:8080 -p 8081:8081 -p 8082:8082 -p 7070:7070 -p 7071:7071 -v "$(pwd)":/app -it pytorch/torchserve:0.5.3-cpu bash /app/serve_megadetect.sh diff --git a/api/megadetectorv5/mdv5_handler.py b/api/megadetectorv5/mdv5_handler.py index 6d44bfe..db3c1ff 100644 --- a/api/megadetectorv5/mdv5_handler.py +++ b/api/megadetectorv5/mdv5_handler.py @@ -15,7 +15,7 @@ class ModelHandler(BaseHandler): A custom model handler implementation. """ - img_size = 640 + img_size = 1280 min_conf_thresh = 0.001 """Image size (px). Images will be resized to this resolution before inference. """ diff --git a/api/megadetectorv5/serve_megadetect.sh b/api/megadetectorv5/serve_megadetect.sh index 29c215b..0f6d342 100644 --- a/api/megadetectorv5/serve_megadetect.sh +++ b/api/megadetectorv5/serve_megadetect.sh @@ -7,5 +7,5 @@ # torch-model-archiver --model-name mdv5 --version 1.0.0 --serialized-file ../models/megadetectorv5/md_v5a.0.0.torchscript --extra-files index_to_name.json --handler ../api/megadetectorv5/mdv5_handler.py # mv mdv5.mar model_store/megadetectorv5-yolov5-1-batch-2048-2048.mar -torchserve --start --model-store /app/model_store --no-config-snapshots --models mdv5=/app/megadetectorv5-yolov5-1-batch-640-640.mar +torchserve --start --model-store /app/model_store --no-config-snapshots --models mdv5=/app/megadetectorv5-yolov5-1-batch-1280-1280.mar #curl http://127.0.0.1:8080/predictions/mdv5 -T ../input/sample-img-fox.jpg