Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKalema committed May 28, 2024
1 parent d6b0de0 commit 342395a
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ cython_debug/
#.idea/

# static
artifacts/
artifacts/

# Pytest stuff
*.xml
5 changes: 4 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def display_intro(self) -> None:
""")

def run(self) -> None:
"""Run the app"""
"""
Run the app
"""

self.load_model()
self.display_intro()
Expand Down
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ def execute_pipeline_stage(stage_name: str, pipeline_obj: object) -> None:
STAGE_NAME = "MODEL EVALUATION"
obj = EvaluationPipeline()
execute_pipeline_stage(STAGE_NAME, obj)

42 changes: 30 additions & 12 deletions research/01_data_ingestion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -107,21 +107,39 @@
" self.config = read_yaml(config_filepath)\n",
" self.params = read_yaml(params_filepath)\n",
"\n",
" create_directories([self.config.artifacts_root])\n",
" # create_directories([self.config.artifacts_root])\n",
" \n",
" def get_data_ingestion_config(self) -> DataIngestionConfig:\n",
" config = self.config.data_ingestion\n",
" # def get_data_ingestion_config(self) -> DataIngestionConfig:\n",
" # config = self.config.data_ingestion\n",
"\n",
" create_directories([config.root_dir])\n",
" # create_directories([config.root_dir])\n",
"\n",
" data_ingestion_config = DataIngestionConfig(\n",
" root_dir=config.root_dir,\n",
" source_URL=config.source_URL,\n",
" local_data_file=config.local_data_file,\n",
" unzip_dir=config.unzip_dir\n",
" )\n",
" # data_ingestion_config = DataIngestionConfig(\n",
" # root_dir=config.root_dir,\n",
" # source_URL=config.source_URL,\n",
" # local_data_file=config.local_data_file,\n",
" # unzip_dir=config.unzip_dir\n",
" # )\n",
"\n",
" return data_ingestion_config"
" # return data_ingestion_config"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2024-05-28 13:04:49,790: INFO: common:33: yaml file: config/config.yaml loaded successfully]\n",
"[2024-05-28 13:04:49,799: INFO: common:33: yaml file: params.yaml loaded successfully]\n"
]
}
],
"source": [
"config = ConfigurationManager()"
]
},
{
Expand Down
11 changes: 0 additions & 11 deletions setup.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/potholeClassifier/components/data_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, config: DataIngestionConfig) -> None:
Args:
config (DataIngestionConfig): Configuration object for data ingestion.
Returns:
Returns:
None
"""
self.config = config
Expand Down
19 changes: 8 additions & 11 deletions src/potholeClassifier/components/model_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, config: EvaluationConfig) -> None:
Args:
config (EvaluationConfig): Configuration object containing evaluation parameters.
Returns:
Returns:
None
"""
self.config = config
Expand All @@ -39,7 +39,7 @@ def _validation_generator(self) -> None:
Args:
None
Returns:
Returns:
None
"""
datagenerator_kwargs = dict(
Expand All @@ -52,8 +52,7 @@ def _validation_generator(self) -> None:
)

validation_datagenerator = tf.keras.preprocessing.image.ImageDataGenerator(
**datagenerator_kwargs
)
**datagenerator_kwargs)

self.validation_data = validation_datagenerator.flow_from_directory(
directory=self.config.training_data,
Expand All @@ -75,45 +74,43 @@ def _load_model(path: Path) -> tf.keras.Model:
tf.keras.Model: Loaded machine learning model.
"""
return tf.keras.models.load_model(path)

def _save_score(self) -> None:
"""
Saves the evaluation score to a JSON file.
Args:
None
Returns:
Returns:
None
"""
scores = {"loss": self.score[0], "accuracy": self.score[1]}
save_json(path=Path("scores.json"), data=scores)


def evaluation(self) -> None:
"""
Performs evaluation of the loaded model using validation data.
Args:
None
Returns:
Returns:
None
"""
self.model = self.load_model(self.config.path_of_model)
self._validation_generator()
self.score = self.model.evaluate(self.validation_data)
self._save_score()


def log_into_mlflow(self) -> None:
"""
Logs evaluation metrics and the model into MLflow.
Args:
None
Returns:
Returns:
None
"""
mlflow.set_registry_uri(self.config.mlflow_uri)
Expand Down
8 changes: 4 additions & 4 deletions src/potholeClassifier/components/model_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, config: TrainingConfig) -> None:
Args:
config (TrainingConfig): The configuration for training the model.
Returns:
Returns:
None
"""
self.config = config
Expand All @@ -43,7 +43,7 @@ def get_base_model(self) -> None:
Args:
None
Returns:
Returns:
None
"""
self.model = tf.keras.models.load_model(
Expand All @@ -60,7 +60,7 @@ def train_valid_generator(self) -> None:
Args:
None
Returns:
Returns:
None
"""

Expand Down Expand Up @@ -109,7 +109,7 @@ def train(self) -> None:
Args:
callback_list (list): A list of callbacks to be used during training.
Returns:
Returns:
None
"""
self.steps_per_epoch = self.train_generator.samples // self.train_generator.batch_size
Expand Down
6 changes: 3 additions & 3 deletions src/potholeClassifier/components/prepare_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, config: PrepareBaseModelConfig) -> None:
Args:
config (PrepareBaseModelConfig): The configuration for preparing base models.
Returns:
Returns:
None
"""
self.config = config
Expand Down Expand Up @@ -78,8 +78,8 @@ def _save_model(path: Path, model: tf.keras.Model) -> None:
Args:
path (Path): The path where the model will be saved.
model (tf.keras.Model): The model to be saved.
Returns:
Returns:
None
"""
model.save(path)
Expand Down
2 changes: 2 additions & 0 deletions src/potholeClassifier/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
from typing import Any
import base64
from io import BytesIO
from PIL import Image


@ensure_annotations
Expand Down

0 comments on commit 342395a

Please sign in to comment.