网站设计模板旅游景点11页,唐河永琚建筑公司网站,女生学数字媒体技术难吗,北京做网站建设公司VOC数据图像和标签一起进行Resize
参加检测比赛的时候#xff0c;很多时候工业原始数据尺度都比较大#xff0c;如果对数据不提前进行处理#xff0c;会导致数据在加载进内存时花费大量的时间#xff0c;所以在执行训练程序之前需要将图像提前进行预处理。对于目标检测的数…VOC数据图像和标签一起进行Resize
参加检测比赛的时候很多时候工业原始数据尺度都比较大如果对数据不提前进行处理会导致数据在加载进内存时花费大量的时间所以在执行训练程序之前需要将图像提前进行预处理。对于目标检测的数据不只是将原始数据进行resize边界框的坐标也要跟随一起进行resize。
如下是今天测试需要用到的原始图像和他的标签。 annotationfolderVOC2012/folderfilename2007_002266.jpg/filenamesourcedatabaseThe VOC2007 Database/databaseannotationPASCAL VOC2007/annotationimageflickr/image/sourcesizewidth500/widthheight373/heightdepth3/depth/sizesegmented1/segmentedobjectnameaeroplane/nameposeRear/posetruncated1/truncateddifficult0/difficultbndboxxmin231/xminymin251/yminxmax458/xmaxymax346/ymax/bndbox/objectobjectnameaeroplane/nameposeLeft/posetruncated0/truncateddifficult0/difficultbndboxxmin5/xminymin118/yminxmax499/xmaxymax258/ymax/bndbox/object
/annotation
等比例缩放之后的结果如下。 单张图像resize
单张进行预处理的脚本如下。
# -*- coding: utf-8 -*-
# File : PreProcessing.py
# Author: 肆十二
# Date : 2023/12/24
# Desc : 同步缩放图片等比例缩放无失真和xml文件标注的anchor size
import glob
import xml.dom.minidom
import cv2img cv2.imread(./demo.jpg)
height, width img.shape[:2]# 定义缩放信息 以等比例缩放到416为例
scale416/height
height416
widthint(width*scale)dom xml.dom.minidom.parse(./demo.xml)
root dom.documentElement# 读取标注目标框
objects root.getElementsByTagName(bndbox)for object in objects:xminobject.getElementsByTagName(xmin)xmin_dataint(float(xmin[0].firstChild.data))# xmin[0].firstChild.data str(int(xmin1 * x))ymin object.getElementsByTagName(ymin)ymin_data int(float(ymin[0].firstChild.data))xmaxobject.getElementsByTagName(xmax)xmax_data int(float(xmax[0].firstChild.data))ymaxobject.getElementsByTagName(ymax)ymax_data int(float(ymax[0].firstChild.data))# 更新xmlwidth_xmlroot.getElementsByTagName(width)width_xml[0].firstChild.datawidthheight_xml root.getElementsByTagName(height)height_xml[0].firstChild.data heightxmin[0].firstChild.data int(xmin_data*scale)ymin[0].firstChild.data int(ymin_data*scale)xmax[0].firstChild.data int(xmax_data*scale)ymax[0].firstChild.data int(ymax_data*scale)# 另存更新后的文件with open(demo2.xml, w) as f:dom.writexml(f, addindent , encodingutf-8)# 测试缩放效果img cv2.resize(img, (width, height))# xmin, ymin, xmax, ymax分别为xml读取的坐标信息left_top (int(xmin_data*scale), int(ymin_data*scale))right_down (int(xmax_data*scale), int(ymax_data*scale))cv2.rectangle(img, left_top, right_down, (255, 0, 0), 1)cv2.imwrite(result.jpg,img)
批量resize
下面是批量对VOC格式数据集进行预处理的脚本处理之后划分为37的比例就可以进行模型训练了。
import glob
import xml.dom.minidom
import cv2
from PIL import Image
import matplotlib.pyplot as plt
import os# 定义待批量裁剪图像的路径地址
IMAGE_INPUT_PATH rD:\code\data\JPEGImages
XML_INPUT_PATH rD:\code\data\Annotations_new
# 定义裁剪后的图像存放地址
IMAGE_OUTPUT_PATH rD:\code\data\JPEGImages_out
XML_OUTPUT_PATH rD:\code\data\Annotations_out
imglist os.listdir(IMAGE_INPUT_PATH)
xmllist os.listdir(XML_INPUT_PATH)for i in range(len(imglist)):# 每个图像全路径这里有改进的空间image_input_fullname IMAGE_INPUT_PATH / imglist[i]# xml_input_fullname XML_INPUT_PATH / xmllist[i] xml_input_fullname XML_INPUT_PATH / imglist[i].replace(jpg, xml)image_output_fullname IMAGE_OUTPUT_PATH / imglist[i]xml_output_fullname XML_OUTPUT_PATH / xmllist[i]img cv2.imread(image_input_fullname)height, width img.shape[:2]# 定义缩放信息 以等比例缩放到416为例scale400/heightheight400widthint(width*scale)dom xml.dom.minidom.parse(xml_input_fullname)root dom.documentElement# 读取标注目标框objects root.getElementsByTagName(bndbox)for object in objects:xminobject.getElementsByTagName(xmin)xmin_dataint(float(xmin[0].firstChild.data))# xmin[0].firstChild.data str(int(xmin1 * x))ymin object.getElementsByTagName(ymin)ymin_data int(float(ymin[0].firstChild.data))xmaxobject.getElementsByTagName(xmax)xmax_data int(float(xmax[0].firstChild.data))ymaxobject.getElementsByTagName(ymax)ymax_data int(float(ymax[0].firstChild.data))# 更新xmlwidth_xmlroot.getElementsByTagName(width)width_xml[0].firstChild.datawidthheight_xml root.getElementsByTagName(height)height_xml[0].firstChild.data heightxmin[0].firstChild.data int(xmin_data*scale)ymin[0].firstChild.data int(ymin_data*scale)xmax[0].firstChild.data int(xmax_data*scale)ymax[0].firstChild.data int(ymax_data*scale)# 另存更新后的文件with open(xml_output_fullname, w) as f:dom.writexml(f, addindent , encodingutf-8)# 测试缩放效果img cv2.resize(img, (width, height))# xmin, ymin, xmax, ymax分别为xml读取的坐标信息left_top (int(xmin_data*scale), int(ymin_data*scale))right_down (int(xmax_data*scale), int(ymax_data*scale))cv2.rectangle(img, left_top, right_down, (255, 0, 0), 1)cv2.imwrite(image_output_fullname,img)总结
当前的目标检测框架中模型方面基本都已经固定下来YOLO或者RCNN靠模型很难取得大规模的增点所以这个时候从图像的角度进行入手显得非常重要这里推荐大家使用一个专业的切图工具。
链接如下GitHub - obss/sahi: Framework agnostic sliced/tiled inference interactive ui error analysis plots
碎碎念数据预处理真的很关键啊好的数据预处理真的可以节省大量的时间。 文章转载自: http://www.morning.pqndg.cn.gov.cn.pqndg.cn http://www.morning.dtrcl.cn.gov.cn.dtrcl.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.wbyqy.cn.gov.cn.wbyqy.cn http://www.morning.rnyhx.cn.gov.cn.rnyhx.cn http://www.morning.pabxcp.com.gov.cn.pabxcp.com http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn http://www.morning.pbwcq.cn.gov.cn.pbwcq.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.prgyd.cn.gov.cn.prgyd.cn http://www.morning.xplng.cn.gov.cn.xplng.cn http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.znqxt.cn.gov.cn.znqxt.cn http://www.morning.dpdns.cn.gov.cn.dpdns.cn http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn http://www.morning.zhoer.com.gov.cn.zhoer.com http://www.morning.dwkfx.cn.gov.cn.dwkfx.cn http://www.morning.zmzdx.cn.gov.cn.zmzdx.cn http://www.morning.gpryk.cn.gov.cn.gpryk.cn http://www.morning.lwgrf.cn.gov.cn.lwgrf.cn http://www.morning.pigcamp.com.gov.cn.pigcamp.com http://www.morning.xcdph.cn.gov.cn.xcdph.cn http://www.morning.lsmgl.cn.gov.cn.lsmgl.cn http://www.morning.ryzgp.cn.gov.cn.ryzgp.cn http://www.morning.qqklk.cn.gov.cn.qqklk.cn http://www.morning.trnhy.cn.gov.cn.trnhy.cn http://www.morning.hbywj.cn.gov.cn.hbywj.cn http://www.morning.nlryq.cn.gov.cn.nlryq.cn http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.kjsft.cn.gov.cn.kjsft.cn http://www.morning.xwqxz.cn.gov.cn.xwqxz.cn http://www.morning.xbmwh.cn.gov.cn.xbmwh.cn http://www.morning.wfykn.cn.gov.cn.wfykn.cn http://www.morning.dpruuode.cn.gov.cn.dpruuode.cn http://www.morning.fbfnk.cn.gov.cn.fbfnk.cn http://www.morning.zxybw.cn.gov.cn.zxybw.cn http://www.morning.tqldj.cn.gov.cn.tqldj.cn http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn http://www.morning.bpyps.cn.gov.cn.bpyps.cn http://www.morning.qtsks.cn.gov.cn.qtsks.cn http://www.morning.yrhd.cn.gov.cn.yrhd.cn http://www.morning.zlxrg.cn.gov.cn.zlxrg.cn http://www.morning.gjxr.cn.gov.cn.gjxr.cn http://www.morning.wklmj.cn.gov.cn.wklmj.cn http://www.morning.xhsxj.cn.gov.cn.xhsxj.cn http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn http://www.morning.hmwjk.cn.gov.cn.hmwjk.cn http://www.morning.yrccw.cn.gov.cn.yrccw.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.nsrlb.cn.gov.cn.nsrlb.cn http://www.morning.fwmln.cn.gov.cn.fwmln.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.kzbpx.cn.gov.cn.kzbpx.cn http://www.morning.ngqdp.cn.gov.cn.ngqdp.cn http://www.morning.ywtbk.cn.gov.cn.ywtbk.cn http://www.morning.ptmch.com.gov.cn.ptmch.com http://www.morning.krjrb.cn.gov.cn.krjrb.cn http://www.morning.dsncg.cn.gov.cn.dsncg.cn http://www.morning.ddrdt.cn.gov.cn.ddrdt.cn http://www.morning.xsbhg.cn.gov.cn.xsbhg.cn http://www.morning.jkzq.cn.gov.cn.jkzq.cn http://www.morning.ydhmt.cn.gov.cn.ydhmt.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.bnxnq.cn.gov.cn.bnxnq.cn http://www.morning.tpnch.cn.gov.cn.tpnch.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.yhwmg.cn.gov.cn.yhwmg.cn http://www.morning.mdrnn.cn.gov.cn.mdrnn.cn http://www.morning.ygztf.cn.gov.cn.ygztf.cn http://www.morning.rgxcd.cn.gov.cn.rgxcd.cn http://www.morning.bwjgb.cn.gov.cn.bwjgb.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.dbrpl.cn.gov.cn.dbrpl.cn http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.lhhdy.cn.gov.cn.lhhdy.cn http://www.morning.rjfr.cn.gov.cn.rjfr.cn http://www.morning.czcbl.cn.gov.cn.czcbl.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn