tnc-ca-geo / animl-ml

Machine Learning resources for camera trap data processing
Other
4 stars 1 forks source link

convert MDv5 to torchscript Scripting model #71

Closed rbavery closed 2 years ago

rbavery commented 2 years ago

We have the MDv5 weights, but in order to not depend on the GPL licensed inference code in https://github.com/ultralytics/yolov5 we need to convert the model to Torchscript. Torchscript models can be loaded with Pytorch, as opposed to needing the model definition of the custom library built on top of pytorch.

Torchscript has two flavors: Tracing and Scripting. differences are outlined here: https://detectron2.readthedocs.io/en/latest/tutorials/deployment.html but the major ones are that torchscript tracing models will only work on a fixed batch size and fixed img size.

So it'd be ideal have a more flexible model so we don't need to resize all incoming images to a fixed size in TorchServe and so we can support larger batch sizes later if we want to.

To accomplish this, we'll need to use yolov5 to load the weights and then convert the model to Torchscript Scripting format. If this becomes to cumbersome we can switch to tracing. yolov5 provides a script to convert to Tracing but not Scripting and in my experience frameworks have a tougher time with Scripting, so we may end up with a Tracing model.

CC @nathanielrindlaub @ingalls

rbavery commented 2 years ago

we have converted to torchscript tracing, scripting is not supported. model weights are uploaded here: https://s3.console.aws.amazon.com/s3/buckets/animl-model-zoo?region=us-west-1&prefix=megadetectorv5/&showversions=false