-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[INFORMATION] mmyolo - Model Surgery using edgeai-modeloptimization - to create lite models #7
Comments
How Model Surgery is actually doneThis is for information only - the above patch already includes these changes. The patch adds the following code in mmyolo repository in tools/train.py. similarly tools/test.py is also modified to include model surgery.
Add this in parse_args function:
Add the following code in mmyolo repository in tools/train.py before the line runner.train()
|
Currently i'm facing a major issue integrating these optimization.
ImportError: cannot import name '_parse_stack_trace' from 'torch.fx.graph when i try to run the model after integrating the optimization i run into this issue. which when i tracked require torch with version 2.2 at least. Nevertheless mmyolo 0.6 which is the latest version require an earlier version same with cuda. Hope you can guide me the environment you are currently using cause i tried several updates but reached a dead end. |
The mmyolo repository requires torch version less than 2.1, because it depends on a particular version of mmcv You can try following these steps after applying the above patch :
*python version is 3.10 |
Introduction
mmyolo (https://github.com/open-mmlab/mmyolo) is a repository that has several interesting Object Detection models. For example, it includes models such as YOLOv5, YOLOv7, YOLOX, YOLOv8 etc.
Here we describe how to apply Model Surgery on mmyolo to create lite models that run faster on Embedded Systems.
Background - What actually happens in Model Surgery
The types of Operators/Layers that are being used in popular models are increasing rapidly. All of them may not work efficiently in embedded devices. For example, a ReLU activation layer is much faster compared to a SWish activation layer - because ReLU operator is implemented in Hardware at fullest speed (because of the simplicity of ReLU operation). This is just an example. There are several such examples.
In many cases it is possible to replace in-efficient layers with their efficient alternatives without actually modifying the code. It is done by modifying the Python model after the model has been instantiated.
How to use edgeai-modeloptimization
edgeai-modeloptimization (https://github.com/TexasInstruments/edgeai-tensorlab/tree/main/edgeai-modeloptimization) is a package that can automate some of the Model Surgery aspects.
It provides edgeai_torchmodelopt, a python pakage that helps to modify PyTorch models without manually editing the model code.
The exact location is here: https://github.com/TexasInstruments/edgeai-tensorlab/tree/main/edgeai-modeloptimization/torchmodelopt
It provides various types of model surgery options as described here:
https://github.com/TexasInstruments/edgeai-tensorlab/blob/main/edgeai-modeloptimization/torchmodelopt/docs/surgery.md
Patch file
The commit id of mmyolo (https://github.com/open-mmlab/mmyolo) for this explanation is: 8c4d9dc503dc8e327bec8147e8dc97124052f693
This patch file includes above modification in train.py and other modifications in val.py, prototxt export etc.
0001-2024-Aug-2-mmyolo.commit-8c4d9dc5.-model-surgery-with-edgeai-modeloptimization.txt
Patching mmyolo:
Run training:
You can also use tools/dist_train.sh
(just make sure that --model-surgery 1 argument is passed inside it)
Expected Accuracy
This table shows expected model accuracy of Lite models after training.
Notes
Additional information
Additional information about the details of the modifications done using Model Surgery is here: https://github.com/TexasInstruments/edgeai-yolov5
The text was updated successfully, but these errors were encountered: