-
Notifications
You must be signed in to change notification settings - Fork 462
Enable FeatureVectorHook for action tasks #2408
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
Merged
jaegukhyun
merged 5 commits into
open-edge-platform:develop
from
jaegukhyun:feature-hook-action
Aug 1, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,15 +64,11 @@ class MockModel(nn.Module): | |
|
|
||
| def __init__(self, task_type): | ||
| super().__init__() | ||
| self.module = MockModule() | ||
| self.module.backbone = MockModule() | ||
| self.backbone = MockModule() | ||
| self.task_type = task_type | ||
|
|
||
| def forward(self, return_loss: bool, imgs: DatasetItemEntity): | ||
| forward_hooks = list(self.module.backbone._forward_hooks.values()) | ||
| for hook in forward_hooks: | ||
| hook(1, 2, 3) | ||
| feat = self.backbone(torch.randn(1, 400, 8, 7, 7)) # bs, channel, video_len, h, w | ||
| if self.task_type == "cls": | ||
| return np.array([[0, 0, 1]]) | ||
| return [[np.array([[0, 0, 1, 1, 0.1]]), np.array([[0, 0, 1, 1, 0.2]]), np.array([[0, 0, 1, 1, 0.7]])]] | ||
|
|
@@ -96,6 +92,9 @@ def evaluate(self, prediction, *args, **kwargs): | |
| else: | ||
| return {"[email protected]": 1.0} | ||
|
|
||
| def __len__(self): | ||
| return len(self.dataset) | ||
|
|
||
|
|
||
| class MockDataLoader: | ||
| """Mock class for data loader.""" | ||
|
|
@@ -130,6 +129,10 @@ def export(self): | |
| f.write(dummy_data) | ||
|
|
||
|
|
||
| def return_model(model, *args, **kwargs): | ||
| return model | ||
|
|
||
|
|
||
| class TestMMActionTask: | ||
| """Test class for MMActionTask. | ||
|
|
||
|
|
@@ -198,7 +201,7 @@ def test_train(self, mocker) -> None: | |
| mocker.patch.object(MMActionTask, "get_model_ckpt", return_value="fake_weight") | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.build_data_parallel", | ||
| return_value=MockModel("cls"), | ||
| side_effect=return_model, | ||
| ) | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.train_model", | ||
|
|
@@ -217,7 +220,7 @@ def test_train(self, mocker) -> None: | |
| _config = ModelConfiguration(ActionConfig(), self.cls_label_schema) | ||
| output_model = ModelEntity(self.cls_dataset, _config) | ||
| self.cls_task.train(self.cls_dataset, output_model) | ||
| output_model.performance == 1.0 | ||
| assert output_model.performance.score.value == 1.0 | ||
| assert self.cls_task._recipe_cfg.data.workers_per_gpu == num_cpu // num_gpu # test adaptive num_workers | ||
|
|
||
| mocker.patch( | ||
|
|
@@ -231,12 +234,12 @@ def test_train(self, mocker) -> None: | |
| mocker.patch.object(MMActionTask, "build_model", return_value=MockModel("det")) | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.build_data_parallel", | ||
| return_value=MockModel("det"), | ||
| side_effect=return_model, | ||
| ) | ||
| _config = ModelConfiguration(ActionConfig(), self.det_label_schema) | ||
| output_model = ModelEntity(self.det_dataset, _config) | ||
| self.det_task.train(self.det_dataset, output_model) | ||
| output_model.performance == 1.0 | ||
| assert output_model.performance.score.value == 1.0 | ||
| assert self.cls_task._recipe_cfg.data.workers_per_gpu == num_cpu // num_gpu # test adaptive num_workers | ||
|
|
||
| @e2e_pytest_unit | ||
|
|
@@ -261,7 +264,7 @@ def test_infer(self, mocker) -> None: | |
| mocker.patch.object(MMActionTask, "build_model", return_value=MockModel("cls")) | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.build_data_parallel", | ||
| return_value=MockModel("cls"), | ||
| side_effect=return_model, | ||
| ) | ||
|
|
||
| inference_parameters = InferenceParameters(is_evaluation=True) | ||
|
|
@@ -280,7 +283,7 @@ def test_infer(self, mocker) -> None: | |
| mocker.patch.object(MMActionTask, "build_model", return_value=MockModel("det")) | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.build_data_parallel", | ||
| return_value=MockModel("det"), | ||
| side_effect=return_model, | ||
| ) | ||
| inference_parameters = InferenceParameters(is_evaluation=True) | ||
| outputs = self.det_task.infer(self.det_dataset, inference_parameters) | ||
|
|
@@ -397,7 +400,7 @@ def test_geti_scenario(self, mocker): | |
| mocker.patch.object(MMActionTask, "get_model_ckpt", return_value="fake_weight") | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.build_data_parallel", | ||
| return_value=MockModel("cls"), | ||
| side_effect=return_model, | ||
| ) | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.train_model", | ||
|
|
@@ -428,7 +431,7 @@ def test_geti_scenario(self, mocker): | |
| mocker.patch.object(MMActionTask, "build_model", return_value=MockModel("cls")) | ||
| mocker.patch( | ||
| "otx.algorithms.action.adapters.mmaction.task.build_data_parallel", | ||
| return_value=MockModel("cls"), | ||
| side_effect=return_model, | ||
| ) | ||
|
|
||
| inference_parameters = InferenceParameters(is_evaluation=True) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.