1.attach_linux_amd64.so: undefined symbol: AttachDebuggerTracing的解决办法
2.如何给tensor添加新的维度?
- 例如,图像的标准化实现:
image - mean[:, None, None]) / std[:, None, None]
3.将两个不同的对象的对应位置的元素进行打包:
ratios = tuple(float(s) / float(s_orig) for s, s_orig in zip(new_size, original_size))
4.将tensor沿着某个维度铺开:
xmin, ymin, xmax, ymax = boxes.unbind(1)
5.元组加法
batch_shape = (len(images),) + max_size
6.对元组进行解压,构建新的tensor, 以及对tensor进行置零初始化,与此同时完成数据拷贝
batch_shape = (len(images),) + max_size
batched_imgs = images[0].new(*batch_shape).zero_()
for img, pad_img in zip(images, batched_imgs):
pad_img[: img.shape[0], : img.shape[1], : img.shape[2]].copy_(img)
7.将数据转换为张量
下面的函数既可以完成对数的转化,也可以完成对列表和元组的转化
torch.as_tensor(data, dtype=None, device=None) → Tensor
8.生成anchor的过程
先考虑在原点生成base anchor(基于预定义好的大小以及anchor的长宽比),然后再通过构建网格的方式将base anchor放置到feature map的每一个点上,具体实现代码如下所示:
def grid_anchors(self, grid_sizes, strides):
anchors = []
for size, stride, base_anchors in zip(
grid_sizes, strides, self.cell_anchors
):
grid_height, grid_width = size
stride_height, stride_width = stride
device = base_anchors.device
shifts_x = torch.arange(
0, grid_width, dtype=torch.float32, device=device
) * stride_width
shifts_y = torch.arange(
0, grid_height, dtype=torch.float32, device=device
) * stride_height
shift_y, shift_x = torch.meshgrid(shifts_y, shifts_x)
shift_x = shift_x.reshape(-1)
shift_y = shift_y.reshape(-1)
shifts = torch.stack((shift_x, shift_y, shift_x, shift_y), dim=1)
anchors.append(
(shifts.view(-1, 1, 4) + base_anchors.view(1, -1, 4)).reshape(-1, 4)
)
return anchors
9.如何针对FPN不同level的feature map来得到前k个得分较高的proposal
def _get_top_n_idx(self, objectness, num_anchors_per_level):
r = []
offset = 0
for ob in objectness.split(num_anchors_per_level, 1):
num_anchors = ob.shape[1]
pre_nms_top_n = min(self.pre_nms_top_n, num_anchors)
_, top_n_idx = ob.topk(pre_nms_top_n, dim=1)
r.append(top_n_idx + offset)
offset += num_anchors
return torch.cat(r, dim=1)