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

Custom Loaders Support #27

Merged
merged 12 commits into from
May 21, 2024
Merged

Custom Loaders Support #27

merged 12 commits into from
May 21, 2024

Conversation

kozlov721
Copy link
Collaborator

@kozlov721 kozlov721 commented May 15, 2024

Added support for using custom loaders.

Example

source.py

from luxonis_train.utils.loaders import BaseLoaderTorch

class CustomLoader(BaseLoaderTorch):
    import torch
    from luxonis_ml.data import LabelType

    from luxonis_train.utils.loaders import LuxonisLoaderTorchOutput

    @property
    def input_shape(self) -> torch.Size:
        return self.torch.Size((1, 3, 256, 256))

    def __getitem__(self, _: int) -> LuxonisLoaderTorchOutput:
        from luxonis_ml.data import LabelType

        img = self.torch.rand(3, 256, 256)
        label = self.torch.zeros(1, 256, 256)
        label[0, 100:200, 100:200] = 1
        labels = {
            "default": {
                LabelType.SEGMENTATION: label,
            }
        }
        return img, labels

    def __len__(self) -> int:
        return 32

    def get_classes(self) -> dict[LabelType, list[str]]:
        return {self.LabelType.SEGMENTATION: ["square"]}
luxonis_train --source source.py \
              --config configs/segmentation_model.yaml \ 
              loader.name CustomLoader loader.params '{}'

Breaking Config Changes

dataset section renamed to loader. Custom loader can be referenced by its name in the LOADERS registry. The default loader is LuxonisLoaderTorch. Former keys of the dataset field now go under params field in the loader.

loader:
  name: LuxonisLoaderTorch  # this is the default

  train_view: train
  val_view: val
  test_view: test

  params:
    dataset_name: coco_test
    bucket_storage: gcs

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

Test Results

  6 files    6 suites   38m 16s ⏱️
 57 tests  25 ✅ 0 💤  7 ❌  25 🔥
342 runs  178 ✅ 0 💤 14 ❌ 150 🔥

For more details on these failures and errors, see this check.

Results for commit 49aab2b.

Copy link

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
4713 3650 77% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
luxonis_train/init.py 100% 🟢
luxonis_train/main.py 49% 🟢
luxonis_train/callbacks/test_on_train_end.py 86% 🟢
luxonis_train/core/init.py 100% 🟢
luxonis_train/core/archiver.py 19% 🟢
luxonis_train/core/core.py 78% 🟢
luxonis_train/core/exporter.py 55% 🟢
luxonis_train/core/inferer.py 87% 🟢
luxonis_train/core/trainer.py 62% 🟢
luxonis_train/core/tuner.py 83% 🟢
luxonis_train/models/luxonis_model.py 89% 🟢
luxonis_train/utils/config.py 95% 🟢
luxonis_train/utils/general.py 78% 🟢
luxonis_train/utils/loaders/init.py 100% 🟢
luxonis_train/utils/loaders/base_loader.py 63% 🟢
luxonis_train/utils/loaders/luxonis_loader_torch.py 100% 🟢
luxonis_train/utils/registry.py 100% 🟢
TOTAL 79% 🟢

updated for commit: 27e59fc 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.

Looks like a nice improvement, thanks!

@@ -23,7 +25,8 @@
HEAD_NAMES = [head_name for head_name in ImplementedHeads.__members__]


class TestArchiver:
@pytest.mark.skip()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we skip this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The NN Archive in the latest dev of luxonis-ml is not compatible with the tests for now (we need to figure out the yolov8 keypoint outputs in the archive)

@tersekmatija tersekmatija requested a review from JSabadin May 20, 2024 09:06
Copy link
Collaborator

@tersekmatija tersekmatija left a comment

Choose a reason for hiding this comment

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

1/ Does this affect any of our current online datasets?
2/ Have we tested the kpts training?

Otherwise looks good, thanks!

sampler = torch_data.WeightedRandomSampler(weights, num_samples)

self.pytorch_loaders = {
view: torch_data.DataLoader(
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if self.loaders[view] does not exist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will always exist

@kozlov721
Copy link
Collaborator Author

1/ Does this affect any of our current online datasets?

No, this shouldn't change anything regarding the underlying datasets

2/ Have we tested the kpts training?

Yes

@kozlov721 kozlov721 merged commit 99b1857 into dev May 21, 2024
@kozlov721 kozlov721 deleted the feature/custom-loader branch May 21, 2024 03:30
@CaptainTrojan
Copy link
Contributor

CaptainTrojan commented May 21, 2024

@kozlov721 What is the correct way of providing BucketType and BucketStorage to the default LuxonisLoaderTorch? The DatasetConfig ensured that strings like internal, local, gcs etc. were mapped to the corresponding enum type.

kozlov721 added a commit that referenced this pull request Oct 9, 2024
* support for custom loaders and datasets

* updated configs

* custom loaders in inspect command

* updated inspect for multi-task labels

* removed custom loader from test config

* deleted comment

* deleted comment

* removed custom dataset

* removed comment

* skipping archiver test untill fixed in luxonis-ml

* [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.

5 participants