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

Revert #3579 #3753

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/otx/core/data/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import torch
from datumaro import Dataset as DmDataset
from datumaro import Environment
from lightning import LightningDataModule
from omegaconf import DictConfig, OmegaConf
from torch.utils.data import DataLoader, RandomSampler
Expand Down Expand Up @@ -60,18 +59,6 @@ def __init__(

VIDEO_EXTENSIONS.append(".mp4")

# Data Format Check
available_data_formats = Environment().detect_dataset(str(self.config.data_root))
if not available_data_formats:
msg = f"Invalid data root: {self.config.data_root}. Please check if the data root is valid."
raise ValueError(msg)
if self.config.data_format not in available_data_formats:
log.warning(
f"Invalid data format: {self.config.data_format}. Available formats: {available_data_formats} "
f"Replace data_format: {self.config.data_format} -> {available_data_formats[0]}.",
)
self.config.data_format = available_data_formats[0]

dataset = DmDataset.import_from(self.config.data_root, format=self.config.data_format)
if self.task != "H_LABEL_CLS":
ignore_index = self.config.ignore_index if self.task == "SEMANTIC_SEGMENTATION" else None
Expand Down
37 changes: 0 additions & 37 deletions tests/unit/core/data/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from unittest.mock import MagicMock, patch

import pytest
from datumaro.components.environment import Environment
from importlib_resources import files
from lightning.pytorch.loggers import CSVLogger
from omegaconf import DictConfig, OmegaConf
Expand Down Expand Up @@ -155,39 +154,3 @@ def test_hparams_initial_is_loggable(

hparams_path = Path(logger.log_dir) / "hparams.yaml"
assert hparams_path.exists()

@patch("otx.core.data.module.OTXDatasetFactory.create")
@patch("otx.core.data.module.DmDataset.import_from")
def test_data_format_check(
self,
mock_dm_dataset,
fxt_config,
mocker,
caplog,
) -> None:
fxt_config.mem_cache_size = "0GB"
fxt_config.tile_config.enable_tiler = False
# Our query for subset name for train, val, test
fxt_config.train_subset.subset_name = "train_1"
fxt_config.val_subset.subset_name = "val_1"
fxt_config.test_subset.subset_name = "test_1"
fxt_config.unlabeled_subset.data_root = None

# Dataset will have "train_0", "train_1", "val_0", ..., "test_1" subsets
mock_dm_subsets = {f"{name}_{idx}": MagicMock() for name in ["train", "val", "test"] for idx in range(2)}
mock_dm_dataset.return_value.subsets.return_value = mock_dm_subsets

mocker.patch("otx.core.data.module.pre_filtering", side_effect=mock_data_filtering)

with patch.object(Environment, "detect_dataset", return_value=["voc", "voc_classification"]):
# with pytest.raises(ValueError, match="Invalid data root:"):
OTXDataModule(task="MULTI_LABEL_CLS", config=fxt_config)

assert "Invalid data format:" in caplog.text
assert "Replace data_format:" in caplog.text

with patch.object(Environment, "detect_dataset", return_value=[]), pytest.raises(
ValueError,
match="Invalid data root:",
):
OTXDataModule(task="MULTI_LABEL_CLS", config=fxt_config)
Loading