YOLOdeepsseek 火灾检测系统[火灾烟雾识别系统]支持图片、视频、摄像头实时检测AI智能识别火情带后台管理功能齐全适合消防、安防、应急等领域111**“YOLO DeepSeek (LLM) 智慧消防系统”**设计方案。用户认证系统登录/注册。数据可视化大屏Dashboard统计火焰/烟雾识别次数、占比饼图、趋势折线图。多模态检测功能支持图片上传、视频文件分析、摄像头实时流。历史记录管理查看过往的检测结果、置信度、耗时等。AI 智能助手 (DeepSeek)基于识别结果利用大语言模型生成专业的防火建议。下面我将为你提供构建这套系统的完整技术栈和核心代码实现。️ 1. 技术栈选型模块技术选型说明前端界面Vue 3 Element Plus构建响应式后台管理界面红白配色图表组件后端框架FastAPI (Python)高性能异步 API适合 AI 推理服务AI 检测模型YOLOv8-Seg / YOLOv10用于火焰和烟雾的目标检测/分割AI 大模型DeepSeek-V3 / R1 (API)用于生成火灾防治建议 (通过 HTTP 调用)数据库SQLite / MySQL存储用户信息、检测记录、统计数据数据处理Pandas ECharts后端处理数据前端渲染图表 2. 项目目录结构fire_detection_system/ ├── backend/ │ ├── main.py # FastAPI 主入口 │ ├── models.py # 数据库模型 (User, DetectionRecord) │ ├── ai_engine.py # YOLO 推理 DeepSeek 调用逻辑 │ ├── database.py # 数据库连接 │ └── requirements.txt # Python 依赖 ├── frontend/ │ ├── src/ │ │ ├── views/ │ │ │ ├── Login.vue # 登录页 │ │ │ ├── Dashboard.vue# 数据大屏 │ │ │ ├── ImageDetect.vue # 图片检测页 │ │ │ └── History.vue # 历史记录页 │ │ ├── components/ # 图表组件 │ │ └── App.vue │ └── package.json └── assets/ # 存放上传的图片和视频 3. 后端核心代码 (FastAPI YOLO DeepSeek)A. 安装依赖 (backend/requirements.txt)fastapi uvicorn python-multipart sqlalchemy pydantic ultralytics requests opencv-python numpy pillowB. AI 引擎与逻辑 (backend/ai_engine.py)这是系统的核心负责调用 YOLO 进行检测并调用 DeepSeek 生成建议。importcv2importnumpyasnpfromultralyticsimportYOLOimportrequestsimporttimeimportos# 加载 YOLO 模型 (确保你已经训练好 fire_smoke_best.pt)MODEL_PATHweights/fire_smoke_best.ptmodelYOLO(MODE_PATH)ifos.path.exists(MODE_PATH)elseYOLO(yolov8n.pt)# fallback# DeepSeek API 配置 (需替换为你的 API Key)DEEPSEEK_API_KEYsk-your-deepseek-api-keyDEEPSEEK_URLhttps://api.deepseek.com/v1/chat/completionsclassFireAIEngine:defdetect_image(self,image_path):执行图片检测start_timetime.time()resultsmodel(image_path,conf0.5,iou0.5)resultresults[0]detections[]has_fireFalsehas_smokeFalse# 解析检测结果ifresult.boxesisnotNone:forboxinresult.boxes:cls_idint(box.cls[0])conffloat(box.conf[0])class_namemodel.names[cls_id]xyxybox.xyxy[0].cpu().numpy()ifclass_namefire:has_fireTrueifclass_namesmoke:has_smokeTruedetections.append({class:class_name,confidence:round(conf,4),box:xyxy.tolist()})# 保存带框的图片output_pathfassets/detected_{int(time.time())}.jpgresult.save(filenameoutput_path)durationround(time.time()-start_time,4)return{status:success,detections:detections,has_fire:has_fire,has_smoke:has_smoke,duration:duration,output_image:output_path}defget_deepseek_advice(self,detection_result):调用 DeepSeek 生成防火建议contextifdetection_result[has_fire]:context检测到明火。ifdetection_result[has_smoke]:context检测到浓烟。ifnotcontext:return未检测到明显火情请保持警惕。promptf 你是一个专业的消防安全专家。 当前监控场景分析结果{context}检测到的具体目标{detection_result[detections]}请给出 3 条简短、专业的紧急处置建议和预防措施。 格式要求使用 Markdown 列表。 headers{Content-Type:application/json,Authorization:fBearer{DEEPSEEK_API_KEY}}payload{model:deepseek-chat,messages:[{role:system,content:You are a helpful fire safety assistant.},{role:user,content:prompt}],temperature:0.7}try:responserequests.post(DEEPSEEK_URL,jsonpayload,headersheaders,timeout10)ifresponse.status_code200:returnresponse.json()[choices][0][message][content]else:returnAI 助手暂时繁忙请稍后再试。exceptExceptionase:returnfAI 服务连接失败{str(e)}ai_engineFireAIEngine()C. 主程序接口 (backend/main.py)fromfastapiimportFastAPI,UploadFile,File,Depends,HTTPExceptionfromfastapi.middleware.corsimportCORSMiddlewarefromsqlalchemy.ormimportSessionfromtypingimportListimportshutilimportosfromai_engineimportai_enginefrommodelsimportBase,DetectionRecord,get_db,RecordCreate# 假设已定义数据库模型appFastAPI(title智慧烟火检测系统 API)# 允许跨域 (供前端 Vue 调用)app.add_middleware(CORSMiddleware,allow_origins[*],allow_credentialsTrue,allow_methods[*],allow_headers[*],)os.makedirs(assets,exist_okTrue)app.post(/detect/image)asyncdefdetect_image_api(file:UploadFileFile(...),db:SessionDepends(get_db)):# 1. 保存图片file_pathfassets/{file.filename}withopen(file_path,wb)asbuffer:shutil.copyfileobj(file.file,buffer)# 2. AI 推理resultai_engine.detect_image(file_path)# 3. 调用 DeepSeek 获取建议adviceai_engine.get_deepseek_advice(result)# 4. 存入数据库 (简化版)# new_record DetectionRecord(...)# db.add(new_record); db.commit()result[advice]advicereturnresultapp.get(/stats/dashboard)asyncdefget_dashboard_stats(db:SessionDepends(get_db)):# 这里需要编写 SQL 查询统计今日/本周的 fire 和 smoke 数量# 返回格式参考截图{ fire_count: 5, smoke_count: 5, trend_data: [...] }return{fire_count:5,smoke_count:5,pie_chart:[{name:火焰,value:50},{name:烟雾,value:50}],line_chart:[3,4,2,7,4,5,8]# 近 7 天趋势}if__name____main__:importuvicorn uvicorn.run(app,host0.0.0.0,port8000) 4. 前端核心代码 (Vue 3 Element Plus)这里展示最关键的**“图像算法识别”**页面代码对应你的第 5 张截图。frontend/src/views/ImageDetect.vuetemplate div classdetect-container el-card classbox-card template #header div classcard-header span 图像算法识别/span /div /template !-- 控制区 -- div classcontrols el-select v-modeldetectType placeholder选择检测类型 el-option label火焰_烟雾 valuefire_smoke / /el-select el-select v-modelmodelName placeholder选择模型 el-option labelfire_smoke_best.pt valuebest / /el-select el-slider v-modelthreshold :min0.1 :max1.0 step0.1 stylewidth: 200px; margin: 0 20px; / el-button typesuccess clickuploadAndDetect :loadingloading开始检测/el-button /div !-- 结果展示区 -- div classresult-area v-ifdetectResult div classimage-box img :srcbaseUrl detectResult.output_image altDetection Result / /div div classinfo-box el-card shadowhover template #header 识别结果/template pstrong识别结果:/strong {{ detectResult.has_fire ? Fire : ✅ Safe }}/p pstrong预测概率:/strong {{ maxConf }}%/p pstrong总时间:/strong {{ detectResult.duration }}秒/p /el-card el-card shadowhover stylemargin-top: 20px; template #header AI 防治建议 (DeepSeek)/template div classmarkdown-body v-htmlrenderMarkdown(detectResult.advice)/div /el-card /div /div /el-card /div /template script setup import { ref, computed } from vue; import axios from axios; import MarkdownIt from markdown-it; // 需安装: npm install markdown-it const detectType ref(fire_smoke); const modelName ref(best); const threshold ref(0.5); const loading ref(false); const detectResult ref(null); const baseUrl http://localhost:8000/; const md new MarkdownIt(); const uploadAndDetect async () { // 实际项目中这里应该有一个 el-upload 组件让用户选图 // 这里模拟一个固定图片上传 const formData new FormData(); // 假设用户通过 input[typefile] 选择了文件 const fileInput document.querySelector(input[typefile]); if(!fileInput || !fileInput.files[0]) { alert(请先选择图片文件); return; } formData.append(file, fileInput.files[0]); loading.value true; try { const res await axios.post(${baseUrl}detect/image, formData, { headers: { Content-Type: multipart/form-data } }); detectResult.value res.data; } catch (error) { console.error(error); alert(检测失败); } finally { loading.value false; } }; const maxConf computed(() { if (!detectResult.value || !detectResult.value.detections.length) return 0; const max Math.max(...detectResult.value.detections.map(d d.confidence)); return (max * 100).toFixed(2); }); const renderMarkdown (text) { return md.render(text); }; /script style scoped .controls { display: flex; align-items: center; margin-bottom: 20px; gap: 15px; } .result-area { display: flex; gap: 20px; margin-top: 20px; } .image-box img { max-width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); } .info-box { flex: 1; } .markdown-body { line-height: 1.6; font-size: 14px; color: #333; } /stylefrontend/src/views/Dashboard.vue(数据大屏简略版)使用ECharts实现截图中的图表。template div classdashboard !-- 顶部卡片 -- el-row :gutter20 el-col :span12 el-card template #header烟火识别总览/template div classstat-item span classdot fire/span 火焰: {{ stats.fire_count }} 次 /div div classstat-item span classdot smoke/span 烟雾: {{ stats.smoke_count }} 次 /div /el-card /el-col /el-row !-- 图表区域 -- el-row :gutter20 stylemargin-top: 20px; el-col :span12 el-card template #header烟火识别占比/template div refpieChart styleheight: 300px;/div /el-card /el-col el-col :span12 el-card template #header近 7 天烟火识别趋势/template div reflineChart styleheight: 300px;/div /el-card /el-col /el-row /div /template script setup import { onMounted, ref } from vue; import * as echarts from echarts; import axios from axios; const stats ref({ fire_count: 0, smoke_count: 0 }); const pieChart ref(null); const lineChart ref(null); onMounted(async () { // 获取数据 const res await axios.get(http://localhost:8000/stats/dashboard); stats.value res.data; // 初始化饼图 const pieInstance echarts.init(pieChart.value); pieInstance.setOption({ tooltip: { trigger: item }, series: [{ type: pie, radius: [40%, 70%], data: res.data.pie_chart, itemStyle: { color: (params) params.name 火焰 ? #ff4d4f : #999 } }] }); // 初始化折线图 const lineInstance echarts.init(lineChart.value); lineInstance.setOption({ xAxis: { type: category, data: [1 日,2 日,3 日,4 日,5 日,6 日,7 日] }, yAxis: { type: value }, series: [{ data: res.data.line_chart, type: line, smooth: true, areaStyle: { opacity: 0.3 }, itemStyle: { color: #ff4d4f } }] }); }); /script style scoped .stat-item { font-size: 18px; margin: 10px 0; display: flex; align-items: center; } .dot { width: 12px; height: 12px; border-radius: 50%; margin-right: 10px; display: inline-block; } .fire { background-color: #ff4d4f; } .smoke { background-color: #999; } /style 5. 如何运行该系统准备模型将你之前训练的best.pt放入backend/weights/目录。确保data.yaml中的类别名是fire和smoke。启动后端cdbackend pipinstall-rrequirements.txt# 设置 DeepSeek API Key (环境变量或直接写在代码里)exportDEEPSEEK_API_KEYsk-...python main.py访问http://localhost:8000/docs可查看 API 文档。启动前端cdfrontendnpminstallnpmrun serve访问http://localhost:8080即可看到完整的红白配色管理系统。✨ 6. 系统亮点总结闭环工作流从“上传图片” - “YOLO 识别” - “DeepSeek 分析” - “生成报告”全流程自动化。专业性强不仅仅是画框还结合了 LLM 的知识库给出了具体的农业/工业防火建议如截图中的“清理可燃物”、“开设隔离带”。数据驱动通过 ECharts 图表管理者可以清晰看到火灾高发时段和类型辅助决策。易于扩展后端采用 FastAPI前端采用 Vue是目前最主流的开发组合方便后续接入更多摄像头或增加用户权限管理功能。以上文字及代码仅供参考。