Skip to content
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

CLI Source Option #11

Merged
merged 3 commits into from
Feb 21, 2024
Merged

CLI Source Option #11

merged 3 commits into from
Feb 21, 2024

Conversation

kozlov721
Copy link
Collaborator

@kozlov721 kozlov721 commented Feb 20, 2024

CLI Source Option

Added option to source custom python file before any command is run with CLI.

This makes it possible to use custom components together with the CLI.

Usage

custom.py:

from luxonis_train.attached_modules.losses import BaseLoss

class CustomLoss(BaseLoss):

    # imports must be inside the class for the sourcing to work properly
    from torch import Tensor

    from luxonis_train.utils.types import Labels, Packet

    def __init__(self, **kwargs):
        super().__init__(**kwargs, required_labels=[])

    def prepare(self, inputs: Packet[Tensor], _: Labels) -> tuple[Tensor]:
        return (inputs["features"][-1],)

    def forward(self, x: Tensor) -> Tensor:
        return x.mean()

config.yaml:

model:
  name: resnet18_classification
  nodes:
    - name: ResNet
      variant: "18"
      download_weights: True

  losses:
    - name: CustomLoss
      attached_to: ResNet

CLI:

luxonis_train --source custom.py train --config config.yaml

@kozlov721 kozlov721 added the enhancement New feature or request label Feb 20, 2024
@kozlov721 kozlov721 self-assigned this Feb 20, 2024
Copy link

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
4433 3529 80% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
luxonis_train/main.py 50% 🟢
luxonis_train/core/exporter.py 55% 🟢
TOTAL 53% 🟢

updated for commit: 0bc0598 by action🐍

Copy link
Collaborator

@conorsim conorsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kozlov721 kozlov721 merged commit 15bd923 into dev Feb 21, 2024
@kozlov721 kozlov721 deleted the feature/cli-custom-source branch February 27, 2024 09:47
kozlov721 added a commit that referenced this pull request Oct 9, 2024
* option to source custom code in CLI

* removed empty dicts

* [Automated] Updated coverage badge

---------

Co-authored-by: GitHub Actions <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants