栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【copy

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【copy

这个脚本是一个针对小目标的数据增强类。理论知识来自这篇论文 Augmentation for small object detection.

import numpy as np
import random
import cv2
class copy_paste(object):
 def __init__(self, thresh 32*32, prob 0.5, copy_times 3, epochs 30, all_objects False, one_object False):
 self.thresh thresh
 self.prob prob,
 self.copy_time copy_times
 self.epochs epochs
 self.all_object all_objects
 self.one_object one_object
 def issmallobject(self, h, w):
 if h*w self.thresh:
 return True
 else:
 return False
 def compute_overlap(self, annot_a, annot_b):
 if annot_a is None: return False
 left_max max(annot_a[1], annot_b[1])
 top_max max(annot_a[2], annot_b[2])
 right_min min(annot_a[3], annot_b[3])
 bottom_min min(annot_a[4], annot_b[4])
 inter max(0, (right_min - left_max)) * max(0, (bottom_min - top_max))
 if inter ! 0:
 return True
 else:
 return False
 def donot_overlap(self, new_l, labels):
 for l in labels:
 if self.compute_overlap(new_l, l): return False
 return True
 def create_copy_label(self, h, w, l, labels):
 l l.astype(np.int)
 l_h, l_w l[4] - l[2], l[3] - l[1]
 for epoch in range(self.epochs):
 random_x, random_y np.random.randint(int(l_w / 2), int(w - l_w / 2)), 
 np.random.randint(int(l_h / 2), int(h - l_h / 2))
 xmin, ymin random_x - l_w / 2, random_y - l_h / 2
 xmax, ymax xmin l_w, ymin l_h
 if xmin 0 or xmax w or ymin 0 or ymax h:
 continue
 new_l np.array([l[0], xmin, ymin, xmax, ymax]).astype(np.int)
 if self.donot_overlap(new_l, labels) is False:
 continue
 return new_l
 return None
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267719.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号