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

做公司网站按年收费全网营销推广是什么

做公司网站按年收费,全网营销推广是什么,深圳宝安天气预报,怎么注册网站卖东西1、copy_paste 如果一张图像中有 segmentation 标注,则可以将标注的物体 copy 出来,paste 到你指定的地方。若没有 segmentation 标注,则无法使用 copy_paste 增强方式 1)将一张图像中的物体 copy 出来,paste 在本图像…

1、copy_paste

  如果一张图像中有 segmentation 标注,则可以将标注的物体 copy 出来,paste 到你指定的地方。若没有 segmentation 标注,则无法使用 copy_paste 增强方式

1)将一张图像中的物体 copy 出来,paste 在本图像中 (yolov5 中的做法)

2)更常用的是 :将 一张图像中的物体 copy 出来,paste 到另外一张图像中


2、代码示例

例 1、将一张图像中的物体 copy 出来,paste 在本图像中

代码说明

  • 按照指定比例 copy-paste 图像中的部分 object, 比如,一张图像中有 10个 object,设置的 copy-paste 概率为 0.5,那么将有 大概5个物体会被 copy-paste

  • 将图片镜像 并从中 copy 出 (镜像的) object,如果 (镜像的) object 的 bbox 与 原图像中的任意一个 bbox 交集面积 都不大于 0.3,则将 (镜像的) object paste 到另外一张图像中

  • bbox 和 segmentation 标注也要进行合并

import numpy as np
import random
import torch
from pycocotools.coco import COCO
import math
import cv2dataDir = '/Users/dataset/COCO2017'
annFile = '{}/annotations/instances_val2017.json'.format(dataDir)
imgFile = '{}/val2017'.format(dataDir)img_size = 640def bbox_ioa(box1, box2, eps=1e-7):"""Returns the intersection over box2 area given box1, box2.Boxes are x1y1x2y2box1:       np.array of shape(4)box2:       np.array of shape(nx4)returns:    np.array of shape(n)"""# Get the coordinates of bounding boxesb1_x1, b1_y1, b1_x2, b1_y2 = box1b2_x1, b2_y1, b2_x2, b2_y2 = box2.T# Intersection areainter_area = (np.minimum(b1_x2, b2_x2) - np.maximum(b1_x1, b2_x1)).clip(0) * (np.minimum(b1_y2, b2_y2) - np.maximum(b1_y1, b2_y1)).clip(0)# box2 areabox2_area = (b2_x2 - b2_x1) * (b2_y2 - b2_y1) + eps# Intersection over box2 areareturn inter_area / box2_areadef copy_paste(im, labels, segments, p=0.5):"""Applies Copy-Paste augmentation by flipping and merging segments and labels on an image.Details at https://arxiv.org/abs/2012.07177."""n = len(segments)if p and n:h, w, c = im.shape  # height, width, channelsim_new = np.zeros(im.shape, np.uint8)for j in random.sample(range(n), k=round(p * n)):l, s = labels[j], segments[j]box = w - l[3], l[2], w - l[1], l[4]ioa = bbox_ioa(box, labels[:, 1:5])  # intersection over areaif (ioa < 0.30).all():  # allow 30% obscuration of existing labelslabels = np.concatenate((labels, [[l[0], *box]]), 0)segments.append(np.concatenate((w - s[:, 0:1], s[:, 1:2]), 1))cv2.drawContours(im_new, [segments[j].astype(np.int32)], -1, (1, 1, 1), cv2.FILLED)result = cv2.flip(im, 1)  # augment segments (flip left-right)i = cv2.flip(im_new, 1).astype(bool)im[i] = result[i]return im, labels, segmentsif __name__ == '__main__':coco = COCO(annFile)indices = range(len(coco.imgs))file_names = []labels = []segments = []for i in coco.imgs:file_names.append(coco.imgs[i]['file_name'])img_w, img_h = coco.imgs[i]['width'], coco.imgs[i]['height']labels_one_img = []segments_one_img = []for ann in coco.imgToAnns[i]:if ann['iscrowd'] == 0:category_id = ann['category_id']bbox_xywh = ann['bbox']bbox_xyxy = bbox_xywh[0], bbox_xywh[1], bbox_xywh[0]+bbox_xywh[2], bbox_xywh[1]+bbox_xywh[3]labels_one_img.append(np.array([category_id, *bbox_xyxy]))segmentation = np.array(ann['segmentation'][0]).reshape((-1, 2))segments_one_img.append(segmentation)labels.append(np.array(labels_one_img))segments.append(segments_one_img)# 随便指定一张图像index = 46img_original = cv2.imread(imgFile + '/' + file_names[index])one_img_labels = labels[index]one_img_segments = segments[index]img, one_img_labels, one_img_segments = copy_paste(img_original, one_img_labels, one_img_segments, p=0.5)# # 可视化 segmentation# for seg in one_img_segments:#     points = np.array(seg).reshape((-1, 2)).astype(np.int32)#     cv2.drawContours(img, [points], -1, (0, 0, 255), thickness=2)# # 可视化 bbox# for rect in one_img_labels:#     cv2.rectangle(img, (int(rect[1]), int(rect[2])), (int(rect[3]), int(rect[4])), color=(0, 0, 255), thickness=2)cv2.imshow('img', img)cv2.waitKey()cv2.destroyAllWindows()


例 2、将 一张图像中的物体 copy 出来,paste 到另外一张图像中

  • 按照指定比例 copy 图像1 中的部分 object,paste 到图像2中, 比如,图像1 中有 10个 object,设置的 copy-paste 概率为 0.5,那么将有 大概5个物体会被 paste 到图像2中

  • 如果图像1中的物体的 bbox 与 图像2 中的任意一个 bbox 交集面积 都不大于 0.3,则将图片1 中的物体 copy-paste 到图像2中

  • bbox 和 segmentation 标注也要进行合并

import numpy as np
import random
import torch
from pycocotools.coco import COCO
import math
import cv2dataDir = '/Users/dataset/COCO2017'
annFile = '{}/annotations/instances_val2017.json'.format(dataDir)
imgFile = '{}/val2017'.format(dataDir)img_size = 640def bbox_ioa(box1, box2, eps=1e-7):"""Returns the intersection over box2 area given box1, box2.Boxes are x1y1x2y2box1:       np.array of shape(4)box2:       np.array of shape(nx4)returns:    np.array of shape(n)"""# Get the coordinates of bounding boxesb1_x1, b1_y1, b1_x2, b1_y2 = box1b2_x1, b2_y1, b2_x2, b2_y2 = box2.T# Intersection areainter_area = (np.minimum(b1_x2, b2_x2) - np.maximum(b1_x1, b2_x1)).clip(0) * (np.minimum(b1_y2, b2_y2) - np.maximum(b1_y1, b2_y1)).clip(0)# box2 areabox2_area = (b2_x2 - b2_x1) * (b2_y2 - b2_y1) + eps# Intersection over box2 areareturn inter_area / box2_areadef copy_paste(img_1, img1_labels, img1_segments, img_2, img2_labels, img2_segments, p=0.5):"""Applies Copy-Paste augmentation by flipping and merging segments and labels on an image.Details at https://arxiv.org/abs/2012.07177.将 img_1 中的 object copy-paste 到 img_2 中"""n = len(img1_segments)if p and n:img_1_h, img_1_w, _ = img_1.shapeimg_2_h, img_2_w, _ = img_2.shapemin_h, min_w = min(img_1_h, img_2_h), min(img_1_w, img_2_w)img_mask = np.zeros((min_h, min_w, 3), np.uint8)for j in random.sample(range(n), k=round(p * n)):l, s = img1_labels[j], img1_segments[j]ioa = bbox_ioa(l[1:5], img2_labels[:, 1:5])  # intersection over areaif (ioa < 0.30).all():  # allow 30% obscuration of existing labels# 边界情况要再处理一下img2_labels = np.concatenate((img2_labels, [l]), 0)img2_segments.append(s)cv2.drawContours(img_mask, [img1_segments[j].astype(np.int32)], -1, (1, 1, 1), cv2.FILLED)img_mask = img_mask.astype(bool)img_2[:min_h, :min_w, :][img_mask] = img_1[:min_h, :min_w, :][img_mask]return img_2, img2_labels, img2_segmentsif __name__ == '__main__':coco = COCO(annFile)indices = range(len(coco.imgs))file_names = []labels = []segments = []for i in coco.imgs:file_names.append(coco.imgs[i]['file_name'])img_w, img_h = coco.imgs[i]['width'], coco.imgs[i]['height']labels_one_img = []segments_one_img = []for ann in coco.imgToAnns[i]:if ann['iscrowd'] == 0:category_id = ann['category_id']bbox_xywh = ann['bbox']bbox_xyxy = bbox_xywh[0], bbox_xywh[1], bbox_xywh[0]+bbox_xywh[2], bbox_xywh[1]+bbox_xywh[3]labels_one_img.append(np.array([category_id, *bbox_xyxy]))segmentation = np.array(ann['segmentation'][0]).reshape((-1, 2))segments_one_img.append(segmentation)labels.append(np.array(labels_one_img))segments.append(segments_one_img)# 随便指定2张图像index = [46, 2]img_1 = cv2.imread(imgFile + '/' + file_names[index[0]])img_2 = cv2.imread(imgFile + '/' + file_names[index[1]])# 第 1 张图像中的 labels 和 segmentationsimg1_labels = labels[index[0]]img1_segments = segments[index[0]]# 第 2 张图像中的 labels 和 segmentationsimg2_labels = labels[index[1]]img2_segments = segments[index[1]]img_2, img2_labels, img2_segments = copy_paste(img_1, img1_labels, img1_segments, img_2, img2_labels, img2_segments, p=1)# 可视化 segmentationfor seg in img2_segments:points = np.array(seg).reshape((-1, 2)).astype(np.int32)cv2.drawContours(img_2, [points], -1, (0, 0, 255), thickness=2)# # 可视化 bbox# for rect in img2_labels:#     cv2.rectangle(img_2, (int(rect[1]), int(rect[2])), (int(rect[3]), int(rect[4])), color=(0, 0, 255), thickness=2)cv2.imshow('copy-paste img', img_2)cv2.waitKey()cv2.destroyAllWindows()

 

http://www.dtcms.com/wzjs/122582.html

相关文章:

  • 网站建设学习 服务器优化游戏性能的软件
  • 怎么给一个网站做搜索功能网站软件开发
  • 做淘宝客怎么做官方网站卡一卡二卡三入口2021
  • 潍坊网站制作小程序网站优化北京seo
  • 做鸡蛋仔冰淇淋店网站企业培训课程名称大全
  • 网站sem托管中国站长之家
  • 贵州网站开发公司网络服务包括
  • 中国建设人才服务信息网是正规网站产品软文范例
  • 自己想弄个平台怎么弄seo网站优化方案
  • 个人网站建站申请百度指数查询移动版
  • 大兴模板网站建设网络营销10大平台
  • 网站** 教程今日nba战况
  • 20个外国平面设计网站百度在西安的公司叫什么
  • 打开浏览器的网站网页优化包括
  • wordpress没有备案seo外链代发
  • 重庆市建设厅网站首页网页制作代码html制作一个网页
  • 做企业网站项目yandex引擎
  • 宁波seo网络推广报价seo网络营销是什么意思
  • 网站 盈利新闻头条今日最新消息
  • 任何人任意做网站销售产品违法吗二级域名在线扫描
  • 河南省住房城乡和建设厅网站首页推广公司有哪些公司
  • 在线观看视频的免费网站百度网盘会员
  • ih5 做视频网站百度seo招聘
  • 做网站 广告费 步骤seo基础知识
  • 做简历网站app优化排名
  • 一个上线的网站需要怎么做培训心得体会300字
  • 上海营销平台网站建设百度推广一年收费标准
  • 建站之星做的网站如何导出外贸网站有哪些
  • 聊城网站设计咨询最新的新闻 今天
  • 帝国cms做漫画网站教程互联网营销案例分析