没有合适的资源?快使用搜索试试~ 我知道了~
首页对小样本数据进行数据增强
一、前情介绍 在之前对yolov3的学习中,有时候发现小样本数据集容易出现过拟合或者泛化能力不强的问题,在对这一问题提出的不同解决方法进行了摸索和尝试,发现提高数据集样本容量是一个比较直接和简单粗暴的方法,以下纪录这一实验方法。 二、环境 直接交代环境,都是相对较简单,在这里博主没遇到过坑 os numpy PIL imgaug 三、代码 import xml.etree.ElementTree as ET import os import numpy as np from PIL import Image import shutil import imgaug as ia from imga
资源详情
资源评论
资源推荐

对小样本数据进行数据增强对小样本数据进行数据增强
一、前情介绍一、前情介绍
在之前对yolov3的学习中,有时候发现小样本数据集容易出现过拟合或者泛化能力不强的问题,在对这一问题提出的不同解决方法进
行了摸索和尝试,发现提高数据集样本容量是一个比较直接和简单粗暴的方法,以下纪录这一实验方法。
二、环境二、环境
直接交代环境,都是相对较简单,在这里博主没遇到过坑
os
numpy
PIL
imgaug
三、代码三、代码
import xml.etree.ElementTree as ET
import os
import numpy as np
from PIL import Image
import shutil
import imgaug as ia
from imgaug import augmenters as iaa
ia.seed(1)
def read_xml_annotation(root, image_id):
in_file = open(os.path.join(root, image_id))
tree = ET.parse(in_file)
root = tree.getroot()
bndboxlist = []
for object in root.findall('object'): # 找到root节点下的所有country节点
bndbox = object.find('bndbox') # 子节点下节点rank的值
xmin = int(bndbox.find('xmin').text)
xmax = int(bndbox.find('xmax').text)
ymin = int(bndbox.find('ymin').text)
ymax = int(bndbox.find('ymax').text)
# print(xmin,ymin,xmax,ymax)
bndboxlist.append([xmin, ymin, xmax, ymax])
# print(bndboxlist)
bndbox = root.find('object').find('bndbox')
return bndboxlist
# (506.0000, 330.0000, 528.0000, 348.0000) -> (520.4747, 381.5080, 540.5596, 398.6603)
def change_xml_annotation(root, image_id, new_target):
new_xmin = new_target[0] new_ymin = new_target[1] new_xmax = new_target[2] new_ymax = new_target[3]
in_file = open(os.path.join(root, str(image_id) + '.xml')) # 这里root分别由两个意思
tree = ET.parse(in_file)
xmlroot = tree.getroot()
object = xmlroot.find('object')
bndbox = object.find('bndbox')
xmin = bndbox.find('xmin')
xmin.text = str(new_xmin)
ymin = bndbox.find('ymin')
ymin.text = str(new_ymin)
xmax = bndbox.find('xmax')
xmax.text = str(new_xmax)
ymax = bndbox.find('ymax')
ymax.text = str(new_ymax)
tree.write(os.path.join(root, str("%06d" % (str(id) + '.xml'))))
def change_xml_list_annotation(root, image_id, new_target, saveroot, id):
in_file = open(os.path.join(root, str(image_id) + '.xml')) # 这里root分别由两个意思
tree = ET.parse(in_file)
elem = tree.find('filename')
elem.text = (str("%06d" % int(id)) + '.jpg')
xmlroot = tree.getroot()
index = 0



















weixin_38643127
- 粉丝: 8
- 资源: 921
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

评论0