Skip to content

Commit

Permalink
Add from gitlab (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
benemer authored Mar 5, 2024
1 parent 19f75e6 commit 99ccf5e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
]
license_files = "LICENSE"
dependencies = [
"kiss-icp>=0.2.10",
"kiss-icp>=0.3.0",
"diskcache>=5.3.0",
"pytorch_lightning>=1.6.4",
]
Expand All @@ -30,8 +30,7 @@ Homepage = "https://github.com/PRBonn/MapMOS"

[build-system]
requires = [
"scikit_build_core>=0.3.3",
"pybind11",
"scikit_build_core","pybind11",
]
build-backend = "scikit_build_core.build"

Expand Down
44 changes: 25 additions & 19 deletions src/mapmos/config/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
# NOTE: This module was contributed by Markus Pielmeier on PR #63
from __future__ import annotations

import yaml
import importlib
import sys

from pathlib import Path
from typing import Any, Dict, Optional

from pydantic import BaseSettings, PrivateAttr
from pydantic_settings import BaseSettings

from mapmos.config.config import (
DataConfig,
Expand All @@ -43,31 +45,35 @@ class MapMOSConfig(BaseSettings):
odometry: OdometryConfig = OdometryConfig()
mos: MOSConfig = MOSConfig()
training: TrainingConfig = TrainingConfig()
_config_file: Optional[Path] = PrivateAttr()

def __init__(self, config_file: Optional[Path] = None, *args, **kwargs):
self._config_file = config_file
super().__init__(*args, **kwargs)

def _yaml_source(self) -> Dict[str, Any]:
data = None
if self._config_file is not None:
with open(self._config_file) as cfg_file:
data = yaml.safe_load(cfg_file)
return data or {}

class Config:
@classmethod
def customise_sources(cls, init_settings, env_settings, file_secret_settings):
return init_settings, MapMOSConfig._yaml_source
def _yaml_source(config_file: Optional[Path]) -> Dict[str, Any]:
data = None
if config_file is not None:
try:
yaml = importlib.import_module("yaml")
except ModuleNotFoundError:
print(
"Custom configuration file specified but PyYAML is not installed on your system,"
' run `pip install "kiss-icp[all]"`. You can also modify the config.py if your '
"system does not support PyYaml "
)
sys.exit(1)
with open(config_file) as cfg_file:
data = yaml.safe_load(cfg_file)
return data or {}


def load_config(config_file: Optional[Path]) -> MapMOSConfig:
"""Load configuration from an Optional yaml file."""
config = MapMOSConfig(config_file=config_file)
config = MapMOSConfig(**_yaml_source(config_file))
return config


def write_config(config: MapMOSConfig, filename: str):
with open(filename, "w") as outfile:
yaml.dump(config.dict(), outfile, default_flow_style=False)
try:
yaml = importlib.import_module("yaml")
yaml.dump(config.model_dump(), outfile, default_flow_style=False)
except ModuleNotFoundError:
outfile.write(str(config.model_dump()))
4 changes: 2 additions & 2 deletions src/mapmos/datasets/mapmos_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ def get_scan_and_map(
scan_labels = scan_labels[valid_mask]

if self.sequence != sequence:
data_config = DataConfig().parse_obj(data_config_dict)
odometry_config = OdometryConfig().parse_obj(odometry_config_dict)
data_config = DataConfig().model_validate(data_config_dict)
odometry_config = OdometryConfig().model_validate(odometry_config_dict)

self.odometry = Odometry(data_config, odometry_config)
self.gt_map = VoxelHashMap(odometry_config.voxel_size, data_config.max_range)
Expand Down

0 comments on commit 99ccf5e

Please sign in to comment.