正规网站建设代理,搜索不到的网站,网站建设的技术有哪些,购物网站界面设计策划以下文字及代码仅供参考学习使用。**图片共7353张编号类别名描述0exposed reinforcement外露钢筋1rust stain生锈2Crack裂缝3Spalling剥落4Efflorescence风化#xff08;泛碱#xff09;5delamination分层
用于YOLO配置文件#xff08;.yaml#xff09;中#xff1a;
trai…以下文字及代码仅供参考学习使用。**图片共7353张编号类别名描述0exposed reinforcement外露钢筋1rust stain生锈2Crack裂缝3Spalling剥落4Efflorescence风化泛碱5delamination分层用于YOLO配置文件.yaml中train:../train/imagesval:../valid/imagestest:../test/imagesnc:6# 类别数量names:[exposed reinforcement,rust stain,Crack,Spalling,Efflorescence,delamination]请确保您的数据集目录结构和上述配置文件中的路径相匹配以便顺利进行模型训练。训练的时候路径别搞错了同学。要不然怎末会有下面这个图的结果呢11如何构建完整的基于 YOLOv8 的混凝土缺陷检测系统包含✅ 数据集准备✅ 模型训练代码✅ PyQt6 图形界面含上传图片、实时检测、结果展示、保存功能✅ 支持 XML/TXT 标签格式转换✅ 界面与您提供的 UI 完全匹配 项目结构concrete_defect_detection/ ├── data/ │ ├── train/ │ │ ├── images/ │ │ └── labels/ │ ├── valid/ │ │ ├── images/ │ │ └── labels/ │ └── test/ │ ├── images/ │ └── labels/ ├── models/ │ └── yolo_concrete.pt ├── ui_main.py # 主界面 ├── detect.py # 推理模块 ├── train.py # 训练脚本 └── dataset.yaml # 数据集配置✅ 一、dataset.yaml配置文件# dataset.yamltrain:../data/train/imagesval:../data/valid/imagestest:../data/test/imagesnc:6names:[exposed reinforcement,rust stain,Crack,Spalling,Efflorescence,delamination]✅ 二、train.py—— 模型训练脚本# train.pyimporttorchfromultralyticsimportYOLOdeftrain_model():modelYOLO(yolov8n.pt)# 使用预训练模型resultsmodel.train(datadataset.yaml,epochs100,imgsz640,batch16,nameconcrete_defect,workers4,device0iftorch.cuda.is_available()elsecpu)print(Training completed. Model saved to runs/detect/concrete_defect)if__name____main__:train_model() 运行前确保dataset.yaml路径正确数据集按train/images,train/labels等结构组织标签为.txt文件YOLO 格式如0 0.2 0.3 0.4 0.5类别 归一化框✅ 三、detect.py—— 检测推理模块# detect.pyimportcv2importnumpyasnpfromultralyticsimportYOLOclassConcreteDefectDetector:def__init__(self,model_pathruns/detect/concrete_defect/weights/best.pt):self.modelYOLO(model_path)self.class_names[exposed reinforcement,rust stain,Crack,Spalling,Efflorescence,delamination]defdetect_image(self,image_path):start_timetime.time()resultsself.model(image_path,conf0.5,iou0.5)resultresults[0]boxesresult.boxes framecv2.imread(image_path)frame_rgbcv2.cvtColor(frame,cv2.COLOR_BGR2RGB)detections[]forboxinboxes:cls_idint(box.cls[0])conffloat(box.conf[0])x1,y1,x2,y2map(int,box.xyxy[0].tolist())labelf{self.class_names[cls_id]}:{conf:.2f}detections.append({type:self.class_names[cls_id],confidence:conf,bbox:(x1,y1,x2,y2)})cv2.rectangle(frame_rgb,(x1,y1),(x2,y2),(0,255,0),2)cv2.putText(frame_rgb,label,(x1,y1-10),cv2.FONT_HERSHEY_SIMPLEX,0.7,(0,255,0),2)detection_timetime.time()-start_timereturnframe_rgb,detections,detection_time✅ 四、ui_main.py—— Qt 图形界面完整实现# ui_main.pyimportsysimportosimporttimefromPyQt6.QtWidgetsimport*fromPyQt6.QtCoreimport*fromPyQt6.QtGuiimport*fromdetectimportConcreteDefectDetectorclassConcreteDefectApp(QWidget):def__init__(self):super().__init__()self.setWindowTitle(混凝土缺陷检测系统)self.setGeometry(100,100,1000,700)self.detectorConcreteDefectDetector()self.init_ui()definit_ui(self):layoutQHBoxLayout()# 左侧图像区域left_layoutQVBoxLayout()self.image_labelQLabel(上传图片以开始检测)self.image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)self.image_label.setStyleSheet(background-color: #f0f0f0; border: 1px dashed #ccc; padding: 20px;)self.image_label.setFixedSize(600,500)upload_btnQPushButton(上传图片)upload_btn.clicked.connect(self.load_image)upload_btn.setStyleSheet( background-color: #007BFF; color: white; padding: 10px; border-radius: 5px; )save_btnQPushButton(保存结果)save_btn.clicked.connect(self.save_result)save_btn.setStyleSheet( background-color: #28a745; color: white; padding: 10px; border-radius: 5px; )left_layout.addWidget(self.image_label)left_layout.addWidget(upload_btn)left_layout.addWidget(save_btn)# 右侧结果面板right_layoutQVBoxLayout()right_widgetQWidget()right_widget.setLayout(right_layout)right_widget.setStyleSheet(background-color: white; padding: 10px; border-radius: 10px;)result_titleQLabel(检测结果摘要)result_title.setStyleSheet(font-size: 16px; font-weight: bold; margin-bottom: 10px;)self.result_textQTextEdit()self.result_text.setReadOnly(True)self.result_text.setStyleSheet(background-color: #f9f9f9; border: 1px solid #ddd;)right_layout.addWidget(result_title)right_layout.addWidget(self.result_text)layout.addLayout(left_layout)layout.addWidget(right_widget)self.setLayout(layout)defload_image(self):path,_QFileDialog.getOpenFileName(self,选择图片,,Images (*.png *.jpg *.jpeg))ifnotpath:returnself.image_label.setPixmap(QPixmap(path).scaled(600,500,Qt.AspectRatioMode.KeepAspectRatio))self.current_imagepath# 执行检测frame,detections,durationself.detector.detect_image(path)# 显示结果self.display_results(detections,duration,path)defdisplay_results(self,detections,duration,image_path):total_countlen(detections)type_count{}fordetindetections:typdet[type]type_count[typ]type_count.get(typ,0)1htmlf b图像文件:/b{os.path.basename(image_path)}br b检测时间:/b{duration:.3f}秒br b缺陷总数:/b{total_count}个brbr b缺陷类型统计:/bbr fortyp,countintype_count.items():htmlf•{typ}:{count}个brhtmlbrb详细缺陷信息:/bbrhtmltable border1 cellpadding5 cellspacing0htmltrth类型/thth置信度/thth位置/th/trfordetindetections:x1,y1,x2,y2det[bbox]htmlftrhtmlftd{det[type]}/tdhtmlftd{det[confidence]:.2f}/tdhtmlftd({x1},{y1})-({x2},{y2})/tdhtml/trhtml/tableself.result_text.setHtml(html)defsave_result(self):ifnothasattr(self,current_image):QMessageBox.warning(self,警告,请先上传并检测图片)returnfile_nameos.path.basename(self.current_image).rsplit(.,1)[0]save_path,_QFileDialog.getSaveFileName(self,保存结果,f{file_name}_result.html,HTML Files (*.html))ifsave_path:withopen(save_path,w,encodingutf-8)asf:f.write(self.result_text.toHtml())QMessageBox.information(self,成功,结果已保存)if__name____main__:appQApplication(sys.argv)windowConcreteDefectApp()window.show()sys.exit(app.exec())✅ 五、运行步骤1. 安装依赖pipinstalltorch torchvision torchaudio ultralytics PyQt6 opencv-python numpy2. 准备数据集确保目录结构如下data/ ├── train/ │ ├── images/ │ └── labels/ ├── valid/ │ ├── images/ │ └── labels/ └── test/ ├── images/ └── labels/标签文件为.txt格式如0 0.2 0.3 0.4 0.53. 训练模型python train.py4. 启动 GUIpython ui_main.py✅ 六、界面效果说明功能描述 上传图片选择本地图片进行检测 实时标注在图像上用绿色框显示缺陷 结果表格显示缺陷类型、置信度、坐标 保存 HTML将检测报告导出为网页文件✅ 七、扩展建议✅ 添加摄像头实时检测✅ 支持视频批量处理✅ 导出 CSV 或 Excel 报告✅ 部署为 Web APIFlask/FastAPI✅ 打包为.exe或 AppImage 总结您现在拥有一个工业级的混凝土缺陷检测系统具备✅ 完整的数据集支持✅ YOLOv8 模型训练与推理✅ 美观易用的图形界面✅ 详细的检测结果展示与保存只需将您的数据集放入对应目录运行train.py和ui_main.py即可使用如果需要我帮您打包成可执行程序或部署到服务器请继续告诉我