Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KGallyamov committed Sep 1, 2024
1 parent 7345e74 commit f10443e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
6 changes: 3 additions & 3 deletions config/datasets/detection-3d/lep_3d_dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ _target_: innofw.core.integrations.mmdetection.datamodule.Mmdetection3DDataModul

train:
source: https://api.blackhole.ai.innopolis.university/public-datasets/lep_3d_detection/train.zip
target: /home/karim/workdir/innofw/data/lep3d
target: ./data/lep3d

test:
source: https://api.blackhole.ai.innopolis.university/public-datasets/lep_3d_detection/test.zip
target: /home/karim/workdir/innofw/data/lep3d
target: ./data/lep3d

infer:
source: https://api.blackhole.ai.innopolis.university/public-datasets/lep_3d_detection/test.zip
target: /home/karim/workdir/innofw/data/lep3d
target: ./data/lep3d

num_workers: 8

Expand Down
1 change: 1 addition & 0 deletions innofw/core/integrations/mmdetection/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
target_maxes = np.array([[136.7853946685791, 135.2938232421875, 45.29965019226074]])
target_mins = np.array([[-136.7853946685791, -135.2938232421875, -45.29965019226074]])


class Mmdetection3DDataModuleAdapter(BaseDataModule, ABC):
"""
...
Expand Down
5 changes: 3 additions & 2 deletions innofw/core/integrations/mmdetection/model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def predict(self, data, ckpt_path=None):


def setup_mmdetection():
logging.info('mmdetection-3d found')
if os.path.exists('../mmdetection3d'):
logging.info('mmdetection-3d found')
os.environ['MMDET_FOR_INNOFW'] = os.path.join(Path(os.getcwd()).parent, 'mmdetection3d')
if 'MMDET_FOR_INNOFW' not in os.environ:
logging.info("Cloning mmdetection-3d")
Expand All @@ -138,5 +138,6 @@ def setup_mmdetection():

return os.environ['MMDET_FOR_INNOFW']


def map_optimizer_to_mmdet_optim(optim_name):
return {'adam': 'Adam', 'adamw': 'AdamW', 'sgd': 'SGD'}[optim_name]
return {'adam': 'Adam', 'adamw': 'AdamW', 'sgd': 'SGD'}[optim_name]
4 changes: 4 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
python -m pip install -U openmim
mim install mmengine
mim install 'mmcv>=2.0.0rc4'
mim install 'mmdet>=3.0.0'
export PYTHONPATH=.
python -m pytest --cov=innofw --cov-report=xml --junitxml=out_report.xml --cov-fail-under=10 # not percents
if [ $? -ne 0 ]; then
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/config/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
trainer_cfg_w_gpu_devices_1 = base_trainer_on_gpu_cfg.copy()
trainer_cfg_w_gpu_devices_1["devices"] = 1

trainer_cfg_w_gpu_devices_0 = base_trainer_on_gpu_cfg.copy()
trainer_cfg_w_gpu_devices_0["devices"] = 0

# case: accelerator = 'gpu', devices = 2 # uses two gpu devices
trainer_cfg_w_gpu_devices_2 = base_trainer_on_gpu_cfg.copy()
trainer_cfg_w_gpu_devices_2["devices"] = 2
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import shutil

from omegaconf import DictConfig

from innofw.constants import Stages
from innofw.core.integrations.mmdetection.datamodule import Mmdetection3DDataModuleAdapter
from innofw.core.integrations.mmdetection.model_adapter import Mmdetection3DDataModel, \
BaseMmdetModel
from tests.fixtures.config import optimizers as fixt_optimizers
from tests.fixtures.config import trainers as fixt_trainers


def test_integration():
data_path = {
'source': 'https://api.blackhole.ai.innopolis.university/public-datasets/lep_3d_detection/test.zip',
'target': './tmp'}
datamodule = Mmdetection3DDataModuleAdapter(data_path, data_path, data_path, 4)
datamodule.setup_train_test_val()
datamodule.setup_infer()
assert datamodule.predict_dataloader() is None
assert datamodule.train_dataloader() is None
assert datamodule.test_dataloader() is None
assert datamodule.save_preds(None, Stages.test, '') is None

optimizer_cfg = DictConfig(fixt_optimizers.adam_optim_w_target)
model = Mmdetection3DDataModel(BaseMmdetModel(), './tmp/logs',
fixt_trainers.trainer_cfg_w_gpu_devices_0,
optimizers_cfg=optimizer_cfg)
model.train(datamodule)
ckpt_path = model.mmdet_path + '/work_dirs/pointpillars_hv_secfpn_8xb6_custom/epoch_10.pth'
model.test(datamodule, ckpt_path=ckpt_path)
model.predict(datamodule, ckpt_path=ckpt_path)

for i in range(3):
try:
shutil.rmtree('./tmp')
break
except:
pass

0 comments on commit f10443e

Please sign in to comment.