Skip to content

Commit

Permalink
pin docker container, change to 1280 resize, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rbavery committed Dec 9, 2022
1 parent e83e328 commit 9c0ec84
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions api/megadetectorv5/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/megadetectorv5/docker_mdv5.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion api/megadetectorv5/mdv5_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion api/megadetectorv5/serve_megadetect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9c0ec84

Please sign in to comment.