Skip to content

Commit

Permalink
Create config boilerplate for apps (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolgheroni authored Sep 9, 2024
2 parents 9965845 + 76953c9 commit e22d3c8
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 23 deletions.
17 changes: 0 additions & 17 deletions src/spira_training/apps/feature_engineering/app/app.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pathlib import Path

from pydantic import BaseModel

class DatasetPaths(BaseModel):
patients_csv: Path
controls_csv: Path
noises_csv: Path

class AudioConfig(BaseModel):
dataset_paths: DatasetPaths
hop_length: int
normalize: bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pydantic import BaseModel


class AudioFeatureTransformerOptions(BaseModel):
use_noise: bool
use_overlapping: bool
use_padding: bool
use_mixture: bool

class NoisyAudioFeatureTransformerConfig(BaseModel):
num_noise_control: int
num_noise_patient: int
noise_max_amp: float
noise_min_amp: float

class OverlappedAudioFeatureTransformerConfig(BaseModel):
window_length: int
step_size: int

class MixedAudioFeatureTransformerConfig(BaseModel):
alpha: float
beta: float

class AudioFeatureTransformersCollection(BaseModel):
noisy_audio: NoisyAudioFeatureTransformerConfig
overlapped_audio: OverlappedAudioFeatureTransformerConfig
mixed_audio: MixedAudioFeatureTransformerConfig

class AudioFeatureTransformerConfig(BaseModel):
options: AudioFeatureTransformerOptions
audio_feature_transformers: AudioFeatureTransformersCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from pydantic import BaseModel


class AudioProcessorType(BaseModel):
MFCC = "mfcc"
SPECTROGRAM = "spectrogram"
MELSPECTROGRAM = "melspectrogram"

class MFCCAudioProcessorConfig:
sample_rate: int
num_mels: int
num_mfcc: int
log_mels: bool
n_fft: int
win_length: int

class SpectrogramAudioProcessorConfig:
sample_rate: int
num_mels: int
mel_fmin: float
mel_fmax: None
num_mfcc: int
log_mels: bool
n_fft: int
num_freq: int
win_length: int

class MelspectrogramAudioProcessorConfig:
sample_rate: int
num_mels: int
mel_fmin: float
mel_fmax: None
num_mfcc: int
log_mels: bool
n_fft: int
num_freq: int
win_length: int

class AudioProcessorConfig(BaseModel):
feature_type: AudioProcessorType
mfcc: MFCCAudioProcessorConfig
spectrogram: SpectrogramAudioProcessorConfig
melspectrogram: MelspectrogramAudioProcessorConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pydantic import BaseModel

from audio_config import AudioConfig
from audio_processor_config import AudioProcessorConfig
from audio_feature_transformer_config import AudioFeatureTransformerConfig

class FeatureEngineeringConfig(BaseModel):
audio: AudioConfig
audio_processor: AudioProcessorConfig
audio_feature_transformer: AudioFeatureTransformerConfig
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from src.spira_training.apps.feature_engineering.app.app import App
from src.spira_training.shared.core.services.feature_engineering_service import FeatureEngineeringService
from src.spira_training.shared.core.services.randomizer import Randomizer
from src.spira_training.shared.ports.config_loader import ConfigLoader
from src.spira_training.shared.ports.dataset_repository import DatasetRepository


def main():
config = ConfigLoader.load()
randomizer = Randomizer.initialize_random()
dataset_repository = DatasetRepository()
service = FeatureEngineeringService(config, randomizer, dataset_repository)

app = App(config, randomizer, dataset_repository)
app.execute()
service.execute()

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ModelEvaluationConfig():
pass
2 changes: 2 additions & 0 deletions src/spira_training/apps/model_publish/model_publish_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ModelPublishConfig:
pass
10 changes: 9 additions & 1 deletion src/spira_training/shared/core/models/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
from src.spira_training.apps.feature_engineering.configs.feature_engineering_config import FeatureEngineeringConfig
from src.spira_training.apps.model_evaluation.model_evaluation_config import ModelEvaluationConfig
from src.spira_training.apps.model_publish.model_publish_config import ModelPublishConfig


class Config:
pass
feature_engineering_config: FeatureEngineeringConfig
model_trainer_config: ModelTrainerConfig
model_evaluation_config: ModelEvaluationConfig
model_publish_config: ModelPublishConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from src.spira_training.apps.feature_engineering.configs.feature_engineering_config import FeatureEngineeringConfig
from src.spira_training.shared.core.interfaces.random import Random
from src.spira_training.shared.ports import dataset_repository
from src.spira_training.shared.ports.dataset_repository import DatasetRepository

class FeatureEngineeringService:
def __init__(self, config: FeatureEngineeringConfig, randomizer: Random, dataset_repository: DatasetRepository):
self.config = config
self.randomizer = randomizer
self.dataset_repository = dataset_repository

def execute(self) -> None:
patients_inputs, controls_inputs, noises = self._load_data(self.config)
dataset = self._generate_dataset(self.config, self.randomizer, patients_inputs, controls_inputs, noises)
dataset_repository.save_dataset(dataset, self.config.paths.dataset)

def _load_data(self, config: FeatureEngineeringConfig):
pass

def _generate_dataset(self):
pass

0 comments on commit e22d3c8

Please sign in to comment.