Token导航 LogoToken导航

Agent Skill · 待分类

defect-detection-ai(缺陷检测 AI)

defect-detection-ai 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

defect-detection-ai 是待分类类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为权限未标注;许可证信息还不明确,第三方扫描有提醒项,按安装量在待分类类的 11,209 个 Skill 里排第 6,894。

总安装 412周安装 17GitHub Stars 111下载 135核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:defect-detection-ai(缺陷检测 AI)
来源仓库:https://github.com/datadrivenconstruction/ddc_skills_for_ai_agents_in_construction
仓库路径:skills/defect-detection-ai
安装命令:
npx skills add https://github.com/datadrivenconstruction/ddc_skills_for_ai_agents_in_construction --skill defect-detection-ai
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/datadrivenconstruction/ddc_skills_for_ai_agents_in_construction --skill defect-detection-ai

这个 Skill 是做什么的

这个 Skill 的分类还没最终确定,用法以来源仓库的说明为准。

基于深度学习构建的建筑缺陷自动识别系统,支持多材质检测。可识别混凝土裂缝、钢结构腐蚀、砌体砂浆劣化等多种缺陷类型。输出包含坐标框与置信度的检测结果,生成标准化巡检报告。需 GPU 加速推理,建议部署于具备 CUDA 支持的计算节点。

defect-detection-ai 属于待分类类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/defect-detection-ai

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/datadrivenconstruction/ddc_skills_for_ai_agent…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    权限没有明确标注,第一次使用时只给一个无关紧要的任务,观察它到底读了哪些文件和网络。

常见问题

6 条

defect-detection-ai 怎么安装?

在终端执行 npx skills add https://github.com/datadrivenconstruction/ddc_skills_for_ai_agents_in_const…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

defect-detection-ai 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

defect-detection-ai 需要什么权限?

权限级别没有明确标注。第一次使用时建议只给无关紧要的任务,观察它实际读写了哪些内容。

defect-detection-ai 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

defect-detection-ai 用的人多吗?

公开数据是累计安装 412 次,近一周安装 17 次,下载 135 次,GitHub 111 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

defect-detection-ai 安全吗?

第三方扫描有提醒项,说明存在需要人工确认的行为。安装前请打开源码看清它读了什么、联网到哪里。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方扫描存在提醒项或未通过项,需要人工逐条确认。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理待分类类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

待分类类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
infsh-cli

infsh CLI · Codex、Claude

4,374,576382权限未标注未明确未收录
ai-video-generation

AI 视频生成 · Codex、Claude

4,313,376382调用外部服务未明确有提醒
lark-openapi-explorer

云雀 OpenAPI 浏览器 · Codex、Claude

2,064,1209,011需要联网未明确有提醒
lark-workflow-standup-report

Lark 工作流程站立报告 · Codex、Claude

2,041,6328,978需要联网未明确通过
use-my-browser

使用我的浏览器 · Codex、Claude

1,848,49140操作浏览器未明确未通过
defect-detection-ai

缺陷检测 AI · 本页

412111权限未标注未明确有提醒

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

AI Defect Detection

Overview

This skill implements deep learning-based defect detection for construction quality control. Analyze images and video to automatically identify structural and surface defects, classify severity, and generate inspection reports.

Detectable Defects:

  • Concrete: Cracks, spalling, honeycombing, efflorescence
  • Steel: Corrosion, weld defects, deformation
  • Masonry: Mortar deterioration, displacement
  • Finishes: Surface defects, coating failures
  • MEP: Insulation damage, pipe corrosion

Quick Start

import torch
import torch.nn as nn
from torchvision import transforms, models
from PIL import Image
from dataclasses import dataclass
from typing import List, Dict, Tuple
from enum import Enum

class DefectType(Enum):
    CRACK = "crack"
    SPALLING = "spalling"
    CORROSION = "corrosion"
    HONEYCOMBING = "honeycombing"
    EFFLORESCENCE = "efflorescence"
    DEFORMATION = "deformation"
    SURFACE_DAMAGE = "surface_damage"
    NO_DEFECT = "no_defect"

class SeverityLevel(Enum):
    MINOR = "minor"
    MODERATE = "moderate"
    SEVERE = "severe"
    CRITICAL = "critical"

@dataclass
class DefectDetection:
    defect_type: DefectType
    confidence: float
    severity: SeverityLevel
    bounding_box: Tuple[int, int, int, int]  # x1, y1, x2, y2
    area_ratio: float  # Defect area as ratio of image

# Simple classifier using pretrained model
class SimpleDefectClassifier:
    def __init__(self, num_classes: int = 8):
        self.model = models.resnet18(pretrained=True)
        self.model.fc = nn.Linear(self.model.fc.in_features, num_classes)
        self.model.eval()

        self.transform = transforms.Compose([
            transforms.Resize((224, 224)),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ])

        self.classes = list(DefectType)

    def predict(self, image_path: str) -> DefectDetection:
        """Classify defect in image"""
        image = Image.open(image_path).convert('RGB')
        input_tensor = self.transform(image).unsqueeze(0)

        with torch.no_grad():
            outputs = self.model(input_tensor)
            probs = torch.softmax(outputs, dim=1)
            confidence, predicted = torch.max(probs, 1)

        defect_type = self.classes[predicted.item()]

        return DefectDetection(
            defect_type=defect_type,
            confidence=confidence.item(),
            severity=self._estimate_severity(confidence.item()),
            bounding_box=(0, 0, image.width, image.height),
            area_ratio=1.0
        )

    def _estimate_severity(self, confidence: float) -> SeverityLevel:
        if confidence > 0.9:
            return SeverityLevel.CRITICAL
        elif confidence > 0.7:
            return SeverityLevel.SEVERE
        elif confidence > 0.5:
            return SeverityLevel.MODERATE
        else:
            return SeverityLevel.MINOR

# Usage
classifier = SimpleDefectClassifier()
# result = classifier.predict("concrete_image.jpg")
# print(f"Defect: {result.defect_type.value}, Confidence: {result.confidence:.2%}")

Comprehensive Defect Detection System

Object Detection Model

import torch
import torch.nn as nn
from torchvision import transforms
from torchvision.models.detection import fasterrcnn_resnet50_fpn
from PIL import Image
import numpy as np
from dataclasses import dataclass, field
from typing import List, Dict, Tuple, Optional
from datetime import datetime
import json

@dataclass
class BoundingBox:
    x1: int
    y1: int
    x2: int
    y2: int

    @property
    def width(self) -> int:
        return self.x2 - self.x1

    @property
    def height(self) -> int:
        return self.y2 - self.y1

    @property
    def area(self) -> int:
        return self.width * self.height

    @property
    def center(self) -> Tuple[int, int]:
        return ((self.x1 + self.x2) // 2, (self.y1 + self.y2) // 2)

@dataclass
class DetectedDefect:
    defect_id: str
    defect_type: DefectType
    confidence: float
    severity: SeverityLevel
    bounding_box: BoundingBox
    area_sqm: Optional[float] = None
    dimensions_mm: Optional[Tuple[float, float]] = None
    metadata: Dict = field(default_factory=dict)

@dataclass
class InspectionResult:
    inspection_id: str
    image_path: str
    timestamp: datetime
    location: str
    element_type: str
    defects: List[DetectedDefect]
    overall_condition: str
    recommended_actions: List[str]

class DefectDetectionModel:
    """Deep learning defect detection with object detection"""

    DEFECT_CLASSES = {
        1: DefectType.CRACK,
        2: DefectType.SPALLING,
        3: DefectType.CORROSION,
        4: DefectType.HONEYCOMBING,
        5: DefectType.EFFLORESCENCE,
        6: DefectType.DEFORMATION,
        7: DefectType.SURFACE_DAMAGE
    }

    def __init__(self, model_path: str = None, device: str = 'cpu'):
        self.device = torch.device(device)

        # Initialize Faster R-CNN
        self.model = fasterrcnn_resnet50_fpn(pretrained=True)

        # Modify for our classes
        num_classes = len(self.DEFECT_CLASSES) + 1  # +1 for background
        in_features = self.model.roi_heads.box_predictor.cls_score.in_features
        self.model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)

        if model_path:
            self.model.load_state_dict(torch.load(model_path, map_location=self.device))

        self.model.to(self.device)
        self.model.eval()

        self.transform = transforms.Compose([
            transforms.ToTensor()
        ])

    def detect(self, image_path: str, confidence_threshold: float = 0.5,
               pixels_per_mm: float = None) -> List[DetectedDefect]:
        """Detect defects in image"""
        image = Image.open(image_path).convert('RGB')
        image_tensor = self.transform(image).to(self.device)

        with torch.no_grad():
            predictions = self.model([image_tensor])

        pred = predictions[0]
        defects = []

        for i in range(len(pred['boxes'])):
            score = pred['scores'][i].item()

            if score < confidence_threshold:
                continue

            label = pred['labels'][i].item()
            box = pred['boxes'][i].cpu().numpy()

            defect_type = self.DEFECT_CLASSES.get(label, DefectType.SURFACE_DAMAGE)

            bbox = BoundingBox(
                x1=int(box[0]),
                y1=int(box[1]),
                x2=int(box[2]),
                y2=int(box[3])
            )

            # Calculate dimensions if scale provided
            dimensions_mm = None
            if pixels_per_mm:
                width_mm = bbox.width / pixels_per_mm
                height_mm = bbox.height / pixels_per_mm
                dimensions_mm = (width_mm, height_mm)

            severity = self._classify_severity(defect_type, bbox, image.size)

            defects.append(DetectedDefect(
                defect_id=f"DEF-{i:04d}",
                defect_type=defect_type,
                confidence=score,
                severity=severity,
                bounding_box=bbox,
                dimensions_mm=dimensions_mm
            ))

        return defects

    def _classify_severity(self, defect_type: DefectType,
                          bbox: BoundingBox,
                          image_size: Tuple[int, int]) -> SeverityLevel:
        """Classify defect severity based on type and size"""
        image_area = image_size[0] * image_size[1]
        defect_ratio = bbox.area / image_area

        # Severity thresholds by defect type
        thresholds = {
            DefectType.CRACK: {'critical': 0.1, 'severe': 0.05, 'moderate': 0.02},
            DefectType.SPALLING: {'critical': 0.15, 'severe': 0.08, 'moderate': 0.03},
            DefectType.CORROSION: {'critical': 0.2, 'severe': 0.1, 'moderate': 0.05},
            DefectType.HONEYCOMBING: {'critical': 0.1, 'severe': 0.05, 'moderate': 0.02},
            DefectType.DEFORMATION: {'critical': 0.05, 'severe': 0.02, 'moderate': 0.01}
        }

        t = thresholds.get(defect_type, {'critical': 0.15, 'severe': 0.08, 'moderate': 0.03})

        if defect_ratio >= t['critical']:
            return SeverityLevel.CRITICAL
        elif defect_ratio >= t['severe']:
            return SeverityLevel.SEVERE
        elif defect_ratio >= t['moderate']:
            return SeverityLevel.MODERATE
        else:
            return SeverityLevel.MINOR

class FastRCNNPredictor(nn.Module):
    """Custom predictor for Faster R-CNN"""

    def __init__(self, in_channels, num_classes):
        super().__init__()
        self.cls_score = nn.Linear(in_channels, num_classes)
        self.bbox_pred = nn.Linear(in_channels, num_classes * 4)

    def forward(self, x):
        scores = self.cls_score(x)
        bbox_deltas = self.bbox_pred(x)
        return scores, bbox_deltas

Crack Analysis System

import cv2
import numpy as np
from typing import List, Tuple, Dict

class CrackAnalyzer:
    """Specialized crack detection and measurement"""

    def __init__(self):
        self.min_crack_length = 10  # pixels
        self.min_crack_width = 2  # pixels

    def detect_cracks(self, image_path: str,
                      pixels_per_mm: float = 1.0) -> List[Dict]:
        """Detect and measure cracks in image"""
        # Load image
        image = cv2.imread(image_path)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        # Enhance contrast
        clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
        enhanced = clahe.apply(gray)

        # Edge detection
        edges = cv2.Canny(enhanced, 50, 150)

        # Morphological operations to connect crack segments
        kernel = np.ones((3, 3), np.uint8)
        dilated = cv2.dilate(edges, kernel, iterations=1)
        closed = cv2.morphologyEx(dilated, cv2.MORPH_CLOSE, kernel)

        # Find contours
        contours, _ = cv2.findContours(closed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

        cracks = []
        for i, contour in enumerate(contours):
            # Filter by length
            arc_length = cv2.arcLength(contour, False)
            if arc_length < self.min_crack_length:
                continue

            # Get bounding box
            x, y, w, h = cv2.boundingRect(contour)

            # Calculate crack properties
            length_px = arc_length
            width_px = self._estimate_crack_width(gray, contour)

            # Convert to mm
            length_mm = length_px / pixels_per_mm
            width_mm = width_px / pixels_per_mm

            # Classify crack
            crack_type = self._classify_crack(length_mm, width_mm, contour)

            cracks.append({
                'crack_id': f"CRACK-{i:04d}",
                'type': crack_type,
                'length_mm': length_mm,
                'width_mm': width_mm,
                'bounding_box': (x, y, x + w, y + h),
                'contour': contour.tolist(),
                'severity': self._get_crack_severity(width_mm, length_mm),
                'orientation': self._get_crack_orientation(contour)
            })

        return cracks

    def _estimate_crack_width(self, gray_image: np.ndarray,
                             contour: np.ndarray) -> float:
        """Estimate average crack width"""
        # Create mask for contour
        mask = np.zeros(gray_image.shape, dtype=np.uint8)
        cv2.drawContours(mask, [contour], -1, 255, 1)

        # Distance transform
        dist = cv2.distanceTransform(mask, cv2.DIST_L2, 5)

        # Get average distance (half-width)
        nonzero = dist[dist > 0]
        if len(nonzero) > 0:
            return np.mean(nonzero) * 2
        return 0

    def _classify_crack(self, length_mm: float, width_mm: float,
                       contour: np.ndarray) -> str:
        """Classify crack type"""
        # Fit line to get orientation
        [vx, vy, x, y] = cv2.fitLine(contour, cv2.DIST_L2, 0, 0.01, 0.01)
        angle = np.arctan2(vy, vx) * 180 / np.pi

        if abs(angle) < 20 or abs(angle) > 160:
            orientation = "horizontal"
        elif 70 < abs(angle) < 110:
            orientation = "vertical"
        else:
            orientation = "diagonal"

        # Check for pattern (simplified)
        if width_mm > 3:
            return "structural_crack"
        elif orientation == "horizontal" and length_mm > 100:
            return "settlement_crack"
        elif orientation == "diagonal":
            return "shear_crack"
        else:
            return "shrinkage_crack"

    def _get_crack_severity(self, width_mm: float, length_mm: float) -> str:
        """Determine crack severity based on dimensions"""
        # Based on ACI 224R guidelines
        if width_mm > 1.0:
            return "critical"
        elif width_mm > 0.4:
            return "severe"
        elif width_mm > 0.2:
            return "moderate"
        else:
            return "minor"

    def _get_crack_orientation(self, contour: np.ndarray) -> float:
        """Get crack orientation angle"""
        [vx, vy, x, y] = cv2.fitLine(contour, cv2.DIST_L2, 0, 0.01, 0.01)
        return float(np.arctan2(vy, vx) * 180 / np.pi)

    def generate_crack_report(self, cracks: List[Dict]) -> Dict:
        """Generate summary report of detected cracks"""
        if not cracks:
            return {'message': 'No cracks detected'}

        total_length = sum(c['length_mm'] for c in cracks)
        max_width = max(c['width_mm'] for c in cracks)
        severity_counts = {}

        for c in cracks:
            sev = c['severity']
            severity_counts[sev] = severity_counts.get(sev, 0) + 1

        return {
            'total_cracks': len(cracks),
            'total_length_mm': total_length,
            'max_width_mm': max_width,
            'avg_width_mm': sum(c['width_mm'] for c in cracks) / len(cracks),
            'by_severity': severity_counts,
            'by_type': self._group_by_type(cracks),
            'most_severe': max(cracks, key=lambda c: c['width_mm'])
        }

    def _group_by_type(self, cracks: List[Dict]) -> Dict:
        """Group cracks by type"""
        grouped = {}
        for c in cracks:
            t = c['type']
            if t not in grouped:
                grouped[t] = []
            grouped[t].append(c['crack_id'])
        return grouped

Inspection Report Generator

from datetime import datetime
import pandas as pd

class DefectInspectionSystem:
    """Complete defect inspection and reporting system"""

    def __init__(self, detection_model: DefectDetectionModel):
        self.model = detection_model
        self.crack_analyzer = CrackAnalyzer()
        self.inspections: List[InspectionResult] = []

    def perform_inspection(self, image_path: str,
                          location: str,
                          element_type: str,
                          pixels_per_mm: float = None) -> InspectionResult:
        """Perform complete inspection on image"""
        # Detect defects
        defects = self.model.detect(image_path, pixels_per_mm=pixels_per_mm)

        # Additional crack analysis for concrete
        if element_type.lower() in ['concrete', 'slab', 'wall', 'column', 'beam']:
            cracks = self.crack_analyzer.detect_cracks(image_path, pixels_per_mm or 1.0)

            # Add detailed crack info to relevant defects
            for defect in defects:
                if defect.defect_type == DefectType.CRACK:
                    for crack in cracks:
                        # Check if crack overlaps with defect bbox
                        if self._boxes_overlap(defect.bounding_box, crack['bounding_box']):
                            defect.metadata['crack_details'] = crack
                            break

        # Determine overall condition
        overall_condition = self._assess_overall_condition(defects)

        # Generate recommendations
        recommendations = self._generate_recommendations(defects, element_type)

        result = InspectionResult(
            inspection_id=f"INS-{datetime.now().strftime('%Y%m%d%H%M%S')}",
            image_path=image_path,
            timestamp=datetime.now(),
            location=location,
            element_type=element_type,
            defects=defects,
            overall_condition=overall_condition,
            recommended_actions=recommendations
        )

        self.inspections.append(result)
        return result

    def _boxes_overlap(self, box1: BoundingBox, box2: Tuple) -> bool:
        """Check if two bounding boxes overlap"""
        x1_1, y1_1, x2_1, y2_1 = box1.x1, box1.y1, box1.x2, box1.y2
        x1_2, y1_2, x2_2, y2_2 = box2

        return not (x2_1 < x1_2 or x2_2 < x1_1 or y2_1 < y1_2 or y2_2 < y1_1)

    def _assess_overall_condition(self, defects: List[DetectedDefect]) -> str:
        """Assess overall structural condition"""
        if not defects:
            return "Good"

        severity_scores = {
            SeverityLevel.MINOR: 1,
            SeverityLevel.MODERATE: 2,
            SeverityLevel.SEVERE: 3,
            SeverityLevel.CRITICAL: 4
        }

        max_severity = max(severity_scores[d.severity] for d in defects)
        total_defects = len(defects)

        if max_severity >= 4 or total_defects > 10:
            return "Critical - Immediate attention required"
        elif max_severity >= 3 or total_defects > 5:
            return "Poor - Repairs needed"
        elif max_severity >= 2 or total_defects > 2:
            return "Fair - Monitor and plan repairs"
        else:
            return "Good - Minor issues only"

    def _generate_recommendations(self, defects: List[DetectedDefect],
                                 element_type: str) -> List[str]:
        """Generate repair recommendations"""
        recommendations = []

        # Group defects by type
        defect_groups = {}
        for d in defects:
            t = d.defect_type
            if t not in defect_groups:
                defect_groups[t] = []
            defect_groups[t].append(d)

        # Generate recommendations by defect type
        for defect_type, group in defect_groups.items():
            max_severity = max(d.severity for d in group)

            if defect_type == DefectType.CRACK:
                if max_severity in [SeverityLevel.CRITICAL, SeverityLevel.SEVERE]:
                    recommendations.append(
                        f"Structural engineer assessment required for {len(group)} crack(s). "
                        f"Consider epoxy injection or structural repair."
                    )
                else:
                    recommendations.append(
                        f"Seal {len(group)} minor crack(s) with appropriate sealant."
                    )

            elif defect_type == DefectType.SPALLING:
                recommendations.append(
                    f"Remove loose concrete and apply repair mortar to {len(group)} spalling area(s). "
                    f"Check reinforcement for corrosion."
                )

            elif defect_type == DefectType.CORROSION:
                recommendations.append(
                    f"Treat {len(group)} corrosion area(s). Clean rust, apply rust converter, "
                    f"and protective coating."
                )

            elif defect_type == DefectType.HONEYCOMBING:
                recommendations.append(
                    f"Fill {len(group)} honeycomb area(s) with non-shrink grout. "
                    f"Investigate concrete placement procedures."
                )

            elif defect_type == DefectType.EFFLORESCENCE:
                recommendations.append(
                    f"Clean efflorescence from {len(group)} area(s). "
                    f"Investigate and address moisture source."
                )

        if not recommendations:
            recommendations.append("Continue regular inspection schedule.")

        return recommendations

    def export_inspection_report(self, inspection_id: str,
                                output_path: str) -> str:
        """Export inspection report to Excel"""
        inspection = next(
            (i for i in self.inspections if i.inspection_id == inspection_id),
            None
        )

        if not inspection:
            raise ValueError(f"Inspection {inspection_id} not found")

        with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
            # Summary
            summary = pd.DataFrame([{
                'Inspection ID': inspection.inspection_id,
                'Date': inspection.timestamp.strftime('%Y-%m-%d %H:%M'),
                'Location': inspection.location,
                'Element Type': inspection.element_type,
                'Overall Condition': inspection.overall_condition,
                'Total Defects': len(inspection.defects),
                'Image': inspection.image_path
            }])
            summary.to_excel(writer, sheet_name='Summary', index=False)

            # Defects
            if inspection.defects:
                defect_data = [{
                    'Defect ID': d.defect_id,
                    'Type': d.defect_type.value,
                    'Severity': d.severity.value,
                    'Confidence': f"{d.confidence:.1%}",
                    'Location (x,y)': f"({d.bounding_box.x1}, {d.bounding_box.y1})",
                    'Size (w×h)': f"{d.bounding_box.width}×{d.bounding_box.height}",
                    'Dimensions (mm)': d.dimensions_mm if d.dimensions_mm else 'N/A'
                } for d in inspection.defects]
                pd.DataFrame(defect_data).to_excel(writer, sheet_name='Defects', index=False)

            # Recommendations
            rec_data = [{'#': i+1, 'Recommendation': r}
                       for i, r in enumerate(inspection.recommended_actions)]
            pd.DataFrame(rec_data).to_excel(writer, sheet_name='Recommendations', index=False)

        return output_path

    def get_defect_statistics(self, start_date: datetime = None,
                             end_date: datetime = None) -> Dict:
        """Get defect statistics across inspections"""
        filtered = self.inspections
        if start_date:
            filtered = [i for i in filtered if i.timestamp >= start_date]
        if end_date:
            filtered = [i for i in filtered if i.timestamp <= end_date]

        all_defects = []
        for inspection in filtered:
            all_defects.extend(inspection.defects)

        if not all_defects:
            return {'message': 'No defects found in period'}

        # Statistics
        by_type = {}
        by_severity = {}

        for d in all_defects:
            t = d.defect_type.value
            s = d.severity.value

            by_type[t] = by_type.get(t, 0) + 1
            by_severity[s] = by_severity.get(s, 0) + 1

        return {
            'period': {
                'start': start_date.isoformat() if start_date else 'all',
                'end': end_date.isoformat() if end_date else 'all'
            },
            'total_inspections': len(filtered),
            'total_defects': len(all_defects),
            'by_type': by_type,
            'by_severity': by_severity,
            'avg_defects_per_inspection': len(all_defects) / len(filtered) if filtered else 0
        }

Model Training

import torch
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms
import os
from PIL import Image

class DefectDataset(Dataset):
    """Dataset for training defect detection model"""

    def __init__(self, root_dir: str, annotations_file: str, transform=None):
        self.root_dir = root_dir
        self.annotations = self._load_annotations(annotations_file)
        self.transform = transform or transforms.Compose([
            transforms.Resize((800, 800)),
            transforms.ToTensor()
        ])

    def _load_annotations(self, path: str) -> List[Dict]:
        """Load COCO-format annotations"""
        import json
        with open(path, 'r') as f:
            data = json.load(f)
        return data['annotations']

    def __len__(self):
        return len(self.annotations)

    def __getitem__(self, idx):
        ann = self.annotations[idx]
        image_path = os.path.join(self.root_dir, ann['image_file'])
        image = Image.open(image_path).convert('RGB')

        if self.transform:
            image = self.transform(image)

        # Prepare target
        boxes = torch.tensor(ann['boxes'], dtype=torch.float32)
        labels = torch.tensor(ann['labels'], dtype=torch.int64)

        target = {
            'boxes': boxes,
            'labels': labels
        }

        return image, target

def train_defect_model(train_dataset: DefectDataset,
                       val_dataset: DefectDataset,
                       num_epochs: int = 10,
                       batch_size: int = 4,
                       learning_rate: float = 0.005):
    """Train defect detection model"""
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

    # Initialize model
    model = fasterrcnn_resnet50_fpn(pretrained=True)
    num_classes = 8  # 7 defect types + background
    in_features = model.roi_heads.box_predictor.cls_score.in_features
    model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
    model.to(device)

    # Data loaders
    train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True,
                              collate_fn=lambda x: tuple(zip(*x)))
    val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False,
                           collate_fn=lambda x: tuple(zip(*x)))

    # Optimizer
    optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate,
                                momentum=0.9, weight_decay=0.0005)

    # Training loop
    for epoch in range(num_epochs):
        model.train()
        total_loss = 0

        for images, targets in train_loader:
            images = [img.to(device) for img in images]
            targets = [{k: v.to(device) for k, v in t.items()} for t in targets]

            loss_dict = model(images, targets)
            losses = sum(loss for loss in loss_dict.values())

            optimizer.zero_grad()
            losses.backward()
            optimizer.step()

            total_loss += losses.item()

        avg_loss = total_loss / len(train_loader)
        print(f"Epoch {epoch+1}/{num_epochs}, Loss: {avg_loss:.4f}")

    return model

Quick Reference

Defect TypeDetection MethodTypical Severity
CrackEdge detection + CNNVaries by width
SpallingObject detectionModerate-Severe
CorrosionColor + texture analysisModerate-Critical
HoneycombingObject detectionSevere
EfflorescenceColor analysisMinor-Moderate

ACI 224R Crack Width Guidelines

Width (mm)ConditionExposure
< 0.1AcceptableAny
0.1 - 0.2AcceptableDry
0.2 - 0.4Repair recommendedHumid
> 0.4Repair requiredAny
> 1.0Structural concernAny

Resources

Next Steps

  • See progress-monitoring-cv for construction progress analysis
  • See safety-compliance-checker for safety defect integration
  • See bim-validation-pipeline for model-based quality control

平台分布

Codex

35.66%
按下载量换算48

Claude

29.92%
按下载量换算40

Cursor

16.63%
按下载量换算22

Gemini CLI

8.74%
按下载量换算12

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

权限未标注

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在提醒或未通过项,安装前请自行复核。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills