Spaces:
Paused
Paused
| """ | |
| Development configuration and utilities for Forest Fire Detection project | |
| """ | |
| import json | |
| from pathlib import Path | |
| from typing import Dict, Any | |
| class Config: | |
| """Project configuration management""" | |
| def __init__(self): | |
| self.project_root = Path.cwd() | |
| self.data_dir = self.project_root / "data" | |
| self.models_dir = self.project_root / "models" | |
| self.assets_dir = self.project_root / "assets" | |
| self.notebooks_dir = self.project_root / "notebooks" | |
| self.src_dir = self.project_root / "src" | |
| # Load or create configuration | |
| self.config_path = self.project_root / "config.json" | |
| self.load_config() | |
| def load_config(self) -> Dict[str, Any]: | |
| """Load configuration from file or create default""" | |
| if self.config_path.exists(): | |
| with open(self.config_path, 'r') as f: | |
| self.config = json.load(f) | |
| else: | |
| self.config = self._get_default_config() | |
| self.save_config() | |
| return self.config | |
| def _get_default_config(self) -> Dict[str, Any]: | |
| """Get default project configuration""" | |
| return { | |
| "project_name": "Forest Fire Detection using FirenetCNN and XAI Techniques", | |
| "version": "1.0.0", | |
| "description": "Detect and classify forest fires with explainable AI", | |
| "model": { | |
| "input_size": [224, 224], | |
| "num_classes": 3, | |
| "class_labels": ["fire", "no_fire", "smoke"], | |
| "reverse_class_map": {"fire": 0, "no_fire": 1, "smoke": 2} | |
| }, | |
| "gradcam": { | |
| "target_layer": "out_relu", | |
| "alpha": 0.5, | |
| "colormap": "cv2.COLORMAP_JET" | |
| }, | |
| "app": { | |
| "title": "Forest Fire Detection - FirenetCNN", | |
| "port": 7860, | |
| "share": True | |
| }, | |
| "paths": { | |
| "data_dir": "data", | |
| "models_dir": "models", | |
| "assets_dir": "assets", | |
| "notebooks_dir": "notebooks", | |
| "src_dir": "src" | |
| } | |
| } | |
| def save_config(self) -> None: | |
| """Save configuration to file""" | |
| with open(self.config_path, 'w') as f: | |
| json.dump(self.config, f, indent=2) | |
| def get_model_paths(self) -> Dict[str, str]: | |
| """Get all model file paths""" | |
| return { | |
| "modern": str(self.models_dir / "FirenetCNN.keras"), | |
| "legacy": str(self.models_dir / "FirenetCNN1.h5"), | |
| "alternative": str(self.models_dir / "firenet_model.h5") | |
| } | |
| def setup_directories(self) -> None: | |
| """Create necessary directories""" | |
| directories = [ | |
| self.models_dir, | |
| self.assets_dir, | |
| self.notebooks_dir, | |
| self.src_dir, | |
| self.data_dir | |
| ] | |
| for directory in directories: | |
| directory.mkdir(parents=True, exist_ok=True) | |
| def validate_environment(self) -> bool: | |
| """Validate that required files and directories exist""" | |
| required_items = [ | |
| self.notebooks_dir / "Fire_PredCopy.ipynb" | |
| ] | |
| for item in required_items: | |
| if not item.exists(): | |
| print(f"β οΈ Warning: Required item not found: {item}") | |
| return all(item.exists() for item in required_items) | |
| def print_summary(self) -> None: | |
| """Print project structure summary""" | |
| print("=" * 60) | |
| print(f"π {self.config['project_name']}") | |
| print("=" * 60) | |
| print(f"π Version: {self.config['version']}") | |
| print(f"π Description: {self.config['description']}") | |
| print() | |
| print("π Project Structure:") | |
| print(f" β’ Models: {self.models_dir}/") | |
| print(f" β’ Assets: {self.assets_dir}/") | |
| print(f" β’ Notebooks: {self.notebooks_dir}/") | |
| print(f" β’ Source: {self.src_dir}/") | |
| print(f" β’ Data: {self.data_dir}/") | |
| print() | |
| print("π§ Key Features:") | |
| print(" β’ FirenetCNN (MobileNetV2 based)") | |
| print(" β’ Grad-CAM Explainable AI") | |
| print(" β’ Gradio Web Interface") | |
| print(" β’ Image & Video Analysis") | |
| print(" β’ Model Conversion Tools") | |
| print(" β’ Full Documentation") | |
| print("=" * 60) | |
| if __name__ == "__main__": | |
| config = Config() | |
| config.print_summary() | |