A custom module implant system for Ultralytics models
Project description
Module-Implant
This project can help you implant 3rd party / custom pytorch nn.module components into Ultralytics library. After that, you can simply modify the yaml file, which defines your network structure, with new components.
1. Install
There are 2 ways to install this project. You can simply download / clone the project and follow the manual instructions below, or try:
pip install moduleimplant
2. Usage
Auto setup
Module-Implant need some manual operations to modify Ultralytics since Ultralytics does not provide APIs for custom modules and using if-else to select inner modules.
For auto setup, try:
moduleimlpant modify
for modifying Ulralytics pack;
moduleimlpant de-modify
for cancle modification before uninstallation.
manual setup
Paste moduleimplant.py file where task.py located, modify task.py as following:
- import
from .moduleimplant import ModuleImplant
- update globals() during parse_model()
globals().update(ModuleImplant.get_third_party_modules_dict()) # insert this before 'for i, (f, n, m, args) in enumerate...'
- add this elif within others in the for statement that mentioned above
elif m in ModuleImplant.get_third_party_modules(): c1, c2, args = ModuleImplant.parse_third_party_module(ch, f, n, m, args)
Then, modify the paralled __init__.py file as following:
- add this piece of code
from .moduleimplant import ( ModuleImplant )
- add "ModuleImplant" to
__all__
prepare custom modules
You also need a parser func to parse arguments provided by .yaml file. Implement a func called 'yaml_args_parser' in your custom module like this:
@staticmethod
def yaml_args_parser(ch, f, n, m, args):
return ch[f], ch[f], [ch[f], *args]
tasks.py will pass 5 arguments for your custom module:
- ch: a list that recorded all layers' output channel count
- f: previous layer's serial number which indicates where this layer's data comes from
- n: assume that your layer should be a serial of modules, n represents the repetition times
- m: definition form of this module
- args: custom arguments after aboves
tasks.py needs 3 return values:
- c1: layer's input channel count
- c2: layer's output channel count
- args: all arguments that module's initial function requires
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moduleimplant-0.2.0.tar.gz.
File metadata
- Download URL: moduleimplant-0.2.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6383cdb1b2bd052e592a296bac82afce4b4357034e4dfba97693892b36bd1658
|
|
| MD5 |
78f805893d41dcb6d1cfc36c8c500980
|
|
| BLAKE2b-256 |
e435bce3cf8831179a9aaf6c90178c221e56118ba0eb88a0b29e5f1c2213fed5
|
File details
Details for the file moduleimplant-0.2.0-py3-none-any.whl.
File metadata
- Download URL: moduleimplant-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d76de72338fd37168be9b7039f50231c0971019121fcba64a99f6881a391c35
|
|
| MD5 |
1de8cceecdb654ea6a4064996c622a23
|
|
| BLAKE2b-256 |
18fa1145b7a8f945ad710bf05281dd19921c1e4ebcfeda32291994b2f7a8096b
|