Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
443 changes: 443 additions & 0 deletions AI_DEVELOPMENT_REQUIREMENTS.md

Large diffs are not rendered by default.

378 changes: 378 additions & 0 deletions AI_IMPLEMENTATION_ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,378 @@
"""
AutoFire AI Implementation Roadmap
==================================

CRITICAL PATH for AI to develop AutoFire correctly - prioritized by immediate blocking needs.

Phase 1: IMMEDIATE BLOCKERS (Week 1)
====================================

1. OCR Integration
-----------------
CRITICAL: Without OCR, AI cannot read title blocks or scale information.

Required Implementation:
```python
import pytesseract
import easyocr

def extract_title_block_text(self, image_region):
# Multiple OCR engines for reliability
tesseract_result = pytesseract.image_to_string(image_region)
easyocr_result = easyocr.Reader(['en']).readtext(image_region)
return self._combine_ocr_results(tesseract_result, easyocr_result)

def extract_scale_information(self, text):
# Regex patterns for scale detection
scale_patterns = [
r'1/8"?\s*=\s*1\'-0"?', # 1/8" = 1'-0"
r'1/4"?\s*=\s*1\'-0"?', # 1/4" = 1'-0"
r'1"?\s*=\s*\d+\'?', # 1" = 10'
r'1:\d+' # 1:100
]
# Implementation needed
```

Installation Command:
```bash
pip install pytesseract easyocr
# Also need Tesseract binary: choco install tesseract (Windows)
```

1a. CAD Layer Intelligence (CRITICAL ADDITION)
----------------------------------------------
GAME CHANGER: Reading CAD layers provides precise element classification vs visual guessing.

Required Implementation:
```python
import ezdxf
import dxfgrabber

class LayerIntelligenceEngine:
def extract_fire_safety_by_layers(self, cad_file):
"""
BREAKTHROUGH: Extract devices by layer analysis
- E-FIRE layer = fire alarm devices with exact coordinates
- E-SPKR layer = sprinkler systems with precise placement
- E-LITE layer = emergency lighting with locations
Much more accurate than visual detection!
"""
doc = ezdxf.readfile(cad_file)
fire_devices = {}

# Target fire safety layers
target_layers = ["E-FIRE", "E-SPKR", "E-LITE", "E-SECU"]

for layer_name in target_layers:
if layer_name in doc.layers:
devices = []
msp = doc.modelspace()

# Extract block references (symbols) on this layer
for entity in msp.query(f'*[layer=="{layer_name}"]'):
if entity.dxftype() == 'INSERT':
device = {
"type": self._classify_device_by_block(entity.dxf.name),
"coordinates": (entity.dxf.insert.x, entity.dxf.insert.y),
"block_name": entity.dxf.name,
"layer": layer_name,
"nfpa_compliant": self._check_nfpa_placement(entity)
}
devices.append(device)

fire_devices[layer_name] = devices

return fire_devices

def analyze_layer_hierarchy(self, cad_file):
"""Understand drawing organization through layer structure."""
doc = ezdxf.readfile(cad_file)
layer_analysis = {}

for layer_name in doc.layers:
layer_info = doc.layers.get(layer_name)
element_count = len(list(doc.modelspace().query(f'*[layer=="{layer_name}"]')))

layer_analysis[layer_name] = {
"element_count": element_count,
"color": layer_info.color,
"line_weight": layer_info.lineweight,
"purpose": self._classify_layer_purpose(layer_name),
"fire_safety_relevance": self._assess_fire_relevance(layer_name)
}

return layer_analysis
```

Benefits of Layer Intelligence:
- **Exact Device Counts**: No more 656 smoke detectors - count actual CAD blocks
- **Precise Coordinates**: Real CAD coordinates vs visual estimation
- **Professional Classification**: Know device types from CAD block names
- **Layer-based Validation**: Check if devices are on correct layers
- **Industry Standards**: Match AIA layer naming conventions

2. Fire Safety Symbol Templates
------------------------------
CRITICAL: AutoFire's core purpose requires fire safety device recognition.

Required Symbol Library:
```python
# These need to be actual image templates
FIRE_SAFETY_SYMBOLS = {
"smoke_detector": [
"smoke_detector_ceiling.png",
"smoke_detector_wall.png",
"smoke_detector_beam.png"
],
"sprinkler_head": [
"sprinkler_pendant.png",
"sprinkler_upright.png",
"sprinkler_sidewall.png"
],
"manual_pull_station": [
"pull_station_standard.png",
"pull_station_ada.png"
],
"horn_strobe": [
"horn_strobe_wall.png",
"horn_strobe_ceiling.png"
]
}
```

Source Requirements:
- NFPA symbol standards
- Major fire alarm manufacturer symbols (Simplex, Notifier, EST)
- CAD block libraries

3. NFPA 72 Validation Core
-------------------------
CRITICAL: Device placement validation against fire codes.

Required Implementation:
```python
class NFPA72Validator:
def validate_smoke_detector_spacing(self, room_area, ceiling_height):
"""
NFPA 72: Maximum 30ft spacing for smooth ceilings
Reduced spacing for sloped or beamed ceilings
"""
max_spacing = 30 # feet
if ceiling_height > 10:
max_spacing *= 0.9 # Reduce for high ceilings

coverage_area = max_spacing * max_spacing
required_detectors = math.ceil(room_area / coverage_area)
return required_detectors

def check_coverage_areas(self, detectors, room_polygon):
"""Verify no dead zones in coverage"""
# Implementation needed
pass
```

Phase 2: CORE FUNCTIONALITY (Week 2-3)
======================================

1. Room Segmentation Fix
-----------------------
Current Issue: Detects entire page as one room instead of individual spaces.

Solution Approach:
```python
def segment_individual_rooms(self, wall_lines, door_openings):
"""
Use flood-fill algorithm from multiple seed points
Stop at wall boundaries, continue through door openings
"""
# Convert walls to binary mask
wall_mask = self._create_wall_mask(wall_lines)

# Remove door openings from wall mask
for door in door_openings:
wall_mask = self._remove_door_from_mask(wall_mask, door)

# Flood fill from multiple seed points
rooms = []
for seed_point in self._generate_seed_points(wall_mask):
room_mask = self._flood_fill_room(wall_mask, seed_point)
if self._is_valid_room_size(room_mask):
rooms.append(room_mask)

return rooms
```

2. Scale Detection System
------------------------
Convert pixel measurements to real-world dimensions.

Implementation:
```python
def calibrate_scale_from_drawing(self, image, title_block):
"""
Priority order:
1. Title block scale notation
2. Dimension callouts on drawing
3. Standard element recognition (doors ~3ft)
"""
# Try title block first
scale_from_title = self._extract_scale_from_title(title_block)
if scale_from_title:
return scale_from_title

# Try dimension analysis
dimensions = self._detect_dimension_callouts(image)
if dimensions:
return self._calibrate_from_dimensions(dimensions)

# Fall back to standard elements
doors = self._detect_door_symbols(image)
return self._calibrate_from_standard_doors(doors)
```

Phase 3: ML ENHANCEMENT (Week 4-6)
==================================

1. Object Detection Models
-------------------------
Replace template matching with trained models.

Implementation Path:
```python
import ultralytics
from ultralytics import YOLO

# Train custom model for construction symbols
model = YOLO('yolov8n.pt') # Start with pretrained
model.train(
data='construction_symbols.yaml',
epochs=100,
imgsz=640,
device='gpu'
)

# Use trained model
symbol_detector = YOLO('construction_symbols_trained.pt')
results = symbol_detector.predict(construction_image)
```

Training Data Requirements:
- 1000+ annotated construction drawings
- Symbol bounding boxes with classifications
- Data augmentation for various drawing styles

2. Advanced Room Detection
-------------------------
Use semantic segmentation for precise room boundaries.

Model Architecture:
```python
import torch
import torch.nn as nn
from torchvision.models.segmentation import deeplabv3_resnet50

class RoomSegmentationModel(nn.Module):
def __init__(self, num_classes=3): # background, walls, rooms
super().__init__()
self.backbone = deeplabv3_resnet50(pretrained=True)
self.backbone.classifier[4] = nn.Conv2d(256, num_classes, 1)

def forward(self, x):
return self.backbone(x)
```

REQUIRED DEPENDENCIES
====================

Critical Installations:
```bash
# OCR capabilities
pip install pytesseract easyocr paddleocr

# CAD layer reading (CRITICAL ADDITION)
pip install ezdxf dxfgrabber

# Machine learning
pip install torch torchvision ultralytics

# Computer vision enhancement
pip install scikit-image opencv-contrib-python

# CAD integration
pip install ezdxf

# Testing framework
pip install pytest pytest-cov

# NFPA standards (manual research needed)
# Need to implement based on NFPA 72 code book
```

System Requirements:
```bash
# Tesseract OCR binary
choco install tesseract # Windows
# or: apt-get install tesseract-ocr # Linux

# GPU support for ML training (optional but recommended)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
```

DATA REQUIREMENTS
=================

Symbol Libraries:
- Fire safety symbols (smoke detectors, sprinklers, pull stations)
- Electrical symbols (outlets, switches, panels)
- Architectural symbols (doors, windows, stairs)
- MEP symbols (HVAC diffusers, piping, equipment)

Training Datasets:
- 500+ construction floor plans with room annotations
- 200+ symbol detection training images
- Scale notation examples with ground truth
- Professional validation datasets

VALIDATION FRAMEWORK
===================

Testing Requirements:
```python
def test_nfpa_compliance():
# Test against known compliant designs
assert validate_smoke_detector_placement(test_room) == True

def test_symbol_detection_accuracy():
# Minimum 95% accuracy on test set
accuracy = symbol_detector.test(validation_set)
assert accuracy > 0.95

def test_room_segmentation():
# Compare against manual annotations
iou_score = calculate_iou(predicted_rooms, ground_truth_rooms)
assert iou_score > 0.90
```

SUCCESS CRITERIA
================

Phase 1 Complete When:
- OCR extracts scale information from title blocks
- Fire safety symbols detected with >90% accuracy
- NFPA 72 spacing calculations implemented
- Room segmentation identifies individual spaces

Phase 2 Complete When:
- Scale detection works automatically
- Room boundaries accurate within 5%
- Symbol recognition >95% accuracy
- Processing time <30 seconds per drawing

Phase 3 Complete When:
- ML models outperform template matching
- Professional validation >90% approval
- Full NFPA compliance checking
- Industry-ready deployment capability

The AI now has a clear implementation path from foundation to production! 🔥
"""
Loading
Loading