moduleimplant


Namemoduleimplant JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/Gelinzh/moduleimplant
SummaryA custom module implant system for Ultralytics models
upload_time2024-12-21 16:15:00
maintainerNone
docs_urlNone
authoracelych
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
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:

```bash
moduleimlpant modify
```

for modifying Ulralytics pack;

```bash
moduleimlpant de-modify
```

for cancle modification before uninstallation.

**manual setup**

Paste moduleimplant.py file where task.py located, modify task.py as following:
1. import
    ```python
    from .moduleimplant import ModuleImplant
    ```
2. update globals() during parse_model()
    ```python
    globals().update(ModuleImplant.get_third_party_modules_dict())
    # insert this before 'for i, (f, n, m, args) in enumerate...'
    ```
3. add this elif within others in the for statement that mentioned above
    ```python
    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:
1. add this piece of code
    ```python
    from .moduleimplant import (
        ModuleImplant
    )
    ```
2. 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:
```python
@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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Gelinzh/moduleimplant",
    "name": "moduleimplant",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "acelych",
    "author_email": "acelych@foxmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e4/35/bce3cf8831179a9aaf6c90178c221e56118ba0eb88a0b29e5f1c2213fed5/moduleimplant-0.2.0.tar.gz",
    "platform": null,
    "description": "# Module-Implant\n\nThis project can help you implant 3rd party / custom pytorch nn.module components\ninto Ultralytics library. After that, you can simply modify the yaml file,\nwhich defines your network structure, with new components.\n\n## 1. Install\n\nThere are 2 ways to install this project.\nYou can simply download / clone the project and follow the manual instructions below, or try:\n\n```bash\npip install moduleimplant\n```\n\n## 2. Usage\n\n**Auto setup**\n\nModule-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.\n\nFor auto setup, try:\n\n```bash\nmoduleimlpant modify\n```\n\nfor modifying Ulralytics pack;\n\n```bash\nmoduleimlpant de-modify\n```\n\nfor cancle modification before uninstallation.\n\n**manual setup**\n\nPaste moduleimplant.py file where task.py located, modify task.py as following:\n1. import\n    ```python\n    from .moduleimplant import ModuleImplant\n    ```\n2. update globals() during parse_model()\n    ```python\n    globals().update(ModuleImplant.get_third_party_modules_dict())\n    # insert this before 'for i, (f, n, m, args) in enumerate...'\n    ```\n3. add this elif within others in the for statement that mentioned above\n    ```python\n    elif m in ModuleImplant.get_third_party_modules():\n        c1, c2, args = ModuleImplant.parse_third_party_module(ch, f, n, m, args)\n    ```\n    \nThen, modify the paralled `__init__.py` file as following:\n1. add this piece of code\n    ```python\n    from .moduleimplant import (\n        ModuleImplant\n    )\n    ```\n2. add \"ModuleImplant\" to `__all__`\n\n**prepare custom modules**\n\nYou also need a parser func to parse arguments provided by .yaml file.\nImplement a func called 'yaml_args_parser' in your custom module like this:\n```python\n@staticmethod\ndef yaml_args_parser(ch, f, n, m, args):\n    return ch[f], ch[f], [ch[f], *args]\n```\ntasks.py will pass 5 arguments for your custom module:\n- ch: a list that recorded all layers' output channel count\n- f: previous layer's serial number which indicates where this layer's data comes from\n- n: assume that your layer should be a serial of modules, n represents the repetition times\n- m: definition form of this module\n- args: custom arguments after aboves\n\ntasks.py needs 3 return values:\n- c1: layer's input channel count\n- c2: layer's output channel count\n- args: all arguments that module's initial function requires\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A custom module implant system for Ultralytics models",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/Gelinzh/moduleimplant"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "18fa1145b7a8f945ad710bf05281dd19921c1e4ebcfeda32291994b2f7a8096b",
                "md5": "1de8cceecdb654ea6a4064996c622a23",
                "sha256": "8d76de72338fd37168be9b7039f50231c0971019121fcba64a99f6881a391c35"
            },
            "downloads": -1,
            "filename": "moduleimplant-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1de8cceecdb654ea6a4064996c622a23",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7007,
            "upload_time": "2024-12-21T16:14:46",
            "upload_time_iso_8601": "2024-12-21T16:14:46.988904Z",
            "url": "https://files.pythonhosted.org/packages/18/fa/1145b7a8f945ad710bf05281dd19921c1e4ebcfeda32291994b2f7a8096b/moduleimplant-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e435bce3cf8831179a9aaf6c90178c221e56118ba0eb88a0b29e5f1c2213fed5",
                "md5": "78f805893d41dcb6d1cfc36c8c500980",
                "sha256": "6383cdb1b2bd052e592a296bac82afce4b4357034e4dfba97693892b36bd1658"
            },
            "downloads": -1,
            "filename": "moduleimplant-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "78f805893d41dcb6d1cfc36c8c500980",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 5579,
            "upload_time": "2024-12-21T16:15:00",
            "upload_time_iso_8601": "2024-12-21T16:15:00.301501Z",
            "url": "https://files.pythonhosted.org/packages/e4/35/bce3cf8831179a9aaf6c90178c221e56118ba0eb88a0b29e5f1c2213fed5/moduleimplant-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 16:15:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Gelinzh",
    "github_project": "moduleimplant",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "moduleimplant"
}
        
Elapsed time: 0.43182s