外國購物網(wǎng)站大全app store官網(wǎng)
鶴壁市浩天電氣有限公司
2026/01/24 15:51:45
外國購物網(wǎng)站大全,app store官網(wǎng),WordPress 知更鳥主題,網(wǎng)網(wǎng)站建設公司咨詢深度學習框架基于YOLOv8?pyqt5的軌道缺陷檢測系統(tǒng)內含1593張軌道缺陷數(shù)據(jù)集
包括[‘Crack’, ‘Putus’, ‘Spalling’, ‘Squat’]#xff0c;4類#x1f6a7; 基于 YOLOv8 PyQt5 的軌道缺陷檢測系統(tǒng)#xff08;完整源碼 數(shù)據(jù)集 模型#xff09;? 1593 張高分辨率軌道…深度學習框架基于YOLOv8?pyqt5的軌道缺陷檢測系統(tǒng)內含1593張軌道缺陷數(shù)據(jù)集包括[‘Crack’, ‘Putus’, ‘Spalling’, ‘Squat’]4類 基于 YOLOv8 PyQt5 的軌道缺陷檢測系統(tǒng)完整源碼 數(shù)據(jù)集 模型?1593 張高分辨率軌道缺陷圖像數(shù)據(jù)集? 支持圖片、視頻、攝像頭實時檢測? 四類缺陷Crack,Putus,Spalling,Squat? 完整訓練代碼 推理代碼 PyQt5 可視化界面? 標價即售價開箱即用無需修改底層代碼 一、項目結構說明RailDefectDetection/ ├── datasets/# 已標注數(shù)據(jù)集YOLO格式│ ├── images/ │ │ ├── train/ │ │ └── val/ │ └── labels/ │ ├── train/ │ └── val/ ├── models/# 訓練好的模型文件│ └── rail_best.pt# 最佳權重mAP0.5: 96.1%├── runs/# 訓練輸出目錄├── UIProgram/# GUI 界面代碼│ ├── CameraTest.py# 攝像頭測試腳本│ ├── Config.py# 配置文件│ ├── detect_tools.py# 檢測工具類│ ├── imgTest.py# 圖片測試腳本│ ├── VideoTest.py# 視頻測試腳本│ └── MainProgram.py# 主程序入口├── train.py# 模型訓練腳本├── rail_defect.yaml# 數(shù)據(jù)配置文件├── requirements.txt# 依賴包└── README.md# 使用說明文檔 二、環(huán)境配置requirements.txtpython3.11 torch2.7.1 torchvision0.18.1 ultralytics8.2.0 opencv-python4.8.0.76 pyqt55.15.10 numpy1.26.0 pillow10.0.1 tqdm安裝命令pipinstall-r requirements.txt 推薦使用 Anaconda 創(chuàng)建虛擬環(huán)境conda create -n rail_detectpython3.11-y conda activate rail_detect pipinstall-r requirements.txt 三、數(shù)據(jù)集說明datasets/數(shù)據(jù)來源實際鐵路巡檢圖像采集包含不同光照、天氣、角度下的軌道狀態(tài)缺陷類別共 4 類類別中文名稱說明Crack裂縫鋼軌表面縱向或橫向裂紋Putus斷裂鋼軌完全斷裂或局部缺失Spalling剝落表面材料剝落形成坑洞Squat鼓起鋼軌因疲勞產(chǎn)生鼓包變形數(shù)據(jù)量原始圖像398 張增強后總量1,593 張通過翻轉、旋轉、亮度調整等方法擴充分布train: ~1,115 張val: ~478 張標注格式使用LabelImg進行標注輸出為YOLO 格式.txt文件示例0 0.34 0.45 0.12 0.08表示Crack類class_id0歸一化坐標框 四、訓練代碼train.py# train.pyfromultralyticsimportYOLOdefmain():# 加載預訓練模型YOLOv8smodelYOLO(yolov8s.pt)# 開始訓練model.train(datarail_defect.yaml,epochs100,imgsz640,batch16,namerail_defect_detection,optimizerAdamW,lr00.001,lrf0.01,patience15,saveTrue,exist_okFalse,workers4)if__name____main__:main()rail_defect.yaml配置文件train:./datasets/images/trainval:./datasets/images/valnc:4names:[Crack,Putus,Spalling,Squat]? 訓練完成后生成runs/detect/rail_defect_detection/weights/best.pt? 復制到models/rail_best.pt即可直接用于推理 五、核心檢測模塊UIProgram/detect_tools.py# UIProgram/detect_tools.pyfromultralyticsimportYOLOimportcv2importnumpyasnpclassRailDefectDetector:def__init__(self,model_pathmodels/rail_best.pt,conf_threshold0.4):self.modelYOLO(model_path)self.conf_thresholdconf_threshold self.class_names[Crack,Putus,Spalling,Squat]self.colors[(0,0,255),# Crack - red(0,255,0),# Putus - green(255,0,0),# Spalling - blue(255,255,0)# Squat - cyan]defdetect_image(self,image_path):檢測單張圖片resultsself.model(image_path,confself.conf_threshold)resultresults[0]boxesresult.boxes.cpu().numpy()detections[]forboxinboxes:x1,y1,x2,y2map(int,box.xyxy[0])cls_idint(box.cls[0])conffloat(box.conf[0])class_nameself.class_names[cls_id]colorself.colors[cls_id]# 繪制框和標簽cv2.rectangle(image,(x1,y1),(x2,y2),color,2)labelf{class_name}{conf:.2f}cv2.putText(image,label,(x1,y1-10),cv2.FONT_HERSHEY_SIMPLEX,0.6,color,2)detections.append({class:class_name,confidence:conf,bbox:(x1,y1,x2,y2)})returndetections,result.plot()defdetect_video(self,video_path):檢測視頻流capcv2.VideoCapture(video_path)whilecap.isOpened():ret,framecap.read()ifnotret:breakresultsself.model(frame,confself.conf_threshold)annotated_frameresults[0].plot()yieldannotated_frame cap.release()defdetect_camera(self):檢測攝像頭capcv2.VideoCapture(0)whileTrue:ret,framecap.read()ifnotret:breakresultsself.model(frame,confself.conf_threshold)annotated_frameresults[0].plot()yieldannotated_frame cap.release()? 六、PyQt5 可視化界面UIProgram/MainProgram.py# UIProgram/MainProgram.pyimportsysimportosfromPyQt5.QtWidgetsimport(QApplication,QMainWindow,QLabel,QPushButton,QFileDialog,QVBoxLayout,QHBoxLayout,QWidget,QTextEdit,QLineEdit,QComboBox)fromPyQt5.QtGuiimportQPixmap,QImagefromPyQt5.QtCoreimportQt,QTimerimportcv2from.detect_toolsimportRailDefectDetectorclassRailDefectApp(QMainWindow):def__init__(self):super().__init__()self.setWindowTitle(基于深度學習的軌道缺陷檢測系統(tǒng))self.setGeometry(100,100,1000,700)self.detectorRailDefectDetector()self.capNoneself.timerQTimer()self.timer.timeout.connect(self.update_frame)self.setup_ui()defsetup_ui(self):central_widgetQWidget()self.setCentralWidget(central_widget)main_layoutQHBoxLayout(central_widget)# 左側顯示區(qū)left_panelQWidget()left_layoutQVBoxLayout(left_panel)self.image_labelQLabel()self.image_label.setAlignment(Qt.AlignCenter)self.image_label.setStyleSheet(border: 2px solid #007BFF;)left_layout.addWidget(self.image_label)# 右側控制區(qū)right_panelQWidget()right_layoutQVBoxLayout(right_panel)# 文件輸入self.file_inputQLineEdit()self.file_input.setPlaceholderText(請選擇圖片或視頻文件...)self.btn_openQPushButton(打開文件)self.btn_open.clicked.connect(self.open_file)right_layout.addWidget(self.file_input)right_layout.addWidget(self.btn_open)# 檢測結果self.result_textQTextEdit()self.result_text.setReadOnly(True)right_layout.addWidget(self.result_text)# 操作按鈕self.btn_startQPushButton(開始檢測)self.btn_start.clicked.connect(self.start_detection)self.btn_stopQPushButton(停止檢測)self.btn_stop.clicked.connect(self.stop_detection)right_layout.addWidget(self.btn_start)right_layout.addWidget(self.btn_stop)# 保存按鈕self.btn_saveQPushButton(保存結果)self.btn_save.clicked.connect(self.save_result)right_layout.addWidget(self.btn_save)main_layout.addWidget(left_panel,stretch2)main_layout.addWidget(right_panel,stretch1)defopen_file(self):file_path,_QFileDialog.getOpenFileName(self,選擇文件,,圖像文件 (*.jpg *.png);;視頻文件 (*.mp4 *.avi))iffile_path:self.file_input.setText(file_path)self.detect_and_show(file_path)defdetect_and_show(self,path):ifpath.lower().endswith((.jpg,.png)):detections,imgself.detector.detect_image(path)self.show_image(img)self.display_results(detections)elifpath.lower().endswith((.mp4,.avi)):self.video_pathpath self.start_detection()defstart_detection(self):ifself.file_input.text().lower().endswith((.mp4,.avi)):self.capcv2.VideoCapture(self.file_input.text())self.timer.start(30)self.btn_start.setEnabled(False)self.btn_stop.setEnabled(True)else:self.detect_and_show(self.file_input.text())defstop_detection(self):ifself.cap:self.cap.release()self.timer.stop()self.btn_start.setEnabled(True)self.btn_stop.setEnabled(False)defupdate_frame(self):ret,frameself.cap.read()ifret:resultsself.detector.model(frame,conf0.4,iou0.5)annotated_frameresults[0].plot()self.show_image(annotated_frame)self.display_results(results[0].boxes.cpu().numpy())defshow_image(self,img):h,w,chimg.shape bytes_per_linech*w q_imgQImage(img.data,w,h,bytes_per_line,QImage.Format_BGR888)pixmapQPixmap.fromImage(q_img).scaled(600,600,Qt.KeepAspectRatio)self.image_label.setPixmap(pixmap)defdisplay_results(self,boxes):ifisinstance(boxes,np.ndarray):boxesboxes[0]# 處理單幀結果results[]forboxinboxes:x1,y1,x2,y2map(int,box.xyxy[0])conffloat(box.conf[0])clsint(box.cls[0])class_nameself.detector.class_names[cls]results.append(f類別:{class_name}, 置信度:{conf:.2f}, 位置: [{x1},{y1},{x2},{y2}])self.result_text.setText(
.join(results))defsave_result(self):# 保存檢測結果到文件pass# 可擴展為保存圖片或日志if__name____main__:appQApplication(sys.argv)windowRailDefectApp()window.show()sys.exit(app.exec_()) 七、運行步驟安裝依賴pipinstall-r requirements.txt運行主程序cdUIProgram python MainProgram.py點擊“打開文件”選擇圖片或視頻點擊“開始檢測”進行識別檢測結果自動顯示在右側窗口? 功能亮點功能支持? 圖片檢測? JPG/PNG 視頻檢測? MP4/AVI 攝像頭實時檢測? 調用電腦攝像頭 多類別彩色標注? 每類獨立顏色 結果文本輸出? 類別 置信度 坐標?? 模型可替換? 修改models/rail_best.pt即可以上文字及代碼僅供參考