import numpy as np
def generate_basic_anchors(sizes, base_size=16):
#base_anchor([0,0,15,15])
base_anchor = np.array([0, 0, base_size - 1, base_size - 1], np.int32)
anchors = np.zeros((len(sizes), 4), np.int32)
index = 0
for h, w in sizes:
anchors[index] = scale_anchor(base_anchor, h, w)
index += 1
return anchors
def scale_anchor(anchor, h, w):
#anchor为[0,0,15,15]
x_ctr = (anchor[0] + anchor[2]) * 0.5
y_ctr = (anchor[1] + anchor[3]) * 0.5
scaled_anchor = anchor.copy()
scaled_anchor[0] = x_ctr - w / 2 # xmin
scaled_anchor[2] = x_ctr + w / 2 # xmax
scaled_anchor[1] = y_ctr - h / 2 # ymin
scaled_anchor[3] = y_ctr + h / 2 # ymax
return scaled_anchor
def generate_anchors():
heights = [11, 16, 23, 33, 48, 68, 97, 139, 198, 283]
widths = [16]
sizes = []
for h in heights:
for w in widths:
sizes.append((h, w))
return generate_basic_anchors(sizes)

  

if __name__ == '__main__':
import time
t = time.time()
a = generate_anchors()
print(a)
a:
[[ 0 2 15 13]
[ 0 0 15 15]
[ 0 -4 15 19]
[ 0 -9 15 24]
[ 0 -16 15 31]
[ 0 -26 15 41]
[ 0 -41 15 56]
[ 0 -62 15 77]
[ 0 -91 15 106]
[ 0 -134 15 149]] shift_x = np.arange(0, 2) * 16#本来应该是特征图的宽高,为了方便演示,设置为2,3
shift_y = np.arange(0, 3) * 16
print("shift_x:", shift_x)
print("shift_y:",shift_y)
shift_x: [ 0 16]
shift_y: [ 0 16 32]
shift_x, shift_y = np.meshgrid(shift_x, shift_y) # in W H order
shift_x1:
[[ 0 16]
[ 0 16]
[ 0 16]]
shift_y1:
[[ 0 0]
[16 16]
[32 32]]
shifts = np.vstack((shift_x.ravel(), shift_y.ravel(),
shift_x.ravel(), shift_y.ravel())).transpose() # 生成feature-map和真实image上anchor之间的偏移量
print("shifts:",shifts)
shifts:
[[ 0 0 0 0]
[16 0 16 0]
[ 0 16 0 16]
[16 16 16 16]
[ 0 32 0 32]
[16 32 16 32]]
A = a.shape[0] # 10个anchor
K = shifts.shape[0] # 50*38,feature-map的宽乘高的大小
all_anchors = (a.reshape((1, A, 4)) +
shifts.reshape((1, K, 4)).transpose((1, 0, 2))) # 相当于复制宽高的维度,然后相加shape(1938,10,4)
all_anchors = all_anchors.reshape((K * A, 4)) # shape(19380,4)
all_anchors:(特征图上每个点产生10个框,与原图的偏移相加即原图行列每隔16个点产生10个坐标) [[ 0 2 15 13]
[ 0 0 15 15]
[ 0 -4 15 19]
[ 0 -9 15 24]
[ 0 -16 15 31]
[ 0 -26 15 41]
[ 0 -41 15 56]
[ 0 -62 15 77]
[ 0 -91 15 106]
[ 0 -134 15 149]
[ 16 2 31 13]
[ 16 0 31 15]
[ 16 -4 31 19]
[ 16 -9 31 24]
[ 16 -16 31 31]
[ 16 -26 31 41]
[ 16 -41 31 56]
[ 16 -62 31 77]
[ 16 -91 31 106]
[ 16 -134 31 149]
[ 0 18 15 29]
[ 0 16 15 31]
[ 0 12 15 35]
[ 0 7 15 40]
[ 0 0 15 47]
[ 0 -10 15 57]
[ 0 -25 15 72]
[ 0 -46 15 93]
[ 0 -75 15 122]
[ 0 -118 15 165]
[ 16 18 31 29]
[ 16 16 31 31]
[ 16 12 31 35]
[ 16 7 31 40]
[ 16 0 31 47]
[ 16 -10 31 57]
[ 16 -25 31 72]
[ 16 -46 31 93]
[ 16 -75 31 122]
[ 16 -118 31 165]
[ 0 34 15 45]
[ 0 32 15 47]
[ 0 28 15 51]
[ 0 23 15 56]
[ 0 16 15 63]
[ 0 6 15 73]
[ 0 -9 15 88]
[ 0 -30 15 109]
[ 0 -59 15 138]
[ 0 -102 15 181]
[ 16 34 31 45]
[ 16 32 31 47]
[ 16 28 31 51]
[ 16 23 31 56]
[ 16 16 31 63]
[ 16 6 31 73]
[ 16 -9 31 88]
[ 16 -30 31 109]
[ 16 -59 31 138]
[ 16 -102 31 181]]

  

CTPN中anchors代码的更多相关文章

  1. CTPN项目部分代码学习

    上次拜读了CTPN论文,趁热打铁,今天就从网上找到CTPN 的tensorflow代码实现一下,这里放出大佬的github项目地址:https://github.com/eragonruan/text ...

  2. 第二十二篇:在SOUI中使用代码向窗口中插入子窗口

    使用SOUI开发客户端UI程序,通常也推荐使用XML代码来创建窗口,这样创建的窗口使用方便,当窗口大小改变时,内部的子窗口也更容易协同变化. 但是最近不断有网友咨询如何使用代码来创建SOUI子窗口,特 ...

  3. VS2010/VS2013中ashx代码折叠的问题

    Tools->Options->TextEditor->File Extension Add ashx Microsoft Visual C# Apply OK 重启VS就可以了,效 ...

  4. 用 highlight.js 为文章中的代码添加语法高亮

    来源:http://www.ghostchina.com/adding-syntax-highlighting-to-ghost-using-highlight-js/ --------------- ...

  5. VS中的代码段功能

    1.前言 开发人员不喜欢打字.如果你希望提高开发人员的生产力,减少键入的数量,这也同时减少打字稿的数量以及因此产生的编译器错误,这些都极大分散了开发人员的注意力.代码重用是开发人员收集代码的另一个原因 ...

  6. PHP中PSR-[0-4]代码规范

    PHP-FIG 在说啥是PSR-[0-4]规范的之前,我觉得我们有必要说下它的发明者和规范者:PHP-FIG,它的网站是:www.php-fig.org.就是这个联盟组织发明和创造了PSR-[0-4] ...

  7. java eclipse中的代码联动提示功能

    eclipse中的代码联动提示设置:window--->preferences--->java--->editor----> content assist的auto activ ...

  8. demo工程的清单文件及activity中api代码简单示例

    第一步注册一个账户,并创建一个应用.获取app ID与 app Key. 第二步下载sdk 第三步新建工程,修改清单文件,导入相关的sdk文件及调用相应的api搞定. 3.1 修改清单文件,主要是加入 ...

  9. Bootstrap css栅格 + 网页中插入代码+css表格

    设计达人 http://www.shejidaren.com/30-minimal-app-icons.html CSS栅格: <!DOCTYPE html> <html lang= ...

随机推荐

  1. poj 3181 Dollar Dayz(完全背包)

    Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2054 Descr ...

  2. 2018-8-10-win10-uwp-读取保存WriteableBitmap-、BitmapImage

    title author date CreateTime categories win10 uwp 读取保存WriteableBitmap .BitmapImage lindexi 2018-08-1 ...

  3. 教你怎么让vi和vim显示行数

    首先我们来看看没有行号是多么难看. 2 再来看看有行号后的效果. 3 设置行号很简单. 我们要到命令模式下,输入set number :set number 按下回车 来看看效果 4 那么怎么关闭行号 ...

  4. [转]C# 语言历史版本特性(C# 1.0到C# 8.0汇总)

    历史版本 C#作为微软2000年以后.NET平台开发的当家语言,发展至今具有17年的历史,语言本身具有丰富的特性,微软对其更新支持也十分支持.微软将C#提交给标准组织ECMA,C# 5.0目前是ECM ...

  5. 2018-8-10-git-提交添加-emoij-文字

    title author date CreateTime categories git 提交添加 emoij 文字 lindexi 2018-08-10 19:16:52 +0800 2018-2-1 ...

  6. dotnet 设计规范 · 抽象定义

    严格来说,只有一个类被其他的类继承,那么这个类就是基类.在很多时候,基类的定义是提供足够的抽象和通用方法和属性.默认实现.在继承关系中,基类定义在上层抽象和底层自定义之间. 他们充当抽象实现的实现帮助 ...

  7. P1077 旅行

    题目描述 你要进行一个行程为7000KM的旅行,现在沿途有些汽车旅馆,为了安全起见,每天晚上都不开车,住在汽车旅馆,你手里现在已经有一个旅馆列表,用离起点的距离来标识,如下: 0, 990, 1010 ...

  8. jieba—parallel

    jieba 并行处理进行测试,注意:并行分词仅支持默认分词器 jieba.dt 和 jieba.posseg.dt import sys import time import jieba jieba. ...

  9. while循环&CPU占用率高问题深入分析与解决方案

    直接上一个工作中碰到的问题,另外一个系统开启多线程调用我这边的接口,然后我这边会开启多线程批量查询第三方接口并且返回给调用方.使用的是两三年前别人遗留下来的方法,放到线上后发现确实是可以正常取到结果, ...

  10. linux ioctl 系统调用预定义的命令

    尽管 ioctl 系统调用最常用来作用于设备, 内核能识别几个命令. 注意这些命令, 当用 到你的设备时, 在你自己的文件操作被调用之前被解码. 因此, 如果你选择相同的号给一 个你的 ioctl 命 ...