当前位置: 首页 > news >正文

app调用网站天津自动seo

app调用网站,天津自动seo,内蒙古建筑信息平台,网络营销渠道的特点前言 近期看了一些小目标检测的文章#xff0c;尽管基于 Ultralytics 框架进行 YOLO 系列算法的改进较为便捷#xff0c;但开源的却又很少或是开源了但很水#xff0c;而越来越多的研究工作与工业项目开始采用 mmdet作为算法开发的基础框架。为更好地理解和应用当前主流检测…前言 近期看了一些小目标检测的文章尽管基于 Ultralytics 框架进行 YOLO 系列算法的改进较为便捷但开源的却又很少或是开源了但很水而越来越多的研究工作与工业项目开始采用 mmdet作为算法开发的基础框架。为更好地理解和应用当前主流检测算法并为进一步的算法优化与实验打下基础本教程将聚焦于 MMDetection 的基础使用带领大家快速搭建环境、跑通预训练模型并完成基础训练与推理流程。后续我们再逐步深入探讨如何在该框架下实现自定义模块改进与实验迭代。 配置环境 前两年因为要使用mmcv的一个函数写了一个简单的教程没想到看的还挺多的详细参考这篇MMCV与MMDetection安装指南_mmcv安装-CSDN博客。 不想看的如果你的cuda是大于我这里的11.8的就可以直接使用我下面的指令安装。 接下来我将给出我的环境创建命令; conda create --name openmmlab python3.8 -y 激活此环境; conda activate openmmlab 安装pytorch; pip install torch2.0.0 torchvision0.15.1 --index-url https://download.pytorch.org/whl/cu118 安装mmcv2.0.1因为mmengine要求mmcv2.0.02.1.0。如果安装较慢就进入下面的网站找到对应的whl文件下载然后进行本地的安装。 pip install mmcv2.0.1 -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html 安装mmengine我这里的版本是0.10.7。 pip install mmengine通过源码安装mmdet我这里是最新版的3.3.0。 git clone https://github.com/open-mmlab/mmdetection.gitcd mmdetectionpip install -v -e . 以上完成后基本就没什么问题如果后续需要使用mim那就还要安装OpenMIM pip install -U openmim 数据集结构 因为mmdet的集成度很高我们需要了解一下它的数据集的构建结构后续我们自己做实验就按照这一种方式来即可官方是支持coco数据集的格式的那我这里就选择VisDrone2019数据集作为测试。这样方便我们本地的训练和测试下载后解压到./mmdetection/data文件夹下。 如果你之前使用过Ultralytics可以通过以下方式将数据集下载下来 from ultralytics import YOLO# Load a model model YOLO(yolo11n.pt) # load a pretrained model (recommended for training)# Train the model results model.train(dataVisDrone.yaml, epochs100, imgsz640) 当然你也可以使用从官方的github中下载VisDrone/VisDrone-Dataset 然后根据这篇文章的方法转换将visdrone2019数据集转换为COCO格式我下面对json的存储方式做了一点小小的修正。 将visdrone数据集转换为COCO格式 import os import cv2 from PIL import Image from tqdm import tqdm import jsondef convert_to_cocodetection(dir, output_dir):# 数据目录train_dir os.path.join(dir, train)val_dir os.path.join(dir, val)test_dir os.path.join(dir, test)# 数据标注目录train_annotations os.path.join(train_dir, annotations)val_annotations os.path.join(val_dir, annotations)test_annotations os.path.join(test_dir, annotations)# 数据影像目录train_images os.path.join(train_dir, images)val_images os.path.join(val_dir, images)test_images os.path.join(test_dir, images)id_num 0categories [{id: 0, name: pedestrian},{id: 1, name: people},{id: 2, name: bicycle},{id: 3, name: car},{id: 4, name: van},{id: 5, name: truck},{id: 6, name: tricycle},{id: 7, name: awning-tricycle},{id: 8, name: bus},{id: 9, name: motor},]for mode in [train, val, test]:images []annotations []print(fstart loading {mode} data...)if mode train:set os.listdir(train_annotations)annotations_path train_annotationsimages_path train_imageselif mode test:set os.listdir(test_annotations)annotations_path test_annotationsimages_path test_imageselse:set os.listdir(val_annotations)annotations_path val_annotationsimages_path val_imagesfor i in tqdm(set):f open(annotations_path / i, r)name i.replace(.txt, )# images属性image {}image_file_path images_path os.sep name .jpgprint(image_file_path)img_size Image.open((images_path os.sep name .jpg)).sizewidth, height img_size# height, width cv2.imread(images_path os.sep name .jpg).shape[:2]file_name name .jpgimage[id] nameimage[height] heightimage[width] widthimage[file_name] file_nameimages.append(image)for line in f.readlines():# annotation属性annotation {}line line.replace(\n, )if line.endswith(,): # filter dataline line.rstrip(,)line_list [int(i) for i in line.split(,)]if (line_list[4] 1 and 0 line_list[5] 11): # class 0 为 ignore region class 11 为others 目标检测任务中忽略bbox_xywh [line_list[0], line_list[1], line_list[2], line_list[3]]annotation[id] id_numannotation[image_id] nameannotation[category_id] int(line_list[5] - 1) # yolo检测结果标签从0开始 为了与结果对齐 -1annotation[area] bbox_xywh[2] * bbox_xywh[3]# annotation[score] line_list[4]annotation[bbox] bbox_xywhannotation[iscrowd] 0id_num 1annotations.append(annotation)dataset_dict {}dataset_dict {}dataset_dict[images] imagesdataset_dict[annotations] annotationsdataset_dict[categories] categoriesjson_str json.dumps(dataset_dict, indent4, ensure_asciiFalse)with open(f{output_dir}/annotation_{mode}.json, w, encodingutf-8) as json_file:json_file.write(json_str)print(json file write done...)def get_test_namelist(dir, out_dir):full_path out_dir / test.txtfile open(full_path, w)for name in tqdm(os.listdir(dir)):name name.replace(.txt, )file.write(name \n)file.close()return Nonedef centerxywh_to_xyxy(boxes):args:boxes:list of center_x,center_y,width,height,return:boxes:list of x,y,x,y,cooresponding to top left and bottom rightx_top_left boxes[0] - boxes[2] / 2y_top_left boxes[1] - boxes[3] / 2x_bottom_right boxes[0] boxes[2] / 2y_bottom_right boxes[1] boxes[3] / 2return [x_top_left, y_top_left, x_bottom_right, y_bottom_right]def centerxywh_to_topleftxywh(boxes):args:boxes:list of center_x,center_y,width,height,return:boxes:list of x,y,x,y,cooresponding to top left and bottom rightx_top_left boxes[0] - boxes[2] / 2y_top_left boxes[1] - boxes[3] / 2width boxes[2]height boxes[3]return [x_top_left, y_top_left, width, height]def clamp(coord, width, height):if coord[0] 0:coord[0] 0if coord[1] 0:coord[1] 0if coord[2] width:coord[2] widthif coord[3] height:coord[3] heightreturn coordif __name__ __main__:convert_to_cocodetection(E:\PythonProject\mmdetection\data\VisDrone,rE:\PythonProject\mmdetection\data\VisDrone\annotations) 请注意此数据集的标签是从0到11类’ignored regions’,‘pedestrian’,‘people’,‘bicycle’,‘car’,‘van’, ‘truck’,‘tricycle’,‘awning-tricycle’,‘bus’,‘motor’,‘others’0和11是不需要去训练的。 准备配置文件 我们需要准备配置文件来成功加载数据集这里以faster-rcnn为例。我们先找到它这里最基础的配置文件也就是faster-rcnn_r50_fpn_1x_coco.py。如果你不知道哪个是基本的配置文件你可以从名字长短短的一般都是以及其他文件中基础频率出现的多的就是哪个。 我这里选用的是继承faster-rcnn_r50_fpn_ciou_1x_coco.py。然后在./mmdetection/config/faster-rcnn下新建一个py文件命名为 faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py _base_ ./faster-rcnn_r50_fpn_ciou_1x_coco.py 这样就是在新配置中继承了基本配置在新配置文件中只需重新定义需要修改的字段即可覆盖基础配置中的相应部分。 首先修改模型的配置主要是num_classes等等 model dict(roi_headdict(bbox_headdict(typeShared2FCBBoxHead,in_channels256,fc_out_channels1024,roi_feat_size7,num_classes10,)) ) 其次修改数据集的相关配置没有使用测试集就用验证集如果路径弄不来就用绝对路径。 data_root rE:\PythonProject\mmdetection\data\VisDrone/ metainfo {classes: (pedestrian, people, bicycle, car, van, truck, tricycle, awning-tricycle, bus, motor),palette: [(220, 20, 60), # 行人 - 红色(255, 0, 0), # 人群 - 纯红色(0, 255, 0), # 自行车 - 绿色(0, 0, 255), # 汽车 - 蓝色(255, 165, 0), # 货车 - 橙色(128, 0, 128), # 卡车 - 紫色(255, 192, 203), # 三轮车 - 粉色(255, 215, 0), # 带篷三轮车 - 金色(0, 255, 255), # 公交车 - 青色(255, 0, 255) # 摩托车 - 洋红色] }train_dataloader dict(batch_size2,num_workers2,datasetdict(typeCocoDataset,data_rootdata_root,metainfometainfo,ann_fileannotations/annotation_train.json,data_prefixdict(imgtrain/images/),) )val_dataloader dict(batch_size1,num_workers2,datasetdict(typeCocoDataset,data_rootdata_root,metainfometainfo,ann_fileannotations/annotation_val.json,data_prefixdict(imgval/images/),) ) test_dataloader val_dataloader 修改超参数和评估参数 train_cfg dict(typeEpochBasedTrainLoop, # 训练循环的类型请参考 https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.pymax_epochs12,val_interval1) # 验证间隔。每个 epoch 验证一次 val_cfg dict(typeValLoop) test_cfg dict(typeTestLoop)optim_wrapper dict(typeOptimWrapper,optimizerdict( # 优化器配置。支持 PyTorch 的各种优化器。请参考 https://pytorch.org/docs/stable/optim.html#algorithmstypeSGD,lr0.02,momentum0.9,weight_decay0.0001),clip_gradNone, # 梯度裁剪的配置设置为 None 关闭梯度裁剪。使用方法请见 https://mmengine.readthedocs.io/en/latest/tutorials/optimizer.html) 然后下载预训练权重在./mmdetection/config/faster-rcnn这种文件夹下都有一个README.md文件你找到对应的预训练权重下载即可。 完整的配置文件如下所示更多的方法请查阅官方的文档学习配置文件 _base_ ./faster-rcnn_r50_fpn_ciou_1x_coco.pymodel dict(roi_headdict(bbox_headdict(typeShared2FCBBoxHead,in_channels256,fc_out_channels1024,roi_feat_size7,num_classes10,)) )data_root rE:\PythonProject\mmdetection\data\VisDrone/ metainfo {classes: (pedestrian, people, bicycle, car, van, truck, tricycle, awning-tricycle, bus, motor),palette: [(220, 20, 60), # 行人 - 红色(255, 0, 0), # 人群 - 纯红色(0, 255, 0), # 自行车 - 绿色(0, 0, 255), # 汽车 - 蓝色(255, 165, 0), # 货车 - 橙色(128, 0, 128), # 卡车 - 紫色(255, 192, 203), # 三轮车 - 粉色(255, 215, 0), # 带篷三轮车 - 金色(0, 255, 255), # 公交车 - 青色(255, 0, 255) # 摩托车 - 洋红色] }train_dataloader dict(batch_size2,num_workers2,datasetdict(typeCocoDataset,data_rootdata_root,metainfometainfo,ann_fileannotations/annotation_train.json,data_prefixdict(imgtrain/images/),) )val_dataloader dict(batch_size1,num_workers2,datasetdict(typeCocoDataset,data_rootdata_root,metainfometainfo,ann_fileannotations/annotation_val.json,data_prefixdict(imgval/images/),) ) test_dataloader val_dataloaderval_evaluator dict(typeCocoMetric,ann_filedata_root annotations/annotation_val.json,metricbbox,format_onlyFalse,backend_argsNone ) test_evaluator val_evaluatortrain_cfg dict(typeEpochBasedTrainLoop, # 训练循环的类型请参考 https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.pymax_epochs12,val_interval1) # 验证间隔。每个 epoch 验证一次 val_cfg dict(typeValLoop) test_cfg dict(typeTestLoop)optim_wrapper dict(typeAmpOptimWrapper, # OptimWrapperoptimizerdict(typeSGD,lr0.0025,momentum0.9,weight_decay0.0001),clip_gradNone, )default_hooks dict(timerdict(typeIterTimerHook),loggerdict(typeLoggerHook, interval300),param_schedulerdict(typeParamSchedulerHook),checkpointdict(typeCheckpointHook,interval1, # 每个epoch都检查一次是否最佳save_bestauto, # 核心参数自动选择最佳模型rulegreater, # 指标越大越好max_keep_ckpts3 # 只保留最近3个最佳模型避免磁盘爆炸),visualizationdict(typeDetVisualizationHook) )log_level INFO # 日志等级 load_from rE:\PythonProject\mmdetection\configs\faster_rcnn\faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth resume False # 是否从 load_from 中定义的检查点恢复。 如果 load_from 为 None它将恢复 work_dir 中的最新检查点。 如果你想在完整的配置文件上进行修改你可以尝试运行一遍train后在workdirs下会生成同名的文件这个就是完整配置的py文件了。如果遇到任何的问题可以通过官方仓库里的issueshttps://github.com/open-mmlab/mmdetection/issues查找。 最开始的时候我就是遇到了mmseg - INFO - Checkpoints will be saved to这里面相同的问题虽然我使用的是自制数据集但问题的本质是一样的。通过调整 num_workers 和 batch_size 参数后问题就解决了。通常这类显存不足的问题会直接抛出错误提示但我没想到在这种情况下程序会表现为停止不动没有任何明显的报错信息。 在VisDrone2019上进行训练和测试 训练 python tools/train.py E:\PythonProject\mmdetection\configs\faster_rcnn\faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py 测试 python tools/test.py E:\PythonProject\mmdetection\configs\faster_rcnn\faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py work_dirs/faster-rcnn_r50_fpn_ciou_1x_visdrone_2019/epoch_12.pth 结果如下所示 Average Precision  (AP) [ IoU0.50:0.95 | area   all | maxDets100 ] 0.267  Average Precision  (AP) [ IoU0.50      | area   all | maxDets1000 ] 0.434  Average Precision  (AP) [ IoU0.75      | area   all | maxDets1000 ] 0.286  Average Precision  (AP) [ IoU0.50:0.95 | area small | maxDets1000 ] 0.157  Average Precision  (AP) [ IoU0.50:0.95 | areamedium | maxDets1000 ] 0.397  Average Precision  (AP) [ IoU0.50:0.95 | area large | maxDets1000 ] 0.523  Average Recall     (AR) [ IoU0.50:0.95 | area   all | maxDets100 ] 0.360  Average Recall     (AR) [ IoU0.50:0.95 | area   all | maxDets300 ] 0.360  Average Recall     (AR) [ IoU0.50:0.95 | area   all | maxDets1000 ] 0.360  Average Recall     (AR) [ IoU0.50:0.95 | area small | maxDets1000 ] 0.243  Average Recall     (AR) [ IoU0.50:0.95 | areamedium | maxDets1000 ] 0.514  Average Recall     (AR) [ IoU0.50:0.95 | area large | maxDets1000 ] 0.625 09/19 11:12:51 - mmengine - INFO - bbox_mAP_copypaste: 0.267 0.434 0.286 0.157 0.397 0.523 09/19 11:12:51 - mmengine - INFO - Epoch(test) [548/548]    coco/bbox_mAP: 0.2670  coco/bbox_mAP_50: 0.4340  coco/bbox_mAP_75: 0.2860  coco/bbox_mAP_s: 0.1570  coco/bbox_mAP_m: 0.3970  coco/bbox_mAP_l: 0.5230  data_time: 0.0202  time: 0.0957 如果想要看看对比的效果图可以在后面加上下面的指令 --show --show-dir test_save 在使用Faster R-CNN (ResNet-50 FPN) 在VisDrone数据集上的训练完成后下面提供了一些工具的使用。 对结果进行分析 计算模型的参数量 python tools/analysis_tools/get_flops.py E:\PythonProject\mmdetection\configs\faster_rcnn\faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py显示推理时间、fps、gpu memory python tools/analysis_tools/benchmark.py E:\PythonProject\mmdetection\configs\faster_rcnn\faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py --checkpoint work_dirs/faster-rcnn_r50_fpn _ciou_1x_visdrone_2019/epoch_12.pth --task inference --fuse-conv-bn生成预测结果文件.pkl python tools/test.py E:\PythonProject\mmdetection\configs\faster_rcnn\faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py work_dirs/faster-rcnn_r50_fpn_ciou_1x_visdrone_2019/epoch_12.pth --out work_dirs/faster-rcnn_r50_fpn_ciou_1x_visdrone_2019/results.pkl生成混淆矩阵示意图 python tools/analysis_tools/confusion_matrix.py E:\PythonProject\mmdetection\configs\faster_rcnn\faster-rcnn_r50_fpn_ciou_1x_visdrone_2019.py work_dirs/faster-rcnn_r50_fpn_ciou_1x_visdrone_2019/results.pkl ./work_dirs/cm_output --show参考文章 在标准数据集上训练预定义的模型 — MMDetection 3.3.0 文档 将visdrone2019数据集转换为COCO格式_visdrone 转 coco-CSDN博客 将visdrone数据集转化为coco格式并在mmdetection上训练,附上转好的json文件_visdrone转coco-CSDN博客 一库打尽目标检测对比实验mmdetection环境、训练、测试手把手教程_哔哩哔哩_bilibili
http://www.zqtcl.cn/news/716476/

相关文章:

  • 做微商怎样加入网站卖东西赚钱做代理的项目在哪个网站
  • 企业电子商务网站平台建设奉贤做网站公司
  • 非凡网站建设 新三板代运营套餐价格表
  • 湖南建立网站营销设计网站建设的创新之处
  • 手机站是什么意思免费建论坛
  • 网站开发学习路线专用车网站建设哪家好
  • 贵阳网站建设端觉wordpress gif 点击播放
  • 苏州产品推广公司厦门关键词seo
  • 建设内网网站流程凡客诚品现在还有吗
  • 西安网站公司免费云手机无限时间版
  • 网站建设与管理案例教程ipad可以做网站吗
  • 济南网站建设模板python网站开发用什么软件
  • 北京品牌网站建设阿里巴巴logo图片
  • 做宣传册从哪个网站找素材中文在线っと好きだっ
  • 国际物流东莞网站建设wap是什么意思的缩写
  • 传奇官网百度seo营销网站
  • 如何在导航网站上做链接上海建筑设计研究院
  • 微信营销软件网站建设推广链接
  • 美的集团网站建设方案书广汉做网站
  • 个人博客网站实验报告商标购买网站
  • 2020给个免费网站好人有好报做购物微信网站
  • 做淘宝客网站挣钱济南百度竞价代运营
  • 国外网站404错误页网站地址搜索
  • 做 暧视频在线观看网站北京安卓app开发公司
  • h5哪个网站可以做惠州+企业网站建设
  • 网站运营知识哪个网站可以做免费商业推广
  • 电脑做网站怎么解析域名河南郑州静默管理
  • 项目网站制作冯提莫斗鱼前在哪个网站做直播
  • 网站建设 思路wordpress 访问记录插件
  • 网站建设diyseo课程培训班费用