当前位置:网站首页>FCOS3D label assignment
FCOS3D label assignment
2022-07-07 13:55:00 【Roast zongzi】
Follow 2d Of FCOS Not so much ,
It mainly depends on the picture coordinate system to allocate target:
def _get_target_single(self, gt_bboxes, gt_labels, gt_bboxes_3d,
gt_labels_3d, centers2d, depths, attr_labels,
points, regress_ranges, num_points_per_lvl):
"""Compute regression and classification targets for a single image."""
num_points = points.size(0)
num_gts = gt_labels.size(0)
if not isinstance(gt_bboxes_3d, torch.Tensor):
gt_bboxes_3d = gt_bboxes_3d.tensor.to(gt_bboxes.device)
if num_gts == 0:
return gt_labels.new_full((num_points,), self.background_label), \
gt_bboxes.new_zeros((num_points, 4)), \
gt_labels_3d.new_full(
(num_points,), self.background_label), \
gt_bboxes_3d.new_zeros((num_points, self.bbox_code_size)), \
gt_bboxes_3d.new_zeros((num_points,)), \
attr_labels.new_full(
(num_points,), self.attr_background_label)
# change orientation to local yaw
gt_bboxes_3d[..., 6] = -torch.atan2(
gt_bboxes_3d[..., 0], gt_bboxes_3d[..., 2]) + gt_bboxes_3d[..., 6]
areas = (gt_bboxes[:, 2] - gt_bboxes[:, 0]) * (
gt_bboxes[:, 3] - gt_bboxes[:, 1]) # [tl_x, tl_y, br_x, br_y]--> S_areas
areas = areas[None].repeat(num_points, 1) # [2] --> [30929, 2]
regress_ranges = regress_ranges[:, None, :].expand(
num_points, num_gts, 2) # [30929, 2] --> [30929, 2, 2]
gt_bboxes = gt_bboxes[None].expand(num_points, num_gts, 4)
centers2d = centers2d[None].expand(num_points, num_gts, 2)
gt_bboxes_3d = gt_bboxes_3d[None].expand(num_points, num_gts,
self.bbox_code_size)
depths = depths[None, :, None].expand(num_points, num_gts, 1)
# Every points Coordinates of (xs,ys)
xs, ys = points[:, 0], points[:, 1]
xs = xs[:, None].expand(num_points, num_gts)
ys = ys[:, None].expand(num_points, num_gts)
# gt center --> offsets
## centers2d: Every gt stay 2d image The coordinates on
delta_xs = (xs - centers2d[..., 0])[..., None]
delta_ys = (ys - centers2d[..., 1])[..., None]
# 0. The previous operation is mainly for here , Get the same as the network output target_box
bbox_targets_3d = torch.cat(
(delta_xs, delta_ys, depths, gt_bboxes_3d[..., 3:]), dim=-1)
left = xs - gt_bboxes[..., 0]
right = gt_bboxes[..., 2] - xs
top = ys - gt_bboxes[..., 1]
bottom = gt_bboxes[..., 3] - ys
bbox_targets = torch.stack((left, top, right, bottom), -1)
assert self.center_sampling is True, 'Setting center_sampling to '\
'False has not been implemented for FCOS3D.'
# condition1: inside a `center bbox`
radius = self.center_sample_radius # 1.5
center_xs = centers2d[..., 0]
center_ys = centers2d[..., 1]
center_gts = torch.zeros_like(gt_bboxes)
stride = center_xs.new_zeros(center_xs.shape)
# project the points on current lvl back to the `original` sizes
# 1. Map the position of feature points of each layer back to the input image
lvl_begin = 0
for lvl_idx, num_points_lvl in enumerate(num_points_per_lvl): # [23200, 5800, 1450, 375, 104]
lvl_end = lvl_begin + num_points_lvl
stride[lvl_begin:lvl_end] = self.strides[lvl_idx] * radius # [8, 16, 32, 64, 128] * 1.5
# Every point The scaling factor of * radius
lvl_begin = lvl_end
# 2. The position point in the object frame is regarded as a positive sample candidate
## Side length 1.5 Box of -->
center_gts[..., 0] = center_xs - stride
center_gts[..., 1] = center_ys - stride
center_gts[..., 2] = center_xs + stride
center_gts[..., 3] = center_ys + stride
cb_dist_left = xs - center_gts[..., 0] # points Center point to
cb_dist_right = center_gts[..., 2] - xs
cb_dist_top = ys - center_gts[..., 1]
cb_dist_bottom = center_gts[..., 3] - ys
center_bbox = torch.stack(
(cb_dist_left, cb_dist_top, cb_dist_right, cb_dist_bottom), -1)
inside_gt_bbox_mask = center_bbox.min(-1)[0] > 0 # anchor_box The center point falls on gt_box Center point 1.5 Only valid within the square of the unit
# condition2: limit the regression range for each location
# 3. The distance from a certain position point to the object frame can be regarded as a positive sample only if it is within a certain range ( Each floor has its own scope )
max_regress_distance = bbox_targets.max(-1)[0]
# Ensure that on each floor level Within the regression range of
inside_regress_range = (
(max_regress_distance >= regress_ranges[..., 0])
& (max_regress_distance <= regress_ranges[..., 1]))
# center-based criterion to deal with ambiguity
# 4. Fuzzy processing based on central criterion
## 4.1 Choose the one with the smallest offset gt+gt_inds
dists = torch.sqrt(torch.sum(bbox_targets_3d[..., :2]**2, dim=-1)) # offsets The European distance of [30929, 2]
dists[inside_gt_bbox_mask == 0] = INF # Screening anchor
dists[inside_regress_range == 0] = INF
min_dist, min_dist_inds = dists.min(dim=1)
labels = gt_labels[min_dist_inds] # Screening gt
labels_3d = gt_labels_3d[min_dist_inds]
attr_labels = attr_labels[min_dist_inds]
labels[min_dist == INF] = self.background_label # set as BG 10
labels_3d[min_dist == INF] = self.background_label # set as BG
attr_labels[min_dist == INF] = self.attr_background_label
## 4.2 Every point Select the corresponding box_target
bbox_targets = bbox_targets[range(num_points), min_dist_inds] # [30929, 2, 4] --> [30929, 4]
bbox_targets_3d = bbox_targets_3d[range(num_points), min_dist_inds]
## 4.3 Screening centerness_targets
## Offset --> hypotenuse / Side length 1.5scale To the side length of the actual triangle == Relative distance
relative_dists = torch.sqrt(
torch.sum(bbox_targets_3d[..., :2]**2,
dim=-1)) / (1.414 * stride[:, 0])
# [N, 1] / [N, 1]
centerness_targets = torch.exp(-self.centerness_alpha * relative_dists) # exp(-2.5 * relative_dists) todo?
return labels, bbox_targets, labels_3d, bbox_targets_3d, \
centerness_targets, attr_labels
边栏推荐
- Talk about pseudo sharing
- call undefined function openssl_ cipher_ iv_ length
- LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
- Cinnamon taskbar speed
- Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
- Laravel5 call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败
- Leecode3. Longest substring without repeated characters
- What are the principles for distinguishing the security objectives and implementation methods that cloud computing security expansion requires to focus on?
- 2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
- 云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
猜你喜欢
Custom thread pool rejection policy
1、深拷贝 2、call apply bind 3、for of for in 区别
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
C语言数组相关问题深度理解
Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
566. 重塑矩阵
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
Evolution of customer service hotline of dewu
随机推荐
最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
2022-7-6 使用SIGURG来接受外带数据,不知道为什么打印不出来
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
Use of polarscatter function in MATLAB
ES日志报错赏析-Limit of total fields
Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
. Net core about redis pipeline and transactions
Build a secure and trusted computing platform based on Kunpeng's native security
Vmware 与主机之间传输文件
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
[daily training -- Tencent select 50] 231 Power of 2
AI人才培育新思路,这场直播有你关心的
Redis can only cache? Too out!
Laravel Form-builder使用
Toraw and markraw
requires php ~7.1 -&gt; your PHP version (7.0.18) does not satisfy that requirement
Attribute keywords aliases, calculated, cardinality, ClientName
Move base parameter analysis and experience summary
作战图鉴:12大场景详述容器安全建设要求
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?