Spaces:
Paused
Paused
File size: 4,553 Bytes
1feed70 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | """
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()
|