网站建设优化一年赚几十万厦门软件开发培训机构

张小明 2026/1/12 22:03:36
网站建设优化一年赚几十万,厦门软件开发培训机构,找企业做网站,软件开发自学网轴承缺陷数据集#xff0c;3659张#xff0c;提供yolo和voc两种 所有代码仅供参考 轴承缺陷数据集#xff0c;3659张#xff0c;提供yolo和voc两种标注方式 8类#xff0c;标注数量#xff1a; Casting_burr#xff1a;铸造毛刺#xff0c;750 crack#xff1a;裂纹3659张提供yolo和voc两种所有代码仅供参考轴承缺陷数据集3659张提供yolo和voc两种标注方式8类标注数量Casting_burr铸造毛刺750crack裂纹1675scratch划痕2446pit凹坑843Polished_casting抛光铸件2180strain应变94unpolished_casting未抛光铸件742burr毛刺3image num图像数量3659数据准备、模型训练、评估和推理。整个项目结构和代码完整项目结构bearing_defect_detection/ ├── main.py ├── train.py ├── evaluate.py ├── infer.py ├── datasets/ │ ├── bearing_defects/ │ │ ├── Annotations/ │ │ ├── ImageSets/ │ │ │ └── Main/ │ │ │ ├── train.txt │ │ │ └── val.txt │ │ └── JPEGImages/ ├── best_bearing_defects.pt ├── requirements.txt └── data.yaml文件内容requirements.txtopencv-python torch1.9 ultralytics PyQt5data.yamltrain:./datasets/bearing_defects/JPEGImages/trainval:./datasets/bearing_defects/JPEGImages/valtest:./datasets/bearing_defects/JPEGImages/testnc:8names:[Casting_burr,crack,scratch,pit,Polished_casting,strain,unpolished_casting,burr]convert_voc_to_yolo.pyimportosimportxml.etree.ElementTreeasETimportshutilimportcv2defxml_to_yolo(xml_file,image_width,image_height):yolo_labels[]treeET.parse(xml_file)roottree.getroot()forobjinroot.findall(object):labelobj.find(name).text bboxobj.find(bndbox)xminint(bbox.find(xmin).text)yminint(bbox.find(ymin).text)xmaxint(bbox.find(xmax).text)ymaxint(bbox.find(ymax).text)x_center(xminxmax)/2.0/image_width y_center(yminymax)/2.0/image_height width(xmax-xmin)/image_width height(ymax-ymin)/image_height class_id{Casting_burr:0,crack:1,scratch:2,pit:3,Polished_casting:4,strain:5,unpolished_casting:6,burr:7}[label]yolo_labels.append(f{class_id}{x_center}{y_center}{width}{height})return\n.join(yolo_labels)defsplit_dataset(image_dir,annotations_dir,output_dir,train_ratio0.8):images[fforfinos.listdir(image_dir)iff.endswith(.jpg)]num_trainint(len(images)*train_ratio)train_imagesimages[:num_train]val_imagesimages[num_train:]withopen(os.path.join(output_dir,ImageSets/Main/train.txt),w)asf:f.write(\n.join([os.path.splitext(img)[0]forimgintrain_images]))withopen(os.path.join(output_dir,ImageSets/Main/val.txt),w)asf:f.write(\n.join([os.path.splitext(img)[0]forimginval_images]))defconvert_dataset(voc_dir,yolo_dir):annotations_diros.path.join(voc_dir,Annotations)images_diros.path.join(voc_dir,JPEGImages)yolo_labels_diros.path.join(yolo_dir,labels)os.makedirs(yolo_labels_dir,exist_okTrue)os.makedirs(os.path.join(yolo_dir,images),exist_okTrue)os.makedirs(os.path.join(yolo_dir,images/train),exist_okTrue)os.makedirs(os.path.join(yolo_dir,images/val),exist_okTrue)os.makedirs(os.path.join(yolo_dir,ImageSets/Main),exist_okTrue)split_dataset(images_dir,annotations_dir,yolo_dir)forfilenameinos.listdir(annotations_dir):iffilename.endswith(.xml):xml_fileos.path.join(annotations_dir,filename)image_filenameos.path.splitext(filename)[0].jpgimage_pathos.path.join(images_dir,image_filename)imagecv2.imread(image_path)image_height,image_width,_image.shape yolo_labelxml_to_yolo(xml_file,image_width,image_height)txt_filenameos.path.splitext(filename)[0].txttxt_fileos.path.join(yolo_labels_dir,txt_filename)withopen(txt_file,w)asf:f.write(yolo_label)# Copy image to YOLO directorybase_image_diros.path.join(yolo_dir,images)ifimage_filename.split(.)[0]in[line.strip()forlineinopen(os.path.join(yolo_dir,ImageSets/Main/train.txt))]:target_image_diros.path.join(base_image_dir,train)else:target_image_diros.path.join(base_image_dir,val)shutil.copy(image_path,target_image_dir)# 示例用法convert_dataset(./datasets/bearing_defects,./datasets/bearing_defects_yolo)train.pyimporttorchfromultralyticsimportYOLO# 设置随机种子以保证可重复性torch.manual_seed(42)# 定义数据集路径dataset_configdata.yaml# 加载预训练的YOLOv8n模型modelYOLO(yolov8n.pt)# 训练模型resultsmodel.train(datadataset_config,epochs50,imgsz640,batch16,namebearing_defects,projectruns/train)# 评估模型metricsmodel.val()# 保存最佳模型权重best_model_weightsruns/train/bearing_defects/weights/best.ptprint(f最佳模型权重已保存到{best_model_weights})evaluate.pyfromultralyticsimportYOLO# 初始化YOLOv8模型modelYOLO(runs/train/bearing_defects/weights/best.pt)# 评估模型metricsmodel.val()# 打印评估结果print(metrics)infer.pyimportsysimportcv2importnumpyasnpfromultralyticsimportYOLOfromPyQt5.QtWidgetsimportQApplication,QMainWindow,QFileDialog,QMessageBox,QLabel,QPushButtonfromPyQt5.QtGuiimportQImage,QPixmapfromPyQt5.QtCoreimportQTimerclassMainWindow(QMainWindow):def__init__(self):super(MainWindow,self).__init__()self.setWindowTitle(轴承缺陷检测)self.setGeometry(100,100,800,600)# 初始化YOLOv8模型self.modelYOLO(runs/train/bearing_defects/weights/best.pt)# 设置类别名称self.class_names[Casting_burr,crack,scratch,pit,Polished_casting,strain,unpolished_casting,burr]# 创建界面元素self.label_displayQLabel(self)self.label_display.setGeometry(10,10,780,400)self.button_select_imageQPushButton(选择图片,self)self.button_select_image.setGeometry(10,420,150,30)self.button_select_image.clicked.connect(self.select_image)self.button_select_videoQPushButton(选择视频,self)self.button_select_video.setGeometry(170,420,150,30)self.button_select_video.clicked.connect(self.select_video)self.button_start_cameraQPushButton(开始摄像头,self)self.button_start_camera.setGeometry(330,420,150,30)self.button_start_camera.clicked.connect(self.start_camera)self.button_stop_cameraQPushButton(停止摄像头,self)self.button_stop_camera.setGeometry(490,420,150,30)self.button_stop_camera.clicked.connect(self.stop_camera)self.timerQTimer()self.timer.timeout.connect(self.update_frame)self.capNoneself.results[]defselect_image(self):optionsQFileDialog.Options()file_path,_QFileDialog.getOpenFileName(self,选择图片,,图片 (*.jpg *.jpeg *.png);;所有文件 (*),optionsoptions)iffile_path:self.process_image(file_path)defprocess_image(self,image_path):framecv2.imread(image_path)resultsself.model(frame)annotated_frameself.draw_annotations(frame,results)self.display_image(annotated_frame)self.results.append((image_path,annotated_frame))defselect_video(self):optionsQFileDialog.Options()file_path,_QFileDialog.getOpenFileName(self,选择视频,,视频 (*.mp4 *.avi);;所有文件 (*),optionsoptions)iffile_path:self.process_video(file_path)defprocess_video(self,video_path):self.capcv2.VideoCapture(video_path)whileself.cap.isOpened():ret,frameself.cap.read()ifnotret:breakresultsself.model(frame)annotated_frameself.draw_annotations(frame,results)self.display_image(annotated_frame)self.results.append((video_path,annotated_frame))ifcv2.waitKey(1)0xFFord(q):breakself.cap.release()defstart_camera(self):self.capcv2.VideoCapture(0)self.timer.start(30)defstop_camera(self):self.timer.stop()ifself.capisnotNone:self.cap.release()self.label_display.clear()defupdate_frame(self):ret,frameself.cap.read()ifnotret:returnresultsself.model(frame)annotated_frameself.draw_annotations(frame,results)self.display_image(annotated_frame)self.results.append((camera,annotated_frame))defdraw_annotations(self,frame,results):forresultinresults:boxesresult.boxes.cpu().numpy()forboxinboxes:rbox.xyxy[0].astype(int)clsint(box.cls[0])confbox.conf[0]labelf{self.class_names[cls]}{conf:.2f}color(0,255,0)cv2.rectangle(frame,(r[0],r[1]),(r[2],r[3]),color,2)cv2.putText(frame,label,(r[0],r[1]-10),cv2.FONT_HERSHEY_SIMPLEX,0.9,color,2)returnframedefdisplay_image(self,frame):rgb_imagecv2.cvtColor(frame,cv2.COLOR_BGR2RGB)h,w,chrgb_image.shape bytes_per_linech*w qt_imageQImage(rgb_image.data,w,h,bytes_per_line,QImage.Format_RGB888)pixmapQPixmap.fromImage(qt_image)self.label_display.setPixmap(pixmap.scaled(self.label_display.width(),self.label_display.height()))if__name____main__:appQApplication(sys.argv)windowMainWindow()window.show()sys.exit(app.exec_())运行步骤总结克隆项目仓库如果有的话gitclone https://github.com/yourusername/bearing_defect_detection.gitcdbearing_defect_detection安装依赖项pipinstall-r requirements.txt转换数据集格式python convert_voc_to_yolo.py训练模型python train.py评估模型python evaluate.py运行推理界面python infer.py操作界面选择图片进行检测。选择视频进行检测。使用摄像头进行实时检测。结果展示你可以通过以下方式查看演示视频用上述步骤运行infer.py并按照界面上的按钮操作。希望这些详细的信息和代码能够帮助你顺利实施和优化你的轴承缺陷检测系统。如果有其他需求或问题请随时告知详细解释requirements.txt列出项目所需的所有Python包及其版本。data.yaml配置数据集路径和类别信息用于YOLOv8模型训练。convert_voc_to_yolo.py将VOC格式的数据集转换为YOLO格式。读取XML标注文件并将其转换为YOLO所需的TXT标签格式。同时将数据集分为训练集和验证集。train.py加载预训练的YOLOv8模型并使用自定义数据集进行训练。训练完成后评估模型并保存最佳模型权重。evaluate.py加载训练好的YOLOv8模型并对验证集进行评估打印评估结果。infer.py创建一个GUI应用程序支持选择图片、视频或使用摄像头进行实时检测并显示检测结果。
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

生鲜网站怎么做云南网站推广公司

因为开发需要使用 带界面的仿真软件,而以往的使用习惯基本都是 SSH 登录虚拟机即可满足需求。 但这次遇到两个现实问题: 现有虚拟机系统为 Ubuntu 18.04仿真软件要求 Ubuntu 22.04 GUI 最终选择的方案是: 基于 Docker 构建一套 Ubuntu 2…

张小明 2026/1/6 1:30:34 网站建设

国内最炫酷的网站网页游戏排行榜推选新壹玩

70款H5游戏整合小游戏平台网站源码,测试有几个缺失素材,绝大部分都可以玩的,类型多,小游戏平台网站源码,70个H5游戏整合。 包含消消乐、捕鱼、象棋等。 源码下载: https://download.csdn.net/download/m0…

张小明 2026/1/6 4:40:43 网站建设

p2p网站建设cms精仿手表网站

BBDown_GUI终极指南:5分钟掌握B站视频批量下载技巧 【免费下载链接】BBDown_GUI BBDown的图形化版本 项目地址: https://gitcode.com/gh_mirrors/bb/BBDown_GUI BBDown_GUI是一款专为哔哩哔哩视频下载设计的图形化界面工具,它让原本复杂的命令行操…

张小明 2026/1/5 5:08:20 网站建设

做网站如何设计数据库做汽车网站费用

游戏测试的独特技术挑战 游戏测试作为软件测试的一个高度专业化分支,面临着传统业务系统测试中极少遇到的复杂技术挑战。与注重功能正确性和数据准确性的传统软件测试不同,游戏测试需要平衡技术验证与玩家体验的双重目标,这催生了一系列专属…

张小明 2026/1/5 7:06:59 网站建设

长春 建网站珠海建站论坛

互联网大厂Java面试:音视频场景下的技术栈深度解析 场景设定 在一场互联网大厂的Java开发岗位面试中,面试官和水货程序员谢飞机展开了一场关于音视频场景的技术讨论。谢飞机虽有点小聪明,但面对复杂问题时常含糊其辞。 第一轮提问 1. 请简…

张小明 2026/1/7 13:13:51 网站建设

镇江市住房与城乡建设局网站网页制作公司介绍

Label Studio国际化实战:从零搭建多语言数据标注平台 【免费下载链接】label-studio 项目地址: https://gitcode.com/gh_mirrors/lab/label-studio 当你的团队遍布全球,而数据标注工具却只显示单一语言时,工作效率会大打折扣。本文将手…

张小明 2026/1/6 2:58:48 网站建设