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

[Feature] Support Multi-task. #1229

Merged
merged 183 commits into from Dec 30, 2022
Merged

[Feature] Support Multi-task. #1229

merged 183 commits into from Dec 30, 2022

Conversation

piercus
Copy link
Contributor

@piercus piercus commented Nov 25, 2022

Motivation

Multi-tasking

This is inspired from #675 and #808

Inhomogenous dataset

One of the main change compared to #675 is to take into account some inhomogenous dataset.

By inhomogenous dataset, i mean, some sample may have ground truth value for one task, but not for another task, and we need to use mask in the mult-task training logic in order to modulate which sample to take into account with which loss.

1.x

We tried to follow 1.X standard as much as possible

Made with open-mmlab in mind, not only mmcls

The main idea is to provide a generic and flexible multi-task toolbox.

This is for mmclassification, but we tried to limit the deps between the MultiTask Implementation and mmcls, which is mostly related to the data_sample types that can be handled.

We hope this can be discussed further, and we think making a more generic version of it may be part of another PR.

Modification

Modifications are :

  • Dataset MultiTaskDataset + unit tests
  • Pipeline FormatMultiTaskLabels + unit tests
  • Metric MultiTaskMetric + unit tests
  • Head MultiTaskHead + unit tests
  • Structure MultiTaskDataSample + unit tests

BC-breaking (Optional)

No

Use cases (Optional)

Simple use case

The basic use case here it to classify multiple classes using the same neural network.

This can be useful if you want to "superclass" ImageNet for example (see https://robustness.readthedocs.io/en/latest/example_usage/custom_imagenet.html)

Nested use case

If you have 4 classification task, 2 about classifying the background, and 2 about classiying the foreground, you can decide to organize your task like

dict(type= 'MultiTaskHead', task_heads={
  "foreground": dict(type= 'LinearMultiTaskHead', task_heads={
    "foreground0": dict(type= 'LinearClsHead', num_classes=3),
    "foreground1": dict(type= 'LinearClsHead', num_classes=3)
  }),
  "background": dict(type= 'LinearMultiTaskHead', task_heads={
    "background0": dict(type= 'LinearClsHead', num_classes=3),
    "background1": dict(type= 'LinearClsHead', num_classes=3)
  })
})

By doing this, you can share layers between some tasks

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring
  • example tutorials not done yet.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

piercus and others added 30 commits January 27, 2022 23:44
* [Feature] Support MPS device.

* Add `auto_select_device`

* Add unit tests
* Fix albu BUG: using albu will cause the label from array(x) to array([x]) and crash the trainning

* Fix common

* Using copy incase potential bug in multi-label tasks

* Improve coding

* Improve code logic

* Add unit test

* Fix typo

* Fix yapf
@piercus
Copy link
Contributor Author

piercus commented Dec 6, 2022

@mzr1996 we have updated metrics and unit tests following your suggestions.

It creates unseen situations as input of following functions :

  • In the predict function, data_samples type is now List[ClsDataSample | None] (instead of List[ClsDataSample])
  • In the metrics, the input data_sample may have ground truth value and predictions or only predictions, we are checking each data_sample one by one

Please share your thoughts

@piercus
Copy link
Contributor Author

piercus commented Dec 9, 2022

@mzr1996 an eval_mask has been added please share your feedback

mmcls/models/heads/multi_task_head.py Outdated Show resolved Hide resolved
Co-authored-by: Ma Zerun <mzr1996@163.com>
@mzr1996 mzr1996 changed the base branch from 1.x to dev-1.x December 20, 2022 08:34
@mzr1996 mzr1996 changed the title 1.x Multi task [Feature] Support Multi-task. Dec 20, 2022
@mzr1996 mzr1996 merged commit bac181f into open-mmlab:dev-1.x Dec 30, 2022
@piercus
Copy link
Contributor Author

piercus commented Mar 21, 2023

Thanks @marouaneamz for your work on this ! This has been a great internship :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants